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
if (process.argv.length < 4) { | |
console.log('usage: node caesarCipher [cipherText] [key(number)]'); | |
return; | |
} | |
const cipherText = process.argv[2]; | |
const key = parseInt(process.argv[3]); | |
const charCodeA = 'a'.charCodeAt(0); | |
const plainText = cipherText |
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
/** | |
* Project Euler Problem 11 | |
*/ | |
object P11 { | |
val list = List( | |
8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8, | |
49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0, | |
81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65, | |
52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91, |
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
/** | |
* Project Euler Problem 10 | |
*/ | |
object P10 { | |
def primes(limit:Int): List[Int] = { | |
require(limit > 1) | |
def go(primes:List[Int], search:List[Int]):List[Int] = { | |
val prime = search.head |
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
/** | |
* Project Euler Problem 9 | |
*/ | |
object P9 { | |
def isPythagorasNumber(a:Int, b:Int, c:Int):Boolean = a < b && b < c && BigInt(a).pow(2) + BigInt(b).pow(2) == BigInt(c).pow(2) | |
def answer = { | |
val list = for (i <- 1 to 333; j <- (i + 1) to 500; k <- (j + 1) to 1000; if((i + j + k) == 1000 && isPythagorasNumber(i, j, k))) yield (i, j, k) | |
val ans = list(0) | |
ans._1 * ans._2 * ans._3 |
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
/** | |
* Project Euler Problem 8 | |
*/ | |
object P8 { | |
private val LIST = | |
"73167176531330624919225119674426574742355349194934"+ | |
"96983520312774506326239578318016984801869478851843"+ | |
"85861560789112949495459501737958331952853208805511"+ | |
"12540698747158523863050715693290963295227443043557"+ |
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
/** | |
* Project Euler Problem 7 | |
*/ | |
object P7 { | |
def from(n:Long):Stream[Long] = n #:: from(n + 1) | |
def primes(): Stream[Long] = { | |
import scala.collection.mutable.ListBuffer |
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
/** | |
* Project Euler Problem 6 | |
*/ | |
object P6 { | |
def answer():BigInt = BigInt((1 to 100).sum).pow(2) - (1 to 100).map(BigInt(_).pow(2)).sum | |
} |
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
/** | |
* Project Euler Problem 5 | |
*/ | |
object P5 { | |
def from(n:Long)(multiple:Int):Stream[Long] = (n * multiple) #:: from(n + 1)(multiple) | |
def isAnswer(n:Long):Boolean = !(1 to 20).exists(n % _ != 0) | |
def answer():Long = { |
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
/** | |
* Project Euler Problem 4 | |
*/ | |
object P4 { | |
def isKaibunNumber(n:Int):Boolean = n.toString == n.toString.reverse | |
def answer():Int = (for(i <- 100 to 999; j <- 100 to 999; if (isKaibunNumber(i * j))) yield (i * j)).max | |
} |
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
/** | |
* Project Euler Problem 1 | |
*/ | |
object P1 { | |
def answer() = (1 to 999).filter(n => n % 3 == 0 || n % 5 == 0).sum | |
} |
NewerOlder