Skip to content

Instantly share code, notes, and snippets.

@airencracken
Created April 5, 2012 02:22
Show Gist options
  • Save airencracken/2307507 to your computer and use it in GitHub Desktop.
Save airencracken/2307507 to your computer and use it in GitHub Desktop.
Perl Golfed Greedy Change Algo
foreach(0..3){$i=<>;$c=" cents\n";$u="";use integer;{$q=$i/25;$d=($i-$q*25)/10;$n=($i-($d*10+$q*25))/5;$p=($i-($q*25+$d*10+$n*5));}$w=$q==0?$u:$q." x 25".$c;$x=$d==0?$u:$d." x 10".$c;$y=$n==0?$u:$n." x 5".$c;$z=$p==0?$u:$p." x 1".$c;chomp$i;print$i." cents:\n".$w.$x.$y.$z."\n";}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment