Solution of Ilhami Gorgun


 (define (f x wd)
  (if (member? x wd) wd (word x wd)))
        
       ;place the given letter in a given word
 (define (union1 sent1 sent2) (accumulate f (word sent1 sent2)))


       ;find the union of two given words
 (define (union2 wd1 wd2 wd3) 
  (accumulate se (union1 (union1 wd1 wd2) wd3)))

       ;find the union of three given words and convert it to a sentence


 (define (order a sent)
  (+ 1 (- (count sent) (count (member a sent)))))

       ;number the position of a given letter in a given sentence

 (define (convert wd sent)
  (if (empty? wd) "" 
       (word (order (first wd) sent) (convert (bf wd) sent)))) 

       ;convert a word to number by "order" its each elements

 (define (turn wd sent)
  (if (empty? wd) "" (word (item (first wd) sent) (turn (bf wd) sent))))

       ;change the word according to the given sentence

 (define (ok? w1 w2 w3 sent)
  (and (equal? (+ (turn w1 sent) (turn w2 sent)) (turn w3 sent))
       (> (item (first w1) sent) 0)
       (> (item (first w2) sent) 0)
       (> (item (first w3) sent) 0)))

       ;check the confliction

 (define (f-main w1 w2 w3 sent1 sent2 a b)
  (cond ((= a (count sent2)) (if (ok? w1 w2 w3 sent2) '() 'fail))
        ((= b (count sent1)) 'fail)
        ((empty? sent1) 'fail)
        (else (if (equal? (f-main w1 w2 w3 (bf sent1) (se sent2
                                                          (first sent1)) a 0)
                'fail)
 
                      
     (f-main w1 w2 w3 (se (bf sent1) (first sent1)) sent2 a (+ 1 b))
     (se (first sent1) (f-main w1 w2 w3 (bf sent1) (se sent2 (first sent1))
                                                                     
                                                                       a 0))))))

       ;form a new sentence according to the given arguments


 (define (combine lst1 lst2)
  (if (equal? lst2 'fail) '()
  (if (null? lst2) '()
     (cons (list (car lst1) (car lst2))
           (combine (cdr lst1) (cdr lst2))))))

       ;combine two lists by one-to-one matching



 (define (solve-1 sent)
  (combine (union2 (car sent) (cadr sent) (caddr sent))
           (f-main (convert (car sent) (union2 (car sent) (cadr sent)  
                                                 (caddr sent)))
                   (convert (cadr sent) (union2 (car sent) (cadr sent)
                                                    (caddr sent)))
                   (convert (caddr sent) (union2 (car sent) (cadr sent)
                                                     (caddr sent)))
          
                   '(0 1 2 3 4 5 6 7 8 9) '()
  
                   (count (union2 (car sent) (cadr sent) (caddr sent)))
    
                   0)))

        ;find the solution set of a given sentence consisting of three words             and combine it with the matching sentence

  (define (my_first sent1 sent2)
   (if (before? (car sent1) (car sent2))
         sent1 sent2))

        ;give the first-coming sentence according to their first elements

  (define (the-first lst)
   (reduce my_first lst))

        ;give the "my_first" of a given list


  (define (ordered lst)
   (if (null? lst) '()
    (if (equal? (the-first lst) (car lst))
         (cons (car lst) (ordered (cdr lst)))
         (ordered (append (cdr lst) (cons (car lst) '()))))))

        ;order a given list according to the alphabetical order and the first            of its elements



  (define (solve-alphametic sent)
    (ordered (solve-1 sent)))

        ;find the solution set of a given sentence consisting of three words