Intuitive Ruby Solution


  • 0
    I
    require 'minitest/autorun'
    
    class FooTest < Minitest::Test
      def is_ugly(num)
        return false  if num <= 0
        return true   if num == 1
    
        primes = [2,3,5]
    
        primes.each do |i|
          while num % i == 0
            num /= i
          end
        end
    
        num == 1
      end
    
      def test_run
        assert is_ugly(1)
        assert is_ugly(2)
        assert is_ugly(3)
        assert is_ugly(4)
        assert is_ugly(5)
        assert is_ugly(6)
        refute is_ugly(7)
        assert is_ugly(8)
        refute is_ugly(14)
      end
    end
    
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.