church 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/church/utils.rb +9 -0
- data/lib/church/version.rb +1 -1
- data/spec/utils_spec.rb +15 -0
- metadata +1 -1
data/lib/church/utils.rb
CHANGED
@@ -5,4 +5,13 @@ module Church::Utils
|
|
5
5
|
ord > 64 && ord < 91 ? CHR[(ord - 78) % 26 + 65] :
|
6
6
|
ord > 96 && ord < 123 ? CHR[(ord - 110) % 26 + 97] : chr
|
7
7
|
}
|
8
|
+
|
9
|
+
COLLATZ = -> n {
|
10
|
+
c = [n]
|
11
|
+
(collatz_p = -> {
|
12
|
+
n = n % 2 == 0 ? n / 2 : n * 3 + 1
|
13
|
+
c << n
|
14
|
+
n == 1 ? c : collatz_p[]
|
15
|
+
})[]
|
16
|
+
}
|
8
17
|
end
|
data/lib/church/version.rb
CHANGED
data/spec/utils_spec.rb
CHANGED
@@ -12,4 +12,19 @@ describe 'ROT13' do
|
|
12
12
|
expect(ROT13['M']).to eq 'Z'
|
13
13
|
expect(ROT13['Z']).to eq 'M'
|
14
14
|
end
|
15
|
+
|
16
|
+
it "should not touch a non-alphabetical character" do
|
17
|
+
expect(ROT13['!']).to eq '!'
|
18
|
+
expect(ROT13[' ']).to eq ' '
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'COLLATZ' do
|
23
|
+
it "should return its arguments Collatz sequence as an array" do
|
24
|
+
expect(COLLATZ[10]).to eq [10, 5, 16, 8, 4, 2, 1]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should work on 194" do
|
28
|
+
expect(SIZE[COLLATZ[194]]).to be 120
|
29
|
+
end
|
15
30
|
end
|