Skip to content

Instantly share code, notes, and snippets.

View kozake's full-sized avatar

Shinichi Kozake kozake

View GitHub Profile
@kozake
kozake / caesarCipher.js
Created April 27, 2019 22:40
シーザー暗号
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
@kozake
kozake / gist:4425403
Created January 1, 2013 05:44
Project Euler Problem 11
/**
* 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,
@kozake
kozake / gist:4413586
Last active December 10, 2015 09:19
Project Euler Problem 10
/**
* 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
@kozake
kozake / gist:4368214
Last active December 10, 2015 02:29
Project Euler Problem 9
/**
* 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
@kozake
kozake / gist:4368126
Last active December 10, 2015 02:29
Project Euler Problem 8
/**
* Project Euler Problem 8
*/
object P8 {
private val LIST =
"73167176531330624919225119674426574742355349194934"+
"96983520312774506326239578318016984801869478851843"+
"85861560789112949495459501737958331952853208805511"+
"12540698747158523863050715693290963295227443043557"+
@kozake
kozake / gist:4367461
Last active December 10, 2015 02:28
Project Euler Problem 7
/**
* 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
@kozake
kozake / gist:4367378
Last active December 10, 2015 02:28
Project Euler Problem 6
/**
* Project Euler Problem 6
*/
object P6 {
def answer():BigInt = BigInt((1 to 100).sum).pow(2) - (1 to 100).map(BigInt(_).pow(2)).sum
}
@kozake
kozake / gist:4367241
Last active December 10, 2015 02:19
Project Euler Problem 5
/**
* 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 = {
@kozake
kozake / gist:4367136
Last active December 10, 2015 02:18
Project Euler Problem 4
/**
* 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
}
@kozake
kozake / gist:4367053
Last active December 10, 2015 02:18
Project Euler Problem 1
/**
* Project Euler Problem 1
*/
object P1 {
def answer() = (1 to 999).filter(n => n % 3 == 0 || n % 5 == 0).sum
}