You are not logged in.
Offline
Last night I accidentally ate a whole baguette.
Offline
why didn't battler just lift the door off the hinges preserving the chain lock seal
it would have been the coolest thing ever
why did I only get this idea afterwards
aargh episode 6 could have been so much better, I'm going to make my own improved version
We do not die - we go to hell to regroup.
Offline
https://www.youtube.com/watch?v=GceNsojnMf0
all credit to ipep (this is still a bad joke don't take this as validation)
(´・ω・`)
Offline
still better than other meme
Offline
public class ArrayMinMax {
/**
* Method arrayMin
* returns the smallest value in a given array
* @param array array to find minimum from
*/
public static int arrayMin(int[] array) {
int temp = array[0]; // set value of first index in temp
for (int n = 1;n < array.length;n++) {
if (temp > array[n]) // compare current value against temp
temp = array[n]; // if current value is smaller, save it in temp
}
return temp; // return temp that now has the smallest value
}
/**
* Method arrayMax
* returns the largest value in a given array
* @param array array to find maximum from
*/
public static int arrayMax(int[] array) {
int temp = array[0];
for (int n = 1;n < array.length;n++) {
if (temp < array[n]) // the only difference to min is the flip of > to <
temp = array[n];
}
return temp;
}
/**
* Main program
* @param user input, not used
*/
public static void main(String args[]) {
int[] values = { 1, -5, 10, -15, 0, 7 };
// prints out min and max with formatting
System.out.printf("%-5s%2d\n%-5s%2d\n","Min:",arrayMin(values),"Max:",arrayMax(values));
}
}
Offline
Yup thats a java.
Been a while since I've used a java.
My instincts tell me you've forgotten to import a minimum of 5 classes including java.io.
I know this still works.
My experience tells me otherwise.
Offline
public class ArrayColorConversion {
/**
* Method arrayMin
* returns the smallest value in a given array
* @param array array to find minimum from
* @return minimum value in array
*/
public static int arrayMin(int[] array) {
int temp = array[0]; // set value of first index in temp
for (int n = 1;n < array.length;n++) {
if (temp > array[n]) // compare current value against temp
temp = array[n]; // if current value is smaller, save it in temp
}
return temp; // return temp that now has the smallest value
}
/**
* Method arrayMax
* returns the largest value in a given array
* @param array array to find maximum from
* @return maximum value in array
*/
public static int arrayMax(int[] array) {
int temp = array[0];
for (int n = 1;n < array.length;n++) {
if (temp < array[n]) // the only difference to min is the flip of > to <
temp = array[n];
}
return temp;
}
/**
* Method RGBtoHSV
* converts given RGB value to a HSV value
* @param array array to convert values from
* @return array with values in HSV format
*/
public static int[] RGBtoHSV(int[] array) {
//initialize return array and temporary array
int[] hsv = {0,0,0};
double[] hsv_t = {0,0,0};
// convert the 0-255 rgb values to 0-1
double r = (double) array[0] / 255;
double g = (double) array[1] / 255;
double b = (double) array[2] / 255;
// calculate max, min and delta
double cmax = (double) arrayMax(array) / 255;
double cmin = (double) arrayMin(array) / 255;
double delta = cmax - cmin;
if (cmax <= 0) { // if max is 0, then everything is 0 and HSV values are 0,0,0
return hsv;
}
else { // if not, calculate hsv values
if (r >= cmax)
hsv_t[0] = (g - b) / delta;
else if (g >= cmax)
hsv_t[0] = ((b - r) / delta) + 2.0;
else
hsv_t[0] = ((r - g) / delta) + 4.0;
hsv_t[0] *= 60;
if (hsv_t[0] < 0)
hsv_t[0] += 360;
hsv_t[1] = (delta / cmax) * 100;
hsv_t[2] = cmax * 100;
}
// dump the temp values into int array
hsv[0] = (int) Math.round(hsv_t[0]);
hsv[1] = (int) Math.round(hsv_t[1]);
hsv[2] = (int) Math.round(hsv_t[2]);
return hsv;
}
/**
* Main program
* @param args user input, not used
*/
public static void main(String args[]) {
int[] colour = { 255,0,128 }; //the prettiest of colours
int[] colourHSV = RGBtoHSV(colour);
System.out.print("H: " + colourHSV[0] + "\n");
System.out.print("S: " + colourHSV[1] + "\n");
System.out.print("V: " + colourHSV[2] + "\n");
}
}
At least that one is somewhat interesting but it's still java
Offline
That reminds me that I want to learn vim to become a keyboard wizard but I need a good excuse to use it so that I don't look like a complete idiot hipster.
Hoo boy I'm rusty I need to get some practice in.
Offline
>nano
>hacker
:----------D
meanwhile:
def checkSudoku(fName):
sudokuNumbers = []
with open(fName, 'r', encoding="utf-8") as f:
for line in f:
for char in line:
if char.isnumeric():
sudokuNumbers.append(int(char))
sudokuRows = [sudokuNumbers[i:i + 9] for i in range(0, len(sudokuNumbers), 9)]
sudokuColumns = [[] for i in range(9)]
for row in sudokuRows:
for i,col in enumerate(row):
sudokuColumns[i].append(col)
sudokuSubgrids = [[] for i in range(9)]
offset = 0
for i,row in enumerate(sudokuRows):
if i % 3 == 0 and i != 0:
offset += 3
subgridparts = [row[x:x + 3] for x in range(0, len(row), 3)]
for j, subgridpart in enumerate(subgridparts):
for number in subgridpart:
sudokuSubgrids[j+offset].append(number)
sudokuSubgridRows = [sudokuSubgrids[i:i + 3] for i in range(0, len(sudokuSubgrids), 3)]
illegalRows = []
illegalCols = []
illegalSubgrids = []
for i,row in enumerate(sudokuRows):
if len(row) != len(set(row)):
illegalRows.append(str(i+1))
for i,col in enumerate(sudokuColumns):
if len(col) != len(set(col)):
illegalCols.append(str(i+1))
for x,subgridRow in enumerate(sudokuSubgridRows):
for y,subgrid in enumerate(subgridRow):
if len(subgrid) != len(set(subgrid)):
illegalSubgrids.append(str([x+1, y+1]))
if not illegalRows and not illegalCols and not illegalSubgrids:
print("The sudoku solution is legal")
else:
if illegalRows:
print("Illegal rows: {0}".format(' '.join(illegalRows)))
if illegalCols:
print("Illegal columns: {0}".format(' '.join(illegalCols)))
if illegalSubgrids:
print("Illegal subgrids: {0}".format(' '.join(illegalSubgrids)))
(takes files with content like: https://u.nya.fi/Te0QMN.txt )
Offline