How to resolve the algorithm Taxicab numbers step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Taxicab numbers step by step in the J programming language

Table of Contents

Problem Statement

A   taxicab number   (the definition that is being used here)   is a positive integer that can be expressed as the sum of two positive cubes in more than one way.

The first taxicab number is   1729,   which is:

Taxicab numbers are also known as:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Taxicab numbers step by step in the J programming language

Source code in the j programming language

cubes=: 3^~1+i.100 NB. first 100 cubes
triples=: /:~ ~. ,/ (+ , /:~@,)"0/~cubes NB. ordered pairs of cubes (each with their sum)
candidates=: ;({."#. <@(0&#`({.@{.(;,)<@}."1)@.(1<#))/. ])triples

NB. we just want the first 25 taxicab numbers
25{.(,.~ <@>:@i.@#) candidates
┌──┬──────┬────────────┬─────────────┐
117291 1728729 1000
├──┼──────┼────────────┼─────────────┤
241048 4096729 3375
├──┼──────┼────────────┼─────────────┤
3138328 138245832 8000
├──┼──────┼────────────┼─────────────┤
4206831000 196836859 13824
├──┼──────┼────────────┼─────────────┤
53283264 327685832 27000
├──┼──────┼────────────┼─────────────┤
6393128 393043375 35937
├──┼──────┼────────────┼─────────────┤
740033729 393044096 35937
├──┼──────┼────────────┼─────────────┤
84668327 4665619683 27000
├──┼──────┼────────────┼─────────────┤
9642324913 5931917576 46656
├──┼──────┼────────────┼─────────────┤
10657281728 6400029791 35937
├──┼──────┼────────────┼─────────────┤
1111065664 11059246656 64000
├──┼──────┼────────────┼─────────────┤
12110808216 11059219683 91125
├──┼──────┼────────────┼─────────────┤
131343791728 13265154872 79507
├──┼──────┼────────────┼─────────────┤
14149389512 14887724389 125000
├──┼──────┼────────────┼─────────────┤
151654648000 15746454872 110592
├──┼──────┼────────────┼─────────────┤
161712884913 16637513824 157464
├──┼──────┼────────────┼─────────────┤
17195841729 19511210648 185193
├──┼──────┼────────────┼─────────────┤
1821602727 21600010648 205379
├──┼──────┼────────────┼─────────────┤
19216125125 21600091125 125000
├──┼──────┼────────────┼─────────────┤
20262656512 26214446656 216000
├──┼──────┼────────────┼─────────────┤
2131449664 31443227000 287496
├──┼──────┼────────────┼─────────────┤
223202645832 31443232768 287496
├──┼──────┼────────────┼─────────────┤
2332776327000 300763132651 195112
├──┼──────┼────────────┼─────────────┤
24373464216 373248157464 216000
├──┼──────┼────────────┼─────────────┤
2540259774088 328509175616 226981
└──┴──────┴────────────┴─────────────┘


   x:each 7 {. 1999 }. (,.~ <@>:@i.@#) ;({."#. <@(0&#`({.@{.(;,)<@}."1)@.(1<#))/. ])/:~~.,/(+,/:~@,)"0/~3^~1+i.10000
┌────┬──────────┬────────────────────┬────────────────────┬┐
2000167181638478402752 1593413632830584000 841232384 ││
├────┼──────────┼────────────────────┼────────────────────┼┤
2001167247059224389 1672446203252435968 1420034624││
├────┼──────────┼────────────────────┼────────────────────┼┤
2002167317085696071912 1577098944567663552 1105507304││
├────┼──────────┼────────────────────┼────────────────────┼┤
20031675045225142236648 1532808577411830784 1263214441││
├────┼──────────┼────────────────────┼────────────────────┼┤
20041675958167119095488 1556862679359425431 1316532736││
├────┼──────────┼────────────────────┼────────────────────┼┤
20051676926719250047 1676676672363994344 1312932375││
├────┼──────────┼────────────────────┼────────────────────┼┤
20061677646971970299 1676676672707347971 970299000 ││
└────┴──────────┴────────────────────┴────────────────────┴┘


  

You may also check:How to resolve the algorithm Faulhaber's formula step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Long primes step by step in the Go programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Search a list step by step in the Wart programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the PicoLisp programming language