# Lychrel numbers

```ruby
var (
    lychrels = [],
    palindromes = [],
    seeds = [],
    max = 500,
)

for i in (1 .. 10_000) {
    var (test = [], count = 0)

    func lychrel(l) {
        count++ > max && return true
        test << (var m = (l + l.flip))
        m.is_palindrome && return false
        lychrel(m)
    }

    if (lychrel(i)) {
        lychrels << Pair(Str(i), test)
    }
}

seeds << lychrels[0]

for l in lychrels {
    if (l.key.is_palindrome) {
        palindromes << l.key
    }

    var h = Hash()
    h.set_keys(l.value...)

    var trial = seeds.count_by { |s|
        s.value.any { |k| h.contains(k) } ? break : true
    }

    if (trial == seeds.len) {
        seeds << l
    }
}

say ("   Number of Lychrel seed numbers < 10_000: ", seeds.len)
say ("             Lychrel seed numbers < 10_000: ", seeds.map{.key}.join(', '))
say ("Number of Lychrel related numbers < 10_000: ", lychrels.len - seeds.len)
say ("    Number of Lychrel palindromes < 10_000: ", palindromes.len)
say ("              Lychrel palindromes < 10_000: ", palindromes.join(', '))
```

#### Output:

```
   Number of Lychrel seed numbers < 10_000: 5
             Lychrel seed numbers < 10_000: 196, 879, 1997, 7059, 9999
Number of Lychrel related numbers < 10_000: 244
    Number of Lychrel palindromes < 10_000: 3
              Lychrel palindromes < 10_000: 4994, 8778, 9999
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/l/lychrel_numbers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
