Skip to content

Instantly share code, notes, and snippets.

View outsideris's full-sized avatar

Outsider outsideris

View GitHub Profile
@outsideris
outsideris / p009.scala
Created June 16, 2013 01:04
euler problem 9
(for {
a <- 1 until 1000
b <- a + 1 until 1000
c = 1000 - a - b
if (c > b)
if (a * a + b * b == c * c)
} yield (a, b, c)).map( x => x._1 * x._2 * x._3)
// Vector(31875000)
@outsideris
outsideris / p008.scala
Created June 1, 2013 17:39
euler problem 8
val data = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
val resul
@outsideris
outsideris / p007.scala
Created June 1, 2013 17:38
euler problem 7
import scala.language.implicitConversions
import scala.language.postfixOps
class Prime(val i: Int) {
def isPrime = {
if (i <= 1) false
else if (i == 2) true
else { !(2 to (i-1)).exists(i % _ == 0)}
}
}
@outsideris
outsideris / p006.scala
Created May 18, 2013 13:22
euler problem 6
val size = 100
def sumOfPow(size:Int) = (1 to size).map( math.pow(_, 2) ).sum.toInt
def powOfSum(size:Int) = math.pow((1 to size).sum, 2).toInt
val result = powOfSum(size) - sumOfPow(size)
println(result) // 25164150
@outsideris
outsideris / p005.scala
Created May 18, 2013 13:22
euler problem 5
def factorize(n: Int, divider:Int = 2, accum:List[Int] = Nil):List[Int] = {
n match {
case a if a == 1 => accum
case a if a == 2 => n :: accum
case b if b % divider == 0 => factorize(b / divider, divider, divider :: accum)
case _ => factorize(n, divider + 1, accum)
}
}
def getMap(l:List[Int]) = l.groupBy(_.toString).mapValues(_.length)
// from https://github.com/mperham/sidekiq/commit/c1127165f8157807e7855c60f9849d20fb9fec24?utm_source=buffer&utm_medium=twitter&utm_campaign=Buffer&utm_content=buffer0a96b
def self.(╯°□°)╯︵┻━┻
puts "Calm down, bro"
end
@outsideris
outsideris / nginx.conf
Created April 24, 2013 02:55
nginx setting skeleton
user outsider;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
@outsideris
outsideris / osx.sh
Created April 23, 2013 17:58
OSX Setting command
# PostgreSql (homebrew로 설치)
$ initdb /usr/local/var/postgres -E utf8
## to Start
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
## 상태확인
$ pg_ctl -D /usr/local/var/postgres status
## stop
pg_ctl -D /usr/local/var/postgres stop -s -m fast
@outsideris
outsideris / ubuntu-setting.sh
Last active December 16, 2015 13:59
Ubuntu setting & troubleshutting
# 사용자 추가
$ sudo adduser USERNAME
# sudoers에 사용자 추가 ( outsider ALL=(ALL:ALL) ALL )
$ visudo -f /etc/sudoers
# 기본 우분투용 의존성설치
$ sudo apt-get install build-essential libssl-dev libev-dev
$ sudo apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev
# add-apt-repository 사용