Skip to content

Instantly share code, notes, and snippets.

@vivus-ignis
Created March 12, 2012 22:57
Show Gist options
  • Save vivus-ignis/2025246 to your computer and use it in GitHub Desktop.
Save vivus-ignis/2025246 to your computer and use it in GitHub Desktop.
#!/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