Created
February 11, 2012 05:47
-
-
Save kurtsiegfried/1796779 to your computer and use it in GitHub Desktop.
Embedly Problem 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
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package embedly; | |
import java.math.BigInteger; | |
/** | |
* | |
* @author ksiegfried | |
*/ | |
public class Embedly { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
for(long i = 0; i < 2048; i++){ | |
BigInteger n = fact(i); | |
long rval = rval(n); | |
System.out.printf("Index %d Rval %d\n",i,rval); | |
if(rval == 8001){ | |
return; | |
} | |
} | |
} | |
static long rval(BigInteger input){ | |
String asString = input.toString(); | |
long accumulator = 0; | |
for(int i = 0; i < asString.length(); i++){ | |
accumulator += Long.parseLong(Character.toString(asString.charAt(i))); | |
} | |
return accumulator; | |
} | |
static BigInteger fact(long n){ | |
BigInteger accumulator = BigInteger.ONE; | |
BigInteger factVal = BigInteger.valueOf(n); | |
for(long i = 1; i <=n; i++){ | |
accumulator = accumulator.multiply(BigInteger.valueOf(i)); | |
} | |
return accumulator; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment