Skip to content

Instantly share code, notes, and snippets.

@P-Seebauer
Last active September 24, 2015 21:12
Show Gist options
  • Save P-Seebauer/7f4f644c61fe9875f5aa to your computer and use it in GitHub Desktop.
Save P-Seebauer/7f4f644c61fe9875f5aa to your computer and use it in GitHub Desktop.
coin counter
h=100
IO.puts(([200,h,50,20,10,5,2,1]|>Enum.reduce{h*elem(Float.parse(hd System.argv),0)|>trunc,[]},fn(i,{c,l})->{rem(c,i),List.duplicate(i<h&&"#{i}¢ "||"#{div(i,h)}€ ",div(c,i))++l}end)|>elem 1)
h=100
main = do
a <- getLine
putStr$foldl1(\x y->x++' ':y)$snd$foldl(\(y,z)x->(y`mod`x,z++(replicate(y`div`x)$if x`mod`h==0then show(x`div`h)++"€"else(show x)++"¢")))(truncate(((read a)::Float)*100),[])[200,h,50,20,10,5,2,1]
i=process.argv[2],r=[];for(c of [2,1,.5,.2,.1,.05,.02,.01])while(c>i){r.push(c>.5?c+'€':c*100+'¢');i-=c}console.log(r)
for(r=[],b=[1,2,5,10,20,50,h=100,200],i=process.argv[2]*h;c=b.pop();)for(;c<i;i-=c)r.push(c<h?c+'¢':c/h+'€');console.log(r)
my$x=prompt '';say gather for 2,1,.5,.2,.1,.05,.02,.01 {while $x>=$_ {take $_>.5??"$_€"!!"{$_*100}¢";$x-=$_}}
#!/usr/bin/swipl -q -s
z(X,[A|R],S):-X>=A,z(X-A,[A|R],Y),S=[A|Y];z(X,R,S).
z(X,[],[]):-0=:=X.
y(X):-X>99->format('~I€ ',X/100);format('~I¢ ',X).
x(X):-z(X*100,[200,100,50,20,10,5,2,1],Y),maplist(y,Y).
:-write('enter number (finish with .)\n>'),read(X),x(X).
@P-Seebauer
Copy link
Author

Versions:

  • Elixir 1.0.5
  • This is perl6 version 2015.05-139-g2281689 built on MoarVM version 2015.05-49-g07fbd62
  • iojs: v3.3.1
  • SWI-Prolog version 6.6.6 for amd64
  • node: v0.12.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment