Skip to content

Commit

Permalink
Integer#dodecagonal?: Add
Browse files Browse the repository at this point in the history
  • Loading branch information
runpaint committed Jan 5, 2010
1 parent e31b872 commit 423ae01
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/numb.rb
@@ -1,10 +1,10 @@
# coding: utf-8

libs = %w{abundant achilles automorphic balanced_prime carol composite
decagonal deficient cube dihedral_prime dudeney economical emrip
equidigital extravagant factorion frugal happy harshad heptagonal
hexagonal hilbert hyperperfect impolite kaprekar keith kynea lucas
lucas_carmichael mms_pair mobius narcissistic nivenmorphic
libs = %w{abundant achilles automorphic balanced_prime carol composite cube
decagonal deficient dodecagonal dihedral_prime dudeney economical
emrip equidigital extravagant factorion frugal happy harshad
heptagonal hexagonal hilbert hyperperfect impolite kaprekar keith
kynea lucas lucas_carmichael mms_pair mobius narcissistic nivenmorphic
n_gonal octagonal ordinal parasitic pentagonal perfect
perfect_power polite polydivisible powerful practical
primitive_pseudoperfect pronic rhonda self self_descriptive
Expand Down
5 changes: 5 additions & 0 deletions lib/numb/dodecagonal.rb
@@ -0,0 +1,5 @@
class Integer
def dodecagonal?
n_gonal?(12)
end
end
18 changes: 18 additions & 0 deletions spec/dodecagonal_spec.rb
@@ -0,0 +1,18 @@
describe Integer, "#dodecagonal?" do

# A051624
DODECAGONAL = [0,1,12,33,64,105,156,217,288,369,460,561,672,793,
924,1065,1216,1377,1548,1729,1920,2121,2332,2553,
2784,3025,3276,3537,3808,4089,4380,4681,4992,5313,
5644,5985,6336,6697,7068,7449,7840,8241,8652]

it "returns true for dodecagonal numbers" do
DODECAGONAL.each{|n| n.should be_dodecagonal}
end

it "returns false for non-dodecagonal numbers" do
((0..DODECAGONAL.last).to_a - DODECAGONAL).each do |n|
n.should_not be_dodecagonal
end
end
end

0 comments on commit 423ae01

Please sign in to comment.