Created
February 11, 2012 02:10
-
-
Save Olychuck/1795346 to your computer and use it in GitHub Desktop.
Embedly Questions
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
import java.math.BigInteger; | |
public class Factorialcounter { | |
/** | |
* Simply goes through each factorial and tests the cumulative number | |
*/ | |
public static int numb(int s) { | |
BigInteger a = new BigInteger(String.valueOf(s)); | |
while (--s > 0) { | |
a = a.multiply(new BigInteger(String.valueOf(s))); | |
} | |
String qw = a.toString(); | |
int count = 0; | |
for (int i = 0; i < qw.length(); i++) { | |
count += Integer.parseInt(qw.charAt(i) + ""); | |
} | |
return count; | |
} | |
public static void main(String[] args) { | |
int i = 0; | |
while (numb(i) != 8001) { | |
i++; | |
} | |
System.out.println(i); | |
} | |
} |
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
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class Htmlcounter { | |
/** | |
* Simply counts the number of paragraphs by adding ints to a list that | |
* represent the depth at that time | |
*/ | |
// gets Data | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
String tempo = ""; | |
while (scan.hasNext()) { | |
tempo = tempo + " " + scan.next(); | |
if (tempo.charAt(tempo.length() - 1) == ']') { | |
break; | |
} | |
} | |
// Counts the paragraphs and keeps track of the line | |
int curlevel = -1; | |
ArrayList<Integer> arr = new ArrayList<Integer>(); | |
for (int i = 0; i < tempo.length(); i++) { | |
if (tempo.charAt(i) == 'p') { | |
if (tempo.charAt(i - 1) == '<' && tempo.charAt(i + 1) == '>') { | |
arr.add(curlevel); | |
} | |
} | |
if (tempo.charAt(i) == '<') | |
curlevel++; | |
if (tempo.charAt(i) == '/') { | |
if (tempo.charAt(i - 1) == '<') { | |
curlevel -= 2; | |
} else if (tempo.charAt(i + 1) == '>') { | |
curlevel--; | |
} | |
} | |
} | |
// / Does the statistics | |
double avg = 0; | |
for (int i = 0; i < arr.size(); i++) { | |
avg += arr.get(i); | |
} | |
double temp; | |
double tot = 0; | |
for (int i = 0; i < arr.size(); i++) { | |
temp = arr.get(i) - avg; | |
temp *= temp; | |
tot += temp; | |
} | |
tot /= arr.size(); | |
System.out.println(Math.sqrt(tot)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment