raindrops.scm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(define-module (raindrops)
  #:export (convert))

(define (factor number)
  (define (*factor divisor number)
    (if (>= divisor number)
      (list number)
      (if (= (remainder number divisor) 0)
        (cons divisor (*factor (+ 1 divisor) number ))
        (*factor (+ divisor 1) number))))
  (*factor 1 number))

(define (convert number)
  (let ((outstring "")
        (factors (factor number)))
    (if (memq 3 factors)
      (set! outstring (string-append outstring "Pling")))
    (if (memq 5 factors)
      (set! outstring (string-append outstring "Plang")))
    (if (memq 7 factors)
      (set! outstring (string-append outstring "Plong")))

    (if (string=? outstring "")
      (number->string number)
      outstring
      )
    )
  )

Comments


You're not logged in right now. Please login via GitHub to comment