 # craigmaloney's solution

## to Raindrops in the Scheme Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

#### Note:

This solution was written on an old version of Exercism. The tests below might not correspond to the solution code, and the exercise may have changed since this code was written.

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.

## Examples

• 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".

## Source

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.

### raindrops-test.scm

``````;; 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)

(use-modules (raindrops))

(test-begin "raindrops")

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

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

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

(test-equal "test-7"
"Plong"
(convert 7))
(test-equal "test-6"
"Pling"
(convert 6))
(test-equal "test-9"
"Pling"
(convert 9))
(test-equal "test-10"
"Plang"
(convert 10))
(test-equal "test-15"
"PlingPlang"
(convert 15))
(test-equal "test-21"
"PlingPlong"
(convert 21))
(test-equal "test-25"
"Plang"
(convert 25))
(test-equal "test-35"
"PlangPlong"
(convert 35))
(test-equal "test-49"
"Plong"
(convert 49))
(test-equal "test-52"
"52"
(convert 52))
(test-equal "test-105"
"PlingPlangPlong"
(convert 105))
(test-equal "test-12121"
"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)
outstring
)
)
)``````