LoginSignup
3
1

More than 3 years have passed since last update.

Project EulerをHaskellで解いていく(Problem4: Largest palindrome product)

Last updated at Posted at 2019-02-20

TL;DR

Haskellの勉強を兼ねてProject Eulerを解いていきます。
始めたばかりでわからないことが多いのでコメント頂けると嬉しいです。

問題文

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.

左右どちらから読んでも同じ値になる数を回文数という. 2桁の数の積で表される回文数のうち, 最大のものは 9009 = 91 × 99 である.
では, 3桁の数の積で表される回文数の最大値を求めよ.

コード

isPalindrome::Int -> Bool
isPalindrome n = show n == reverse(show n)

main::IO()
main = do
  print $ maximum [x * y | x <- [100..999], y <- [100..999], isPalindrome(x * y)]
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1