Skip to content

Instantly share code, notes, and snippets.

View mrklein's full-sized avatar

Alexey Matveichev mrklein

View GitHub Profile
@mrklein
mrklein / gist:2725110
Created May 18, 2012 12:55
Project Euler #74
open List;;
open Printf;;
let rec dfact n =
match n with
0 -> 1
| 1 -> 1
| 2 -> 2
| 3 -> 6
| 4 -> 24
@mrklein
mrklein / 65.ml
Created May 18, 2012 12:57
Project Euler #65
#load "nums.cma";;
open Big_int;;
open List
let p a n =
let rec p_inner acc m =
let pn k =
let an = big_int_of_int (nth a (k - 2))
in
@mrklein
mrklein / 112.py
Created May 18, 2012 17:03
Project Euler #112
#!/usr/bin/python
n = 1
b = 0
def is_bouncy(n):
if len(str(n)) <= 2:
return False
l = map(int, str(n))
inc = all(x <= y for x, y in zip(l, l[1:]))
@mrklein
mrklein / 73.py
Created May 18, 2012 17:18
Project Euler #73
#!/usr/bin/env python
from fractions import gcd
s = 4
e = 12001
nf = 0
for d in xrange(s, e):
@mrklein
mrklein / 47.py
Created May 18, 2012 23:52
Project Euler #47
#!/usr/bin/env python
from libeuler import is_prime
def prime_factors(n, P):
r = []
t = n
while True:
if t == 1:
break
@mrklein
mrklein / 44.ml
Created May 18, 2012 23:54
Project Euler #44
#load "euler.cma";;
open Euler;;
let pentagonal n = n * (3*n - 1) / 2;;
let pentagonal_index n = int_of_float ((1. +. sqrt(1. +. 24. *. float_of_int(n))) /. 6.);;
let is_pentagonal d = (mod_float ((sqrt(24. *. float_of_int(d) +. 1.) +. 1.) /. 6.) 1.) = 0.;;
@mrklein
mrklein / 43.py
Created May 18, 2012 23:56
Project Euler #43
#!/usr/bin/env python
from libeuler import str_permutations
if __name__ == '__main__':
nums = str_permutations('0123456789')
r = []
for n in nums:
n1 = int(n[1:4])
n2 = int(n[2:5])
@mrklein
mrklein / 64.py
Created May 18, 2012 23:58
Project Euler #64
#!/usr/bin/env python
def period(n):
a_0 = int(n ** 0.5)
if a_0 * a_0 == n:
return 0
b, b_0 = a_0, a_0
c, c_0 = n - a_0*a_0, n - a_0*a_0
res = 0
while True:
@mrklein
mrklein / 70.py
Created May 19, 2012 00:01
Project Euler #70
#!/usr/bin/python
from operator import mul
from multiprocessing import Pool, Manager
manager = Manager()
primes_cache = manager.list()
@mrklein
mrklein / gist:2928396
Created June 14, 2012 06:31
Converter
#!/usr/bin/env coffee
path = require 'path'
fs = require 'fs'
util = require 'util'
hat = require 'hat'
argv = require('optimist')
.usage('Usage: $0 --name <deck name> --color <card color> <directory>')
.string(['name', 'color'])
.demand(1)