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
Every statement must be converted into an equivalent formula that is in CNF (conjunctive normal form), therefore all patterns of match are OR joined ( is a disjunction of simple terms) and matches are AND joined ( is a conjunction of statements).
The Solution:
(define (check-race-result x) (and ;prognose A - Either Kan or Ga will win (match x [(list 'Kan _ _) #t] [(list 'Ga _ _) #t] [_ #f] ) ;prognose B - If Ga is the second, Roo will win. (match x [(list 'Roo _ _) #t] [(not (list _ 'Ga _ )) #t] [_ #f] ) ;prognose C - If Ga is the third, Kan will not win (match x [(not (list 'Kan _ _)) #t] [(not (list _ _ 'Ga)) #t] [_ #f] ) ;prognose D - Either Ga or Roo will be the second. (match x [(list _ 'Ga _) #t] [(list _ 'Roo _) #t] [_ #f] ) ) ) (filter check-race-result (permutations '(Kan Ga Roo)))