This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double bestPracticeMean(String town, String strng) { | |
return parseTemp(town, strng).stream() | |
.collect(averagingDouble(n -> n)); | |
} | |
public static double bestPracticeVariance(String town, String strng) { | |
double mean = mean(town, strng); | |
if (mean == -1.0) return -1.0; | |
return parseTemp(town, strng).stream() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double mean(String town, String strng) { | |
String[] dataList = strng.split("\n"); | |
String targetData = null; | |
String targetRainfall = null; | |
double sum = 0; | |
for(String data : dataList){ | |
if(town.equals(data.split(":")[0])){ | |
targetData = town; | |
targetRainfall = data.split(":")[1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mean("London", data), 51.19(9999999999996) | |
variance("London", data), 57.42(833333333374) | |
public static String data = | |
"Rome:Jan 81.2,Feb 63.2,Mar 70.3,Apr 55.7,May 53.0,Jun 36.4,Jul 17.5,Aug 27.5,Sep 60.9,Oct 117.7,Nov 111.0,Dec 97.9" + | |
"\n" + | |
"London:Jan 48.0,Feb 38.9,Mar 39.9,Apr 42.2,May 47.3,Jun 52.1,Jul 59.5,Aug 57.2,Sep 55.4,Oct 62.0,Nov 59.0,Dec 52.9" + | |
"\n" + | |
"Paris:Jan 182.3,Feb 120.6,Mar 158.1,Apr 204.9,May 323.1,Jun 300.5,Jul 236.8,Aug 192.9,Sep 66.3,Oct 63.3,Nov 83.2,Dec 154.7" + | |
"\n" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int bestPractice(String first, String second){ | |
if (first.length() != second.length()) | |
return -1; | |
return (second + second).indexOf(first); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int shiftedDiff(String first, String second){ | |
if(first.equals(second)){ | |
return 0; | |
} | |
for(int i=0;i<first.length();i++){ | |
String temp = first.substring(0, first.length()-1); | |
temp = first.charAt(first.length()-1) + temp; | |
first = temp; | |
if(first.equals(second)){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"coffee", "eecoff" => 2 | |
"eecoff", "coffee" => 4 | |
"moose", "Moose" => -1 | |
"isn't", "'tisn" => 2 | |
"Esham", "Esham" => 0 | |
"dog", "god" => -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int bestPractice(int n) { | |
return (n != 0 && n%9 == 0) ? 9 : n % 9; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int digital_root(int n) { | |
int sum = 0; | |
if(String.valueOf(n).length() == 1){ | |
return n; | |
} | |
while(String.valueOf(n).length() != 1){ | |
sum += n % 10; | |
n = n / 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digital_root(16) | |
=> 1 + 6 | |
=> 7 | |
digital_root(942) | |
=> 9 + 4 + 2 | |
=> 15 ... | |
=> 1 + 5 | |
=> 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long bestPractice(long m) { | |
long mm = 0, n = 0; | |
while (mm < m) | |
mm += ++n * n * n; | |
return mm == m ? n : -1; | |
} |
NewerOlder