Permalink
Browse files

Integer#liouville: Add

  • Loading branch information...
1 parent 94163ee commit 2140d3665c4ac67a32f37a6ea791f42e0e583f01 @runpaint committed Mar 27, 2010
Showing with 20 additions and 0 deletions.
  1. +4 −0 lib/numb/primes.rb
  2. +16 −0 spec/numb/liouville_spec.rb
View
@@ -153,6 +153,10 @@ def number_of_prime_factors
alias:number_of_prime_factors
alias :roundness :number_of_prime_factors
+ def liouville
+ (-1)**Ω
+ end
+
def prime_factors
return [] if zero?
prime_division.map{|pair| [pair.first] * pair.last}.flatten
@@ -0,0 +1,16 @@
+# coding: utf-8
+describe Integer, "#liouville" do
+ # A008836
+ @seq = [1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,1,1,1,-1,-1,-1,
+ -1,1,1,-1,1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,1,1,
+ 1,-1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,1,1,1,
+ -1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,
+ -1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,
+ -1,1,-1]
+
+ @seq.to_enum.with_index(1).each do |l, n|
+ it "returns #{l} for #{n}" do
+ n.liouville.should == l
+ end
+ end
+end

0 comments on commit 2140d36

Please sign in to comment.