← Back to challenges

Mental Logs (Numberphile)

JavaScriptHardarraysnumbersmath

Instructions

Watch the Numberphile video to write a function that utilizes the formula Katie Steckles uses to solve the Mental Logs.

Mental Logs

  • Your function will get an array with a mental log in each element, so 3847 is one stick with the numbers 3, 8, 4, and 7 below each other. (Picture, last log).
  • Katie tells you about the fact that the trick works with fewer than four sticks. Make your function so that it accepts n sticks.

Examples

mentalLogs([7593, 5687, 4628, 9485]) ➞ 29826

mentalLogs([2957, 8357, 3798, 2739]) ➞ 25591

mentalLogs([6428]) ➞ 20

Notes

The formula is very easy; you'll be able to solve the trick just by looking at the array input.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.