Skip to content

Commit

Permalink
Integer#zeisel?: Add
Browse files Browse the repository at this point in the history
  • Loading branch information
runpaint committed Jan 12, 2010
1 parent d732a4b commit 151600d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/numb.rb
Expand Up @@ -17,7 +17,7 @@
smarandache_wellin smith smooth sophie_germain_prime sphenic square
square_free sublime sum_of_squares superabundant superperfect totient
triangular trimorphic undulating unitary_perfect unitary_divisor
untouchable vampire weird
untouchable vampire weird zeisel
}

class Integer
Expand Down
13 changes: 13 additions & 0 deletions lib/numb/zeisel.rb
@@ -0,0 +1,13 @@
class Integer
def zeisel?
return false unless square_free? and (p=prime_factors.sort.uniq).size >= 3
p.unshift(1)
(1..p.max).any? do |a|
b = p[1] - (a*p[0])
p.each_with_index.all? do |n, i|
next true if i.zero?
n == (a*p[i-1]) + b
end
end
end
end
20 changes: 20 additions & 0 deletions spec/zeisel_spec.rb
@@ -0,0 +1,20 @@
describe Integer, "#zeisel?" do
# A051015
ZEISEL = [105,1419,1729,1885,4505,5719,15387,24211,25085,
27559,31929,54205,59081,114985,207177,208681,
233569,287979,294409,336611,353977,448585,507579,
721907,982513,1012121,1073305,1242709,1485609,
2089257,2263811,2953711,3077705,3506371,3655861,
3973085,4648261,5069629,6173179,6253085,6985249,
7355239,7355671,7558219,8011459,8413179,8444431,
8712985,9271805,9773731,15411785,18175361,
18578113,19827641,20771801,23691481,26000605,
26758057]

# 721907 appears to be in this sequence by error...
(ZEISEL - [721907]).each do |n|
it "should return true for Zeisel number #{n}" do
n.should be_zeisel
end
end
end

0 comments on commit 151600d

Please sign in to comment.