How to resolve the algorithm Cyclops numbers step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cyclops numbers step by step in the Arturo programming language

Table of Contents

Problem Statement

A cyclops number is a number with an odd number of digits that has a zero in the center, but nowhere else. They are named so in tribute to the one eyed giants Cyclops from Greek mythology. Cyclops numbers can be found in any base. This task strictly is looking for cyclops numbers in base 10. There are many different classifications of cyclops numbers with minor differences in characteristics. In an effort to head off a whole series of tasks with tiny variations, we will cover several variants here.

(Note: there are no cyclops numbers between ten million and one hundred million, they need to have an odd number of digits)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Cyclops numbers step by step in the Arturo programming language

Source code in the arturo programming language

cyclops?: function [n][
    digs: digits n
    all? @[
        -> odd? size digs
        -> zero? digs\[(size digs)/2]
        -> 1 = size match to :string n "0"
    ]
]

blind: function [x][
    s: to :string x 
    half: (size s)/2 
    to :integer (slice s 0 dec half)++(slice s inc half dec size s)
]

findFirst50: function [what, start, predicate][
    print ["First 50" what++"cyclops numbers:"]
    first50: new start
    i: 100
    while [50 > size first50][
        if do predicate -> 'first50 ++ i
        i: i + 1
    ]

    loop split.every:10 first50 'row [ 
        print map to [:string] row 'item -> pad item 7
    ]
    print ""
]

findFirst50 "" [0] -> cyclops? i
findFirst50 "prime " [] -> and? [prime? i][cyclops? i]
findFirst50 "blind prime " [] -> all? @[
    -> prime? i
    -> cyclops? i
    -> prime? blind i
]

candidates: map 1..999 'x ->
    to :integer (to :string x)++"0"++(reverse to :string x)

print "First 50 palindromic prime cyclops numbers:"
loop split.every:10 first.n: 50 select candidates 'x -> and? [prime? x][cyclops? x] 'row [ 
    print map to [:string] row 'item -> pad item 7
]


  

You may also check:How to resolve the algorithm Higher-order functions step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the C programming language
You may also check:How to resolve the algorithm 9 billion names of God the integer step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Pentomino tiling step by step in the 11l programming language