## Project Euler Problem #55

### May 20, 2010

Read the details of the problem here

Summary

How many Lychrel numbers are there below ten-thousand?

Solution

Very straightforward. I even used a couple of BigInteger metaClass extensions to make it more readable, well, perhaps more readable! The algorithm was just a simple implementation of the details in the question.

```BigInteger.metaClass.isPalindrome() { ->
def s = delegate.toString()
s == s.reverse()
}

BigInteger.metaClass.reverse() { ->
delegate.toString().reverse().toBigInteger()
}

for (i in 1G..<10000G) {
def n = i
for (c in 0..50) {
n += n.reverse()
if (n.isPalindrome()) {
break
}
}
}
```

Not much else to say on this, it just does what it says on the tin. It runs in 0.39 seconds.

It’s possible to do this as a one-liner with Groovy listops but it’s not as clear as to what’s going on – or maybe it is?

```BigInteger.metaClass.isPalindrome() { ->
def s = delegate.toString()
s == s.reverse()
}

BigInteger.metaClass.reverse() { ->
delegate.toString().reverse().toBigInteger()
}