1
exercism fetch gnu-apl raindrops

raindrops.tc

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
log←'./raindrops.tc.log'
⍎ ')COPY ',(⎕FIO 30),'/../../test.apl'

test∆copy_relative 'raindrops.apl'
test∆clear_log log

⍝ ∇convert
⍝ Given an integer, returns a string representation of that integer's "raindrop sound", based on its prime factors.

⍝ the sound for 1 is '1'
  1⎕CR convert 1
'1'

⍝ the sound for multiples of 3 is 'Pling'
  convert 3
Pling
  convert 6
Pling

⍝ the sound for multiples of 5 is 'Plang'
  convert 5
Plang
  convert 10
Plang

⍝ the sound for multiples of 7 is 'Plong'
  convert 7
Plong
  convert 14
Plong

⍝ the sound for numbers that aren't multiples of 3, 5, or 7 is the stringified number
  1⎕CR convert 8
'8'
  1⎕CR convert 52
'52'

⍝ the sound for numbers that have multiple raindrop factors is the combination of all the sounds
  convert 15 ⍝ 3×5
PlingPlang
  convert 21 ⍝ 3×7
PlingPlong
  convert 35 ⍝ 5×7
PlangPlong
  1⎕CR convert 105 ⍝ 3×5×7
'PlingPlangPlong'

⍝ the sound for powers of a raindrop factor is only the single sound
  convert 9 ⍝ 3×3
Pling
  convert 25 ⍝ 5×5
Plang
  convert 49 ⍝ 7×7
Plong
  convert 27 ⍝ 3*3
Pling
  convert 3125 ⍝ 5*5
Plang

test∆show_log log