rmathemata 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arithmetic.rb +36 -36
- metadata +4 -3
data/lib/arithmetic.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/local/bin/ruby -Kuw
|
2
|
-
|
3
2
|
module Kernel
|
4
3
|
|
5
4
|
def ∑(values)
|
@@ -24,52 +23,53 @@ module Kernel
|
|
24
23
|
|
25
24
|
end
|
26
25
|
|
27
|
-
module
|
28
|
-
|
26
|
+
module RMathemata
|
27
|
+
module Integer
|
28
|
+
require 'mathn'
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def gcdn integers
|
31
|
+
return self unless integers.any?
|
32
|
+
self.gcd integers.shift.gcdn(integers)
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def prime_powers
|
36
|
+
prime_division.map(&:pop)
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def is_powerful?
|
40
|
+
return true if self == 1
|
41
|
+
prime_powers.min >= 2
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
def is_perfect_power?
|
45
|
+
n = 1
|
46
|
+
loop do
|
47
|
+
n += 1
|
48
|
+
root = self**(1/n)
|
49
|
+
return true if root.is_a?(Integer)
|
50
|
+
return false if root < 2
|
51
|
+
end
|
51
52
|
end
|
52
|
-
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def is_achilles_number?
|
55
|
+
is_powerful? and not is_perfect_power?
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def euler_totient
|
59
|
+
return 1 if self == 1
|
60
|
+
self * ∏x("1 - 1/p", "p", prime_division.map(&:first))
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
def is_strong_achilles_number?
|
64
|
+
is_achilles_number? and euler_totient.is_achilles_number?
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
def numbers_of_strong_achilles_numbers_below
|
68
|
+
1.upto(self).inject(0) {|total, number| total += 1 if number.is_strong_achilles_number? ; total}
|
69
|
+
end
|
69
70
|
end
|
70
|
-
|
71
71
|
end
|
72
72
|
|
73
73
|
class Integer
|
74
|
-
include
|
74
|
+
include RMathemata::Integer
|
75
75
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmathemata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Philippe Cantin
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-17 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|