Created
March 12, 2012 22:57
-
-
Save vivus-ignis/2025246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env tclsh | |
set amount [lindex $::argv 0] | |
set coins_values [lrange $::argv 1 end] | |
proc max_coin { coin_list } { | |
lindex [lsort -integer $coin_list] end | |
} | |
proc xchange { val biggest } { | |
global change | |
global coins_values | |
set num_of_big [ expr $val / $biggest ] | |
for {set x 0} {$x < $num_of_big} {incr x} { lappend change $biggest } | |
set rest [ expr $val % $biggest ] | |
set coins_values [lreplace $coins_values end end] | |
if { $rest != 0 } { | |
xchange $rest [max_coin $coins_values] | |
} else { | |
puts $change | |
} | |
} | |
set change {} | |
xchange $amount [max_coin $coins_values] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment