首页 > 代码库 > projecteuler---->problem=36----Double-base palindromes
projecteuler---->problem=36----Double-base palindromes
Problem 36
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
(Please note that the palindromic number, in either base, may not include leading zeros.)
def isCycle(n): if n%10 == 0: return False tempN = n num=list() while n > 0: num.insert(0,n%2) n /= 2 for i in range(0,int(len(num)/2)): if num[i] != num[len(num)-i-1] : return False value = http://www.mamicode.com/list()>class String def isCycle? self == self.reverse end end puts (1..1000000).select{|i| i.to_s.isCycle? && i.to_s(2).isCycle? }.reduce(:+)
projecteuler---->problem=36----Double-base palindromes
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。