How to resolve the algorithm Amicable pairs step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Amicable pairs step by step in the Quackery programming language

Table of Contents

Problem Statement

Two integers

N

{\displaystyle N}

and

M

{\displaystyle M}

are said to be amicable pairs if

N ≠ M

{\displaystyle N\neq M}

and the sum of the proper divisors of

N

{\displaystyle N}

(

s u m

(

p r o p D i v s

( N ) )

{\displaystyle \mathrm {sum} (\mathrm {propDivs} (N))}

)

= M

{\displaystyle =M}

as well as

s u m

(

p r o p D i v s

( M ) )

N

{\displaystyle \mathrm {sum} (\mathrm {propDivs} (M))=N}

.

1184 and 1210 are an amicable pair, with proper divisors:

Calculate and show here the Amicable pairs below 20,000; (there are eight).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Amicable pairs step by step in the Quackery programming language

Source code in the quackery programming language

  [ properdivisors 
    dup size 0 = iff
      [ drop 0 ] done 
    behead swap witheach + ] is spd           ( n --> n )
    
  [ dup dup spd dup spd 
    rot = unrot > and ]      is largeamicable ( n --> b )
    
  [ [] swap times
      [ i^ largeamicable if
        [ i^ dup spd
          swap join 
          nested join ] ] ]  is amicables     ( n --> [ )
          
  20000 amicables witheach [ witheach [ echo sp ] cr ]

  

You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the REBOL programming language
You may also check:How to resolve the algorithm Determine if a string is numeric step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Faces from a mesh step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sorting algorithms/Comb sort step by step in the OCaml programming language
You may also check:How to resolve the algorithm Quine step by step in the F# programming language