Skip to content

Instantly share code, notes, and snippets.

Will Larson lethain

Block or report user

Report or block lethain

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lethain
lethain / refactor.rb
Created Jan 29, 2018
Example of refactoring Ruby into better Ruby.
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
@lethain
lethain / gist:e29eb62c44795ccbb6a9767a3d13068d
Last active Jun 30, 2019
Headcount by year for some internet companies
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])
You can’t perform that action at this time.