Skip to content

Commit

Permalink
Integer#franel: Add
Browse files Browse the repository at this point in the history
  • Loading branch information
runpaint committed Mar 17, 2010
1 parent c9dcfd5 commit bc47039
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/numb/franel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# coding: utf-8
class Integer
def franel
(0..self).map{|k| choose(k) ** 3 }.reduce(:+)
end
end
2 changes: 2 additions & 0 deletions lib/numb/number_of_divisors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Integer

# Returns the number of divisors of self
def τ
# TODO: Consider something simpler, and perhaps faster, like
# primaries.map(&:last).map(&:succ).reduce(:*)
n = self
return @nod if defined?(@nod)
@nod = (1..isqrt).
Expand Down
15 changes: 15 additions & 0 deletions spec/numb/franel_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# coding: utf-8
describe Integer, "#franel" do
# A000172
@seq = [1,2,10,56,346,2252,15184,104960,739162,5280932,
38165260,278415920,2046924400,15148345760,
112738423360,843126957056,6332299624282,
47737325577620,361077477684436,2739270870994736,
20836827035351596]

@seq.each_with_index do |franel, n|
it "returns #{franel} for #{n}" do
n.franel.should == franel
end
end
end

0 comments on commit bc47039

Please sign in to comment.