There are 2 places of memory in Python program.
- Heap: value of variables, functions recipe bind w/ memory address. e.g.
- memory addr:
x1
-> int: 42
from fractions import Fraction | |
from math import factorial | |
from operator import mul | |
from functools import reduce | |
def product(member): | |
return reduce(mul, member) | |
def repile(minimum, remain_piles, remain_dishes, case, stack=[]): |
repile r 1 d m s = if d >= head s then (d:s):r else r | |
repile r p d m s = do | |
if d > m | |
then repile (repile r (p-1) (d-m) m (m:s)) p d (m+1) s | |
else r | |
mkpile r 0 d m = mkpile r (d `div` m) d m | |
mkpile r p d m = do | |
if p > 1 | |
then mkpile (repile r p d m []) (p-1) d m |
e n = 1 + (foldr1 (\ a x -> a + 1 / x) $ take n [i ^ j | i <- [2,4..], j <- [0,0,1]]) | |
-- sample: | |
-- e 1 -> 2.0 | |
-- e 2 -> 3.0 | |
-- e 6 -> 2.71875 | |
-- e 100 -> 2.7182818284590455 | |
-- see more: | |
-- <http://en.wikipedia.org/wiki/E_(mathematical_constant)#Representations> |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2012 Nattawut Phetmak <http://about.me/neizod> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
-- groupIndices 5 [1..20] -> [[1,6,11,16],[2,7,12,17],[3,8,13,18],[4,9,14,19],[5,10,15,20]] | |
groupIndices n = map reverse . foldl (\a x -> [if length h /= length t then x:h else h | (h,t) <- zip a ((42:last a):init a)]) (take n $ repeat []) |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2013 Nattawut Phetmak <http://about.me/neizod> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
^. | |
Xx\. | |
X| x\. | |
X| ^x) | |
X| / ._ | |
<X\. / x\. | |
^ X\ x\._ | |
_..xxXXxx.__ ^x%%/^ | |
./x/ ^\x.. | |
~^^^ _. ._ ^^ |