我在Lychrel数字上做Project Euler question 55,其目的是在50次迭代中找到低于10,000的Lychrel数。我想出了这个:
revAdd n = (read $ reverse $ show n) + n
lychrel n | length xs == 50 = error "False"
| ((reverse $ show (revAdd n)) == (show (revAdd n))) = True
| otherwise = (lychrel (revadd n) ) : xs
answer = length [ x | x <- [1..10000] , lychrel x == True]
但我不知道如何将xs
定义为n
之前迭代的列表,这些列表是n
不是回文的时候。我该怎么做呢,其次这会有用吗?