How to resolve the algorithm Duffinian numbers step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Duffinian numbers step by step in the Raku programming language

Table of Contents

Problem Statement

A Duffinian number is a composite number k that is relatively prime to its sigma sum σ. The sigma sum of k is the sum of the divisors of k.

161 is a Duffinian number.

Duffinian numbers are very common. It is not uncommon for two consecutive integers to be Duffinian (a Duffinian twin) (8, 9), (35, 36), (49, 50), etc. Less common are Duffinian triplets; three consecutive Duffinian numbers. (63, 64, 65), (323, 324, 325), etc. Much, much less common are Duffinian quadruplets and quintuplets. The first Duffinian quintuplet is (202605639573839041, 202605639573839042, 202605639573839043, 202605639573839044, 202605639573839045). It is not possible to have six consecutive Duffinian numbers

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Duffinian numbers step by step in the Raku programming language

Source code in the raku programming language

use Prime::Factor;

my @duffinians = lazy (3..*).hyper.grep: { !.is-prime && $_ gcd .&divisors.sum == 1 };

put "First 50 Duffinian numbers:\n" ~
@duffinians[^50].batch(10)».fmt("%3d").join: "\n";

put "\nFirst 40 Duffinian triplets:\n" ~
    ((^∞).grep: -> $n { (@duffinians[$n] + 1 == @duffinians[$n + 1]) && (@duffinians[$n] + 2 == @duffinians[$n + 2]) })[^40]\
    .map( { "({@duffinians[$_ .. $_+2].join: ', '})" } ).batch(4)».fmt("%-24s").join: "\n";


  

You may also check:How to resolve the algorithm Pentagram step by step in the Julia programming language
You may also check:How to resolve the algorithm Generate Chess960 starting position step by step in the Phix programming language
You may also check:How to resolve the algorithm Keyboard macros step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the Factor programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the Icon and Unicon programming language