Three runners, Kan, Ga and Roo took part in a cross country race. Prior to the race, four spectators from the audience, A, B, C, and D, made their prognoses, as follows: A: Either Kan or Ga will win. B: If Ga is the second, Roo will win. C: If Ga is the third, Kan will not win. D: Either Ga or Roo will be the second. After the race, it turned out that all four statements were correct. In what order did the runners finish? 1. Kan, Ga, Roo 2. Kan, Roo, Ga 3. Roo, Ga, Kan 4. Ga, Roo, Kan 5. Impossible to determine
The Solution:
#lang racket (require racklog) (define %solve (%rel (f s t members)( (f s t) (%= members (list 'Kan 'Ga 'Roo) ) (%member f members) (%member s members) (%member t members) (%and (%/== f s) (%/== f t) (%/== s t)) (%or (%== f 'Kan) (%== f 'Ga)) ;prognose A - Either Kan or Ga will win (%if-then-else (%== s 'Ga) (%== f 'Roo) %true ) ;prognose B - If Ga is the second, Roo will win. (%if-then-else (%== t 'Ga) (%== s 'Kan) %true ) ;prognose C - If Ga is the third, Kan will not win (%or (%== s 'Roo) (%== s 'Ga)) ;prognose D - Either Ga or Roo will be the second. ) ) ) ;find all possible solution (%which(first second third)(%solve first second third)) (%more)
The Answer:
'((first . Ga) (second . Roo) (third . Kan)) #f
No comments:
Post a Comment