examples/mapcolor.rb
# an alternative version, using iteration instead of recursion
an alternative version, using iteration instead of recursion
an alternative version using iteration instead of recursion
def colorize_iterating  map
  colorized = {}
  map.each do |country, neighbors|
    local_colorized = colorized.clone 
    color = Ambit.choose Colors
    neighbors.each {|n| Ambit.assert colorized[n] != color}
    local_colorized[country] = color
    colorized = local_colorized
  end
  colorized
end
def colorize_iterating map colorized = { } map . each do | country , neighbors | local_colorized = colorized . clone color = Ambit . choose Colors neighbors . each { | n | Ambit . assert colorized [ n ] != color } local_colorized [ country ] = color colorized = local_colorized end colorized end
an alternative version, using iteration instead of recursion
an alternative version using iteration instead of recursion
# map from country to its color # fake a functional view of colorized #puts "considering #{color} for #{country}"
map
<not_specific>