How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Raku programming language

Table of Contents

Problem Statement

It's permissible to assume the first two numbers and simply list them.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Raku programming language

Source code in the raku programming language

constant palindromes = 0, 1, |gather for 1 .. * -> $p {
    my $pal = $p.base(3);
    my $n = :3($pal ~ '1' ~ $pal.flip);
    next if $n %% 2;
    my $b2 = $n.base(2);
    next if $b2.chars %% 2;
    next unless $b2 eq $b2.flip;
    take $n;
}

printf "%d, %s, %s\n", $_, .base(2), .base(3) for palindromes[^6];


  

You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Flow-control structures step by step in the Relation programming language
You may also check:How to resolve the algorithm Pathological floating point problems step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Echo server step by step in the Tcl programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the PowerShell programming language