Reduce an integer to its ``Secret Number''.
Enter the mystical world of numerology to find the true soul of an integer! OK, we are not numerologists, but we did find this process in a magazine and thought it could provide some interesting solutions. Actually, the only aspect of numerology that we appreciate is the Perl-Monk-like name of its originator, Edgar Cayce, the Sleeping Prophet of Virginia Beach.
Here is the process:
The first and only argument will be a number. Step through the digits two by two in sequence, adding each pair together. The number 1234 would be handled this way: 1+2, 2+3, 3+4.
If a pair's result is higher than 9, add the digits of the results to obtain a number between 0 and 9 (inclusive).
Concatenate all of the results to obtain a new number. The new number should be shorter by one digit than the previous number.
Repeat steps 1 to 3 until you get a single digit (this is the ``Secret Number'').
Here is an example, let's begin with 8169.
Step 1: 8+1=9, 1+6=7, 6+9=15
Step 2: 15 is higher than 9, so 1+5=6
Step 3: Result = "9"."7"."6" = 976
Step 1: 9+7=16, 7+6=13
Step 2: 16 is higher than 9, so 1+6=7
Step 2: 13 is higher than 9, so 1+3=4
Step 3: Result = "7"."4" = 74
Step 1: 7+4=11
Step 2: 11 is higher than 9, so 1+1=2
Step 3: Result = "2" = 2
Step 4: Done
Thus, the ``Secret Number'' of 8169 is 2.
All programs must work on perl 5.6.1.
Assume total memory is < 2**32 bytes.
The program can be written as one or more lines. The score is the total number of characters you need (smaller is better). If your program is more than one line, you must count the newlines in between as one character each. The #! line is not counted. If you use options on the #! line, the options themselves are counted, including the leading space and ``-''.
If two (or more) identical solutions are submitted, there is a tie. For solutions that have the same score with different characters, the tiebreaking criteria will change each month. We received feedback about last month's tiebreaker (time of receipt) and agreed that it was not appropriate for a global audience.
This month's tiebreaker will favor the script with the greater number of [^\w\s] characters.
The program may only use the perl executable, no other executables on the system are allowed (the program may use itself though). You may use any of the perl 5.6.1 standard core modules. Your solution must be portable in the sense that it should work on all versions of 5.6.1 everywhere (however, it's perfectly fine to abuse perl 5.6.1 bugs). You must not use any of the unicode specific semantics.
Note: Due to contestation in last month's tournament, the following rules are added:
When tested, your script will be named
When tested, you can assume your script to have file permissions of 0644.
The program return code does not matter.
You are to print each number you produced, including the original number. Each line should be likewise properly newline terminated. So, given our example 8169, output should be:
8169 976 74 2
You may assume that there will be only one arg on the command line, which will be a properly formatted number (matching the pattern /^[1-9]\d*\z/ or 0). Numbers will range from 0 to 2**32 - 1 (4294967295) inclusive. There will be no leading 0's.
You must not write to STDERR.
The game starts March 1st (00:00 GMT) and ends March 8th (00:00 GMT).
A test program is provided to help screen entries.
Any program that passes the test program should be submitted. If you are surprised that your solution passed the test program, please submit it anyway! That will help us identify bugs in the test program.
For the test program to work correctly, you will have to name your script
secret.pl and place it in the same directory as your test program. Run the test
$ perl tpr01.pl
to verify that your entry is valid.
Passing the test program does not assure your solution is valid. The referees have the final say.
You can submit your solution here (you'll notice it's the same page as the Leaderboard). Do not publish your solutions anywhere. That will spoil the game, as your solutions are meant to be secret. All solutions will be published at the end of the game.
You can track your ranking through the leaderboard here. Beginners are encouraged to enter and there is a separate leaderboard for them.
We encourage you to send your ideas for holes, tips and tiebreakers to firstname.lastname@example.org.
Dave Hoover <email@example.com>
Jérôme Quelin <firstname.lastname@example.org>