2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rubyで回分数の判定

Last updated at Posted at 2020-12-30

入力された数値が回分数(逆から数値を並べても同じになる数値)の判定

# 回分数であればtrueを返す
def checkPalindromicNumber(number)
  number = number.to_s
  size = number.length / 2 - 1
  return ( number[0..size] == number.reverse[0..size] )
end

↓修正版

def palindromic_number?(number)
  number.to_s == number.to_s.reverse
end
2
1
2

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?