File: quiz70.rb

Project: amb -- amb

#!/usr/bin/env ruby

# Ruby Quiz # 70 -- Constraint Solving
# Copyright 2006 by Jim Weirich
#
# This solution uses a Ruby version of Amb to handle the constraint
# solving.
#
# See the following for details about Amb:
# http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-16.html#node_chap_14

require 'amb'

A = Amb.new

begin
  a = A.choose(*(0..4))
  b = A.choose(*(0..4))
  c = A.choose(*(0..4))
  
  A.assert a < b
  A.assert a + b == c
  
  puts "a=#{a}, b=#{b}, c=#{c}"
  
  A.failure

rescue Amb::ExhaustedError
  puts "No More Solutions"
end


[ Index ][ Presentation ]
Generated by [ source2html ]