Talk:Cyclops numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
(Doh)
(Nice recursive solution)
Line 5: Line 5:


: Indeed you are correct. Thanks. --[[User:Thundergnat|Thundergnat]] ([[User talk:Thundergnat|talk]]) 10:19, 24 June 2021 (UTC)
: Indeed you are correct. Thanks. --[[User:Thundergnat|Thundergnat]] ([[User talk:Thundergnat|talk]]) 10:19, 24 June 2021 (UTC)

==Nice recursive solution==

The cartesian product cP N G, where N and G are lists of integers, returns a list of tuples (n,g) where n and g are all the members of N and G ordered by n then g.
If digits is the list of integers from 1 to 9 then I can define cyclops r s where r is initialized to 100 and s to digits as follows:
for n in cP s s output r*n+g
cyclops (r*10) (cP s digits mapped to 10*n+g)

Revision as of 13:46, 28 June 2021

Don't forget that '0' is a Cyclops number

It has an odd number of digits (namely 1) and it's middle (and only) digit is '0'.

It's also classified as such in OEIS A134808 - Cyclops numbers. --PureFox (talk) 09:22, 24 June 2021 (UTC)

Indeed you are correct. Thanks. --Thundergnat (talk) 10:19, 24 June 2021 (UTC)

Nice recursive solution

The cartesian product cP N G, where N and G are lists of integers, returns a list of tuples (n,g) where n and g are all the members of N and G ordered by n then g. If digits is the list of integers from 1 to 9 then I can define cyclops r s where r is initialized to 100 and s to digits as follows:

 for n in cP s s output r*n+g
 cyclops (r*10) (cP s digits mapped to 10*n+g)