Avatar of craigmaloney

craigmaloney's solution

to Raindrops in the Scheme Track

Published at Jul 13 2018 · 0 comments
Test suite

Convert a number to a string, the contents of which depend on the number's factors.

  • If the number has 3 as a factor, output 'Pling'.
  • If the number has 5 as a factor, output 'Plang'.
  • If the number has 7 as a factor, output 'Plong'.
  • If the number does not have 3, 5, or 7 as a factor, just pass the number's digits straight through.


  • 28's factors are 1, 2, 4, 7, 14, 28.
    • In raindrop-speak, this would be a simple "Plong".
  • 30's factors are 1, 2, 3, 5, 6, 10, 15, 30.
    • In raindrop-speak, this would be a "PlingPlang".
  • 34 has four factors: 1, 2, 17, and 34.
    • In raindrop-speak, this would be "34".


A variation on a famous interview question intended to weed out potential candidates. http://jumpstartlab.com

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


;; Load SRFI-64 lightweight testing specification
(use-modules (srfi srfi-64))

;; Suppress log file output. To write logs, comment out the following line:
(module-define! (resolve-module '(srfi srfi-64)) 'test-log-to-file #f)

(add-to-load-path (dirname (current-filename)))

(use-modules (raindrops))

(test-begin "raindrops")

(test-equal "test-1"
            (convert 1))

(test-equal "test-3"
            (convert 3))

(test-equal "test-5"
            (convert 5))

(test-equal "test-7"
            (convert 7))
(test-equal "test-6"
            (convert 6))
(test-equal "test-9"
            (convert 9))
(test-equal "test-10"
            (convert 10))
(test-equal "test-15"
            (convert 15))
(test-equal "test-21"
            (convert 21))
(test-equal "test-25"
            (convert 25))
(test-equal "test-35"
            (convert 35))
(test-equal "test-49"
            (convert 49))
(test-equal "test-52"
            (convert 52))
(test-equal "test-105"
            (convert 105))
(test-equal "test-12121"
            (convert 12121))

(test-end "raindrops")
(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)

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?