Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it).

Project Euler 4: Largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99.

Find the largest palindrome made from the product of two 3-digit numbers. 1

class Euler4
 def isPalindrome(n)
 n == n.to_s.reverse.to_i
 end
end
 puts "Setting Variables"
 x = 999
 y = 999
 highest = 1
 found = false
 while (x > 100 && !found)
 y = 999
 while (y > 100 && !found)
 puts "Working with"
 puts x
 puts " and "
 puts y
 if Euler4.new.isPalindrome(x*y)
 puts "Found Palindrome"
 puts x
 puts y
 puts x*y
 if highest < (x*y)
 highest = x * y
 end
 end
 y = y - 1
 end
 x = x - 1
 end
puts "Highest Found"
puts highest

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it).

Project Euler 4: Largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99.

Find the largest palindrome made from the product of two 3-digit numbers. 1

class Euler4
 def isPalindrome(n)
 n == n.to_s.reverse.to_i
 end
end
 puts "Setting Variables"
 x = 999
 y = 999
 highest = 1
 found = false
 while (x > 100 && !found)
 y = 999
 while (y > 100 && !found)
 puts "Working with"
 puts x
 puts " and "
 puts y
 if Euler4.new.isPalindrome(x*y)
 puts "Found Palindrome"
 puts x
 puts y
 puts x*y
 if highest < (x*y)
 highest = x * y
 end
 end
 y = y - 1
 end
 x = x - 1
 end
puts "Highest Found"
puts highest

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it).

Project Euler 4: Largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99.

Find the largest palindrome made from the product of two 3-digit numbers. 1

class Euler4
 def isPalindrome(n)
 n == n.to_s.reverse.to_i
 end
end
 puts "Setting Variables"
 x = 999
 y = 999
 highest = 1
 found = false
 while (x > 100 && !found)
 y = 999
 while (y > 100 && !found)
 puts "Working with"
 puts x
 puts " and "
 puts y
 if Euler4.new.isPalindrome(x*y)
 puts "Found Palindrome"
 puts x
 puts y
 puts x*y
 if highest < (x*y)
 highest = x * y
 end
 end
 y = y - 1
 end
 x = x - 1
 end
puts "Highest Found"
puts highest
edited tags; edited title
Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

Ruby solution to Project Euler Problem #4 Ruby: Largest palindrome product

added 307 characters in body
Source Link
Phrancis
  • 20.5k
  • 6
  • 69
  • 155

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it).

Project Euler 4: Largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99.

Find the largest palindrome made from the product of two 3-digit numbers. 1

class Euler4
 def isPalindrome(n)
 n == n.to_s.reverse.to_i
 end
end
 puts "Setting Variables"
 x = 999
 y = 999
 highest = 1
 found = false
 while (x > 100 && !found)
 y = 999
 while (y > 100 && !found)
 puts "Working with"
 puts x
 puts " and "
 puts y
 if Euler4.new.isPalindrome(x*y)
 puts "Found Palindrome"
 puts x
 puts y
 puts x*y
 if highest < (x*y)
 highest = x * y
 end
 end
 y = y - 1
 end
 x = x - 1
 end
puts "Highest Found"
puts highest

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it).

class Euler4
 def isPalindrome(n)
 n == n.to_s.reverse.to_i
 end
end
 puts "Setting Variables"
 x = 999
 y = 999
 highest = 1
 found = false
 while (x > 100 && !found)
 y = 999
 while (y > 100 && !found)
 puts "Working with"
 puts x
 puts " and "
 puts y
 if Euler4.new.isPalindrome(x*y)
 puts "Found Palindrome"
 puts x
 puts y
 puts x*y
 if highest < (x*y)
 highest = x * y
 end
 end
 y = y - 1
 end
 x = x - 1
 end
puts "Highest Found"
puts highest

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it).

Project Euler 4: Largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×ばつ 99.

Find the largest palindrome made from the product of two 3-digit numbers. 1

class Euler4
 def isPalindrome(n)
 n == n.to_s.reverse.to_i
 end
end
 puts "Setting Variables"
 x = 999
 y = 999
 highest = 1
 found = false
 while (x > 100 && !found)
 y = 999
 while (y > 100 && !found)
 puts "Working with"
 puts x
 puts " and "
 puts y
 if Euler4.new.isPalindrome(x*y)
 puts "Found Palindrome"
 puts x
 puts y
 puts x*y
 if highest < (x*y)
 highest = x * y
 end
 end
 y = y - 1
 end
 x = x - 1
 end
puts "Highest Found"
puts highest
Added tag
Link
forsvarir
  • 11.8k
  • 7
  • 39
  • 72
Loading
Source Link
Loading
lang-rb

AltStyle によって変換されたページ (->オリジナル) /