Rhonda Numbers
Challenge: Rhonda Numbers
A Rhonda number is a positive integer n that satisfies the property that, for a given base b, the product of the base-b digits of n is equal to b times the sum of n's prime factors. Only composite bases (non-prime bases) have Rhonda numbers.
For instance, consider 10206₁₀ = 2133132₄, that is, 2×4⁶ + 1×4⁵ + 3×4⁴ + 3×4³ + 1×4² + 3×4¹ + 2×4⁰ = 2×4096₁₀ + 1×1024₁₀ + 3×256₁₀ + 3×64₁₀ + 1×16₁₀ + 3×4₁₀ + 2 = 8192₁₀ + 1024₁₀ + 768₁₀ + 192₁₀ + 16₁₀ + 12₁₀ + 2 = 10206₁₀. 10206₁₀ has the prime factorization (2, 3, 3, 3, 3, 3, 3, 7) because 2×3⁶×7 = 10206₁₀. This is a base-4 Rhonda number because 2×1×3×3×1×3×2 = 108₁₀ and 4×(2+3+3+3+3+3+3+7) = 4×27₁₀ = 108₁₀.
The Wolfram MathWorld entry for “Rhonda Number” provides tables of many Rhonda numbers. Further information on Rhonda numbers may be found at Numbers Aplenty. You may also find this base conversion tool helpful.
Produce three files to carry out this task:
/lib/rhonda/hoonYour library
/lib/rhonda/hoonshould expose two arms:+checkaccepts a@udunsigned decimal value for the base and a@udunsigned decimal value for the number, and returns%.yor%.ndepending on whether the given number is a Rhonda number in that base or not.+seriesaccepts a base as a@udunsigned decimal value and a number of values to returnn, and either returns~if the base is prime or thenfirst Rhonda numbers in that base.
/gen/rhonda-check/hoonYou should provide a
%saygenerator at/gen/rhonda-check/hoonwhich accepts a@udunsigned decimal value and applies+checkto verify if that value is a Rhonda number or not./gen/rhonda-series/hoonYou should provide a
%saygenerator at/gen/rhonda-series/hoonwhich accepts a@udunsigned decimal valueband a@udunsigned decimal valuen, wherebis the base b, and returns the first n Rhonda numbers in that base.
Unit Tests
Following a principle of test-driven development, we compose a series of tests which allow us to rigorously check for expected behavior.
Solutions
These solutions were submitted by the Urbit community as part of a competition in ~2022.6. They are made available under both the MIT license and the CC0 license. We ask you to acknowledge authorship should you utilize these elsewhere.
Solution #1
This solution was produced by ~mocmex-pollen. This code includes the ~_ sigcab error message rune and demonstrates the use of a helper core in a library and shows ^ ket skipping of $ buc.
/lib/rhonda.hoon
/gen/rhonda-check.hoon
/gen/rhonda-series.hoon
Solution #2
This solution was produced by ~ticlys-monlun. This code demonstrates using a +map data structure and a different square-root solution algorithm.
/lib/rhonda.hoon
/gen/rhonda-check.hoon
/gen/rhonda-series.hoon
Solution #3
This solution was produced by ~tamlut-modnys. This code demonstrates a clean prime factorization algorithm and the use of +roll.
/lib/rhonda.hoon
/gen/rhonda-check.hoon
/gen/rhonda-series.hoon
Solution #4
This solution was produced by ~sidnym-ladrut. This code demonstrates using multiple cores in a library.
/lib/rhonda.hoon
/gen/rhonda-check.hoon
/gen/rhonda-series.hoon
Last updated