aboutsummaryrefslogtreecommitdiff
path: root/challenge-085/roger-bell-west/ruby/ch-2.rb
blob: a226f96a02603fcc56cf7814ad9e565a5f52f21e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/ruby

def pti(n)
  l=Math.log(n)
  2.upto(Math.sqrt(n).floor) do |ca|
    bg=(l/Math.log(ca)).floor
    bg.upto(bg+1) do |cb|
      if ca ** cb == n
        return 1
      end
    end
  end
  return 0
end

require 'test/unit'

class TestPti < Test::Unit::TestCase

  def test_ex1
    assert_equal(1,pti(8))
  end

  def test_ex2
    assert_equal(0,pti(15))
  end

  def test_ex3
    assert_equal(1,pti(125))
  end

end