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

Published on 12 May 2024 09:40 PM
#J

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

Table of Contents

Problem Statement

Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that the two partition sums are equal.

Even Zumkeller numbers are common; odd Zumkeller numbers are much less so. For values below 10^6, there is at least one Zumkeller number in every 12 consecutive integers, and the vast majority of them are even. The odd Zumkeller numbers are very similar to the list from the task Abundant odd numbers; they are nearly the same except for the further restriction that the abundance (A(n) = sigma(n) - 2n), must be even: A(n) mod 2 == 0

Let's start with the solution:

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

Source code in the j programming language

divisors=: {{ \:~ */@>,{ (^ i.@>:)&.">/ __ q: y }}
zum=: {{ 
  if. 2|s=. +/divs=. divisors y do. 0 
  elseif. 2|y do. (0<k) * 0=2|k=. s-2*y
  else. s=. -:s for_d. divs do. if. d<:s do. s=. s-d end. end. s=0
  end.
}}@>


   10 22$1+I.zum 1+i.1000  NB. first 220 Zumkeller numbers
  6  12  20  24  28  30  40  42  48  54  56  60  66  70  78  80  84  88  90  96 102 104
108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 204 208 210 216
220 222 224 228 234 240 246 252 258 260 264 270 272 276 280 282 294 300 304 306 308 312
318 320 330 336 340 342 348 350 352 354 360 364 366 368 372 378 380 384 390 396 402 408
414 416 420 426 432 438 440 444 448 456 460 462 464 468 474 476 480 486 490 492 496 498
500 504 510 516 520 522 528 532 534 540 544 546 550 552 558 560 564 570 572 580 582 588
594 600 606 608 612 616 618 620 624 630 636 640 642 644 650 654 660 666 672 678 680 684
690 696 700 702 704 708 714 720 726 728 732 736 740 744 750 756 760 762 768 770 780 786
792 798 804 810 812 816 820 822 828 832 834 836 840 852 858 860 864 868 870 876 880 888
894 896 906 910 912 918 920 924 928 930 936 940 942 945 948 952 960 966 972 978 980 984
   4 10$1+2*I.zum 1+2*i.1e4  NB. first 40 odd Zumkeller numbers
  945  1575  2205  2835  3465  4095  4725  5355  5775  5985
 6435  6615  6825  7245  7425  7875  8085  8415  8505  8925
 9135  9555  9765 10395 11655 12285 12705 12915 13545 14175
14805 15015 15435 16065 16695 17325 17955 18585 19215 19305
   4 10$(#~ 0~:5|])1+2*I.zum 1+2*i.1e6  NB. first 40 odd Zumkeller numbers not divisible by 5
  81081  153153  171171  189189  207207  223839  243243  261261  279279  297297
 351351  459459  513513  567567  621621  671517  729729  742203  783783  793611
 812889  837837  891891  908523  960687  999999 1024947 1054053 1072071 1073709
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377


  

You may also check:How to resolve the algorithm Bitmap/Midpoint circle algorithm step by step in the Python programming language
You may also check:How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Phix programming language
You may also check:How to resolve the algorithm Visualize a tree step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Arithmetic/Rational step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Parallel calculations step by step in the Oforth programming language