Skip to content

Instantly share code, notes, and snippets.

def rock_judger(rocks_arr)
if rocks_arr.length <= 2 # the base case
a = rocks_arr[0]
b = rocks_arr[-1]
else
a = rock_judger(rocks_arr.slice!(0,rocks_arr.length/2))
b = rock_judger(rocks_arr)
end
return a > b ? a : b
def rock_judger(rocks_arr)
#if rocks_arr.length <= 2 # the base case
a = rocks_arr[0]
b = rocks_arr[1]
#b = rocks_arr[-1]
#else
def rock_judger(rocks_arr)
if rocks_arr.length <= 2 # the base case
a = rocks_arr[0]
#b = rocks_arr[1]
b = rocks_arr[-1]
else
def factorize(orig)
factors = {}
factors.default = 0 # return 0 instead nil if key not found in hash
n = orig
i = 2
sqi = 4 # square of i
while sqi <= n do
while n.modulo(i) == 0 do
n /= i
factors[i] += 1
@varreli
varreli / gist:6ed319b53132e4dbab98f82e64801aac
Created June 1, 2017 00:32
terminal output of installation of vim and haskell-vim-now
~ $ sudo apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
vim-doc vim-scripts
The following NEW packages will be installed:
vim
0 upgraded, 1 newly installed, 0 to remove and 316 not upgraded.
Need to get 0 B/976 kB of archives.
@varreli
varreli / gist:7e3e9b158a399087c0c31d236dde82ee
Created June 1, 2017 00:49
also having trouble with stack
I'm running $ stack build primality now , and getting the same very slow process that I got for $ stack new primality:
~/haskell $ stack new primality
Downloading template "new-template" to create project "primality" in primality/ ...
The following parameters were needed by the template but not provided:
author-email, author-name, category, copyright, github-username
You can provide them in /home/john/.stack/config.yaml, like this:
templates:
params:
λ > :l 75_taut.hs
[1 of 1] Compiling Main ( 75_taut.hs, interpreted )
75_taut.hs:2:1: error:
Failed to load interface for ‘Propositions’
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
λ >
~/haskell/hutton]
$ ls
001_math 28_and_all.hs 59_chapt7.hs
002_notes 29_recurse.hs 59_chapt7i.hs
01_qsort.hs 30_merge.hs 60_redefines.hs
02_last.hs 31_mergeSample.hs 61_iterate.hs
03_init.hs 32_mSort.hs 62_parity.hs
04_abs.hs 33_core.hs 63_parity2.hs
05_twice.hs 34_core.hs 64_altMap.hs
06_patMatch.hs 35_basicMap.hs 65_luhn.hs
split :: [a] -> [([a], [a])]
split [] = []
split [_] = []
split (x:xs) = ([x], xs) : [(x:ls, rs) | (ls, rs) <- split xs]
-- auxillary function combine in exprs:
combine :: Expr -> Expr -> [Expr]
combine l r = [App o l r | o <- ops]
import ShowExpression
subs :: [a] -> [[a]]
subs [] = [[]]
subs (x:xs) = yss ++ map (x:) yss
where yss = subs xs
interleave :: a -> [a] -> [[a]]
interleave x [] = [[x]]