Instantly share code, notes, and snippets.

View refactor.rb
# using ruby_parser from https://github.com/seattlerb/ruby_parser
# also ruby2ruby for convert sexps to ruby code: sudo gem install ruby2ruby
require 'ruby_parser'
require 'ruby2ruby'
def load
txt = ''
while line = gets
txt += line
end
View gist:e29eb62c44795ccbb6a9767a3d13068d
# Caveat that picking "year one" is kind of arbitrary, and that these
# are just random numbers from the internet, not meant as canonical sources
Year Google Facebook Twitter Uber
1 11 7 8
2 60 15 29
3 284 150 130 60
4 682 450 350 170
5 1628 850 833 1000
6 3021 1218 2712
View 14.hs
module Main (main) where
col :: Int -> [Int] -> [Int]
col 1 acc = acc
col n acc | n `mod` 2 == 0 = col (n `div` 2) (n:acc)
| otherwise = col (3 * n + 1) (n:acc)
opts :: Int -> [(Int, Int)]
opts n = [(length(col x []), x) | x <- [1..n]]
View min_coins.hs
module Main (main) where
minOrZero lst = if null lst then 0 else minimum lst
coins 0 _ = 0
coins v ds = (1 + minOrZero [coins (v - d) ds | d <- ds, (v - d) >= 0])
main = do print "start"
print (coins 57 [1, 5, 10, 25])
print (coins 15 [1, 6, 9, 10])