JochenAdministrator
(KiX Supporter)
2017-11-05 06:00 PM
Kixgolf - Digital Root Clocks: Private Round

=================================
The Challenge - Digital Root Clocks
=================================

The following (sparing outputs) is completely and shamelessly copied from https://projecteuler.net/problem=315 \:D



Sam and Max are asked to transform two digital clocks into two "digital root" clocks.
A digital root clock is a digital clock that calculates digital roots step by step.
nB.: to get to the digital root of a number, sum the digits of that number and intermediate results until you end up with a number less or equal 9

When a clock is fed a number, it will show it and then it will start the calculation, showing all the intermediate values until it gets to the result.
For example, if the clock is fed the number 137, it will show: "137" -> "11" -> "2" and then it will go black, waiting for the next number.

Every digital number consists of some light segments: three horizontal (top, middle, bottom) and four vertical (top-left, top-right, bottom-left, bottom-right).
Number "1" is made of vertical top-right and bottom-right, number "4" is made by middle horizontal and vertical top-left, top-right and bottom-right. Number "8" lights them all.

The clocks consume energy only when segments are turned on/off.
To turn on a "2" will cost 5 transitions, while a "7" will cost only 4 transitions.

Sam and Max built two different clocks.

Sam's clock is fed e.g. number 137: the clock shows "137", then the panel is turned off, then the next number ("11") is turned on, then the panel is turned off again and finally the last number ("2") is turned on and, after some time, off.
For the example, with number 137, Sam's clock requires:

"137" : (2 + 5 + 4) × 2 = 22 transitions ("137" on/off).
"11" : (2 + 2) × 2 = 8 transitions ("11" on/off).
"2" : (5) × 2 = 10 transitions ("2" on/off).

For a grand total of 40 transitions.

Max's clock works differently. Instead of turning off the whole panel, it is smart enough to turn off only those segments that won't be needed for the next number.
For number 137, Max's clock requires:

"137" : 2 + 5 + 4 = 11 transitions ("137" on)
7 transitions (to turn off the segments that are not needed for number "11").
"11" : 0 transitions (number "11" is already turned on correctly)
3 transitions (to turn off the first "1" and the bottom part of the second "1";
the top part is common with number "2").
"2" : 4 transitions (to turn on the remaining segments in order to get a "2")
5 transitions (to turn off number "2").

For a grand total of 30 transitions.

Of course, Max's clock consumes less power than Sam's one.
As we are very keen on being environmentally friendly and save energy where we can, we are interested in the savings Max's clock has to offer.
Your code shall therefore return the differences between the total number of transitions needed by Sam's clock and that needed by Max's one.
So, for 137 as input the code should return 10 [ 40(Sam) - 30(Max) = 10(saving) ]

*-->A download is available at http://www.kixtart.org/forums/ubbthreads.php?ubb=download&Number=370

================
Inputs and Outputs
================


Input
String of digital root clock value

Example Input
89

Output
Integer or String of calculated savings

Example Output
20

================================================================
Notes
================================================================

- The scoring engine has added code to help diagnose which cases are failing. To see test case results:
 Code:
   kix32 kixgolf_drc $verbose=1 ;shows failing results
   kix32 kixgolf_drc $verbose=2 ;shows all results

- The scoring engine expects your (primary) function to be named a().


=======
Scoring
=======


The solution must pass all tests in order for it's KiXgolf Score to be considered.

When posting KiXtart Golf Scores, please include the KIXGOLF_*.TXT file that is created in the script directory. It contains some basic information about the computer that the script is run on and the resulting scores.

============
Test program
============


Test cases are provided to help screen entries and to provide the Golf Score.
Any script that passes the test cases can be submitted. If you are surprised that your solution passed the test cases, please submit it anyway! That will help me identify bugs in the test program.

================================================================
KiXtart GOLF - How To Play
================================================================


Most importantly, anybody can play, no age restrictions, no penalties, no handicap!

The object in "real" golf is to hit the ball in the hole in the fewest strokes. The object in KiXtart Golf is to get from input (tee) to target (hole) in the fewest keystrokes.

Example: How many positive elements are in array $a?

Array $a could be of structure $a=[1, 2 ,-3, 4, -5, -7, 8, 9]

One approach:
 Code:
for $b=0 to ubound($a)
  if $a[$b]>0
    $c=$c+1
  endif
next

for a score of 45.

Another solution is:
 Code:
DO
  $b=$b+1
  if $a[$b]>0
    $c=$c+1
  endif
UNTIL $b>(UBOUND($a)+1)

for a score of 53.

Better approach: Code sample 1

================================================================
KiXtart GOLF - The Rules
================================================================


1) The goal of KiXtart Golf is to score the lowest strokes.
2) Strokes are all characters in a piece of code except whitespace characters, unless the whitespace character is necessary for the line of code to work. Therefore, carriage returns and line feeds do not count or spaces in between the '=' sign when assigning variables, e.g. '$a = $b' scores 5.
3) Code can be constructed any way you like, as long as it does not generate syntax or other errors when running the script in KiXtart.
4) The final solution MUST pass all test scripts that are part of the KiXtart golf challenge.
7) During the private coding phase, no code is allowed to be posted. Violations result in disqualification of said player.
8) During the public coding phase, code should be posted, reused, and borrowed from other players.
9) The test script contains the official KiXgolf scoring engine
10) Only the person posting a particular score will be recognized for the score, unless the KiXtart Golf Challenge organizer or another delegate posts code on behalf of a player
11) KiXtart Golf (a.k.a KiXgolf) codes must be written inside the KiXgolf UDF collection tags, ';!' and ';!;!'
12) Parameter names of the UDF's can be changed and additional optional parameters can be added.
13) Additional helper UDFs and code can be written as long as they reside inside the ';!' and ';!;!' tags.
14) The use of '$' as a variable is allowed.
15) The UDF layout is up to coder.
16) The UDF is expected to finish in a reasonable time, that is, on modern computers inside 1 hour timeframe.
17) You can submit scores as often as you want.
18) If you reach leading score, you are obligated to post your score immediately so others can try to compete with you.
19) The UDF may only use the KiXtart/KiXforms commands/functions/macros, no other code fragments are allowed.
20) Calls to COM components that are part of a standard default Windows installation are allowed.
21) The use of the KiXforms DLL is also permitted as the KiXforms DLL can now be considered an integral part of KiXtart scripting.
22) Calls to other executables, as long as they are part of a standard default Windows installation are allowed.
23) The UDF should be self-contained (except for any I/O mentioned in the challenge). In particular, you may not do things like fetching extra data from a remote site or file.
24) You may assume ASCII as character set.
25) You may use block comments as the KiXgolf Scoring Engine now supports block comments.
26) You are allowed to only use publicly available versions of KiXtart and KiXforms, private builds or alpha builds are NOT allowed.
27) Your submitted score must include the result print of the KiXgolf test-engine.
28) The SETOPTION() parameters in the KiXgolf script may not be modified and will govern the script behavior. SETOPTION() parameters may change depending on the particular needs of the KiXgolf challenge.
29) Tokenizing the UDF, script, or portions thereof is not allowed.
30) If something is not explicitly denied by the rules, it's allowed.
31) If Confusion arises, arranger of the KiXgolf round has the final say.
32) Additional test cases can be added at any time during the KiXgolf round. The code is expected to pass based on the rules. The test cases may not include tests for all rules and exceptions. Test cases that are added during the public round will not alter the results of the private round.


================================================================
KiXtart GOLF - The Duration of the Competition
================================================================


1) Private coding phase: 2017-11-05 to 2017-11-12 (Official Count down clock will determine end time)

2) Public coding phase: 2017-11-12 to 2017-11-19

3) Final results: 2017-11-19


JochenAdministrator
(KiX Supporter)
2017-11-05 06:13 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Private round ends in

ended


ShaneEP
(MM club member)
2017-11-05 07:56 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Aye...I can see what you meant by needing a lot of strokes on this one.

JochenAdministrator
(KiX Supporter)
2017-11-05 10:19 PM
Re: Kixgolf - Digital Root Clocks: Private Round

should be interesting to see the solutions
I did the initial PE problem using Python not caring about my strokes and stopped golfing with kix in the lower 500 region


AllenAdministrator
(KiX Supporter)
2017-11-06 07:24 AM
Re: Kixgolf - Digital Root Clocks: Private Round

Rusty as hell, but on the course. I got the hard part figured out so now its just a matter of putting it all together. Hopefully tomorrow.

JochenAdministrator
(KiX Supporter)
2017-11-06 09:04 PM
Re: Kixgolf - Digital Root Clocks: Private Round

remember, once you've put it all together, don't forget to leave out the unnecessary parts.
That's what divide the mere mortal golfers from the Tiger Woods kind ;\)


AllenAdministrator
(KiX Supporter)
2017-11-07 02:11 AM
Re: Kixgolf - Digital Root Clocks: Private Round

Going on no sleep makes it tough to think

Anyway... here's my failing score for the participation point. Hope to work on this after a good nights sleep.

 Quote:

KiXtart Version = 4.66
KiXGolf Script = kixgolf_drc.KIX
Scoring Engine = 3.3
OS = Windows 10 Pro
CPU = Intel Pentium III Xeon
Speed = 3392 MHz
Memory = 16384 MB

Tournament = Digital Root Clocks
Processing Start = 2017/11/06 17:07:57.197
Processing End = 2017/11/06 17:07:57.276
Duration = 0000/00/00 00:00:00.078
# Tests Run = 10
# Tests Passed = 0
# Tests Failed = 10
Result = Failed
KiXGolf Score = 273


AllenAdministrator
(KiX Supporter)
2017-11-07 10:08 PM
Re: Kixgolf - Digital Root Clocks: Private Round

OMG this one is tricky. I thought I had all figured out. GRRR!

AllenAdministrator
(KiX Supporter)
2017-11-08 08:58 AM
Re: Kixgolf - Digital Root Clocks: Private Round

Jochen, I've finally got something to call "close to working". If you have it handy could you be so kind to give the individual values of Sam and Max for 991 or 89. In other words... what is $s and $m in the following?

$a=$S - $M

My function and my scribble match, but they don't match the ini result.


JochenAdministrator
(KiX Supporter)
2017-11-08 10:26 AM
Re: Kixgolf - Digital Root Clocks: Private Round

Oi Allen,
nice to see you on the green!

will provide this evening when I'm back home from work (about about 9 1/2 hrs from now)


AllenAdministrator
(KiX Supporter)
2017-11-08 02:22 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Okay... so where might I be going wrong here?

 Code:
  Sam   Max
  7+5  (7+5)*2  
89
  5+1  (2+4)*2
17
  5+4  (7)*2
8
  3+4 
  =34   =50


JochenAdministrator
(KiX Supporter)
2017-11-08 02:52 PM
Re: Kixgolf - Digital Root Clocks: Private Round



you got the number 9 wrong (6 segments)
following error then on Sam's one from 89 to 17 (5+1 must be 5+2)
Sam's step from 17 to 8 then... Hmmm, I can not even guess what that means, but correct would be 2 to turn the one off + 3 to make an eight of the seven.

So we have in total of 32 (last step in Sam's calculation to turn the eight off is in my book a 7 and not a 3+4, but hey, can't tell what you do there)

When we consider the 9 for Max (rest of your calculations are correct) we have 2 more in Max's result ;\)

so I guess you tee off in a minute?

 Code:
  Sam   Max
  7+6  (7+6)*2  
89
  5+2  (2+4)*2
17
  2+3  (7)*2
8
    7
  =32   =52   result: 20


AllenAdministrator
(KiX Supporter)
2017-11-08 02:58 PM
Re: Kixgolf - Digital Root Clocks: Private Round



The 7 got me earlier... I never noticed the 9 having a bottom.

Thanks.


AllenAdministrator
(KiX Supporter)
2017-11-08 03:05 PM
Re: Kixgolf - Digital Root Clocks: Private Round

F!...

 Quote:
Sam's step from 17 to 8 then... Hmmm, I can not even guess what that means, but correct would be 2 to turn the one off + 3 to make an eight of the seven.


I was afraid you were going to say something like this. The original example did not clearly define this....

I may run out of time on this. Heading out of town soon.

I thought I would tell you, I have never spent as much time as I have on this one, just trying to figure the output. Degree of difficulty is higher than it would ever appear from the task given.


JochenAdministrator
(KiX Supporter)
2017-11-08 03:39 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Yeah sorry,

what can I tell. One clue maybe to give you to chew on:

What really counts are Sam's transitions of digits not what he turns on and off because these are the same cost as Max's ;\)


JochenAdministrator
(KiX Supporter)
2017-11-08 04:51 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Oh and maybe, don't let your script do so much calculus... remember you can always substitute/place something you know at the correct position in some lattice.

Now I may have said too much, but as this round seems to be slow anyway, here goes \:\)

btw. Where are the other regulars?


AllenAdministrator
(KiX Supporter)
2017-11-08 05:14 PM
Re: Kixgolf - Digital Root Clocks: Private Round

I already saw the similarities in Sam's and Max's scores but didn't go down that road yet because I just wanted a working function first.

Substitute Positions... that was the first thing I figured out. \:\) It was the damn counting I had so much trouble with.

No idea on others... I sent invites to everyone I had on my list and only heard from Jooel.


AllenAdministrator
(KiX Supporter)
2017-11-08 05:25 PM
Re: Kixgolf - Digital Root Clocks: Private Round

FFS... where's that golfer with the head exploding avatar when you need it? \:\)

 Code:
KiXtart Version  = 4.66
KiXGolf Script   = kixgolf_drc.KIX
Scoring Engine   = 3.3
OS               = Windows 10 Pro
CPU              = Intel Pentium III Xeon
Speed            = 3392 MHz
Memory           = 16384 MB

Tournament       = Digital Root Clocks
Processing Start = 2017/11/08 11:21:14.045
Processing End   = 2017/11/08 11:21:15.045
Duration         = 0000/00/00 00:00:01.000
# Tests Run      = 10
# Tests Passed   = 4
# Tests Failed   = 6
Result           = Failed


AllenAdministrator
(KiX Supporter)
2017-11-08 05:27 PM
Re: Kixgolf - Digital Root Clocks: Private Round

If I have time tonight I'm going to start over. I think I learned enough the first go rounds to fix whatever the hell is wrong without having to read through this monster.

JochenAdministrator
(KiX Supporter)
2017-11-08 05:39 PM
Re: Kixgolf - Digital Root Clocks: Private Round



 Originally Posted By: Allen
all effort... thanks for noticing


http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=209083#Post209083


AllenAdministrator
(KiX Supporter)
2017-11-08 06:14 PM
Re: Kixgolf - Digital Root Clocks: Private Round

I meant my code is a mess

JochenAdministrator
(KiX Supporter)
2017-11-08 07:49 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Oo

Oh, misread that. Good luck wrangle the monster then 😱👹🤔💩


AllenAdministrator
(KiX Supporter)
2017-11-08 08:21 PM
Re: Kixgolf - Digital Root Clocks: Private Round

For anyone else who decides to play, the confusion for me was the alignment of the digital root numbers (89, 17, 8). In the following, the transitions between 17 and 8 are, 1 and off(=2), and 7 and 8(=3). I had incorrectly done it the opposite way, 1 and 8, and 7 and off.

 Code:
  Sam   Max
  7+6  (7+6)*2  
89
  5+2  (2+4)*2
17
  2+3  (7)*2
 8
    7
  =32   =52   result: 20


Hope this helps.


JochenAdministrator
(KiX Supporter)
2017-11-08 10:06 PM
Re: Kixgolf - Digital Root Clocks: Private Round

 Originally Posted By: Allen
FFS... where's that golfer with the head exploding avatar when you need it


Head? This chap wishes it was only his head



AllenAdministrator
(KiX Supporter)
2017-11-08 11:42 PM
Re: Kixgolf - Digital Root Clocks: Private Round

HA!

JochenAdministrator
(KiX Supporter)
2017-11-09 02:32 PM
Re: Kixgolf - Digital Root Clocks: Private Round

To tease you a bit more here are some quotes from this problems exclusive forum on the Project Euler website:

 Quote:
Recreational!

 Quote:
A very welcome diversion from problem No. 314


All right. I promise no more PE based problems to Golf on, from now on.
Next will need a lot more strokes to start with as we have a text based problem there, but the logic itself will be easy peasy ;\)


AllenAdministrator
(KiX Supporter)
2017-11-09 06:17 PM
Re: Kixgolf - Digital Root Clocks: Private Round

I've been working on this in my head. I hope to work on it again before the deadline, which appears to be on Sunday afternoon.

JochenAdministrator
(KiX Supporter)
2017-11-09 08:03 PM
Re: Kixgolf - Digital Root Clocks: Private Round

I really feel a bit bad for you now \:\(

again, just examine Sam‘s transitions (where a change in digits occur) and sum these up...
More help would be unethical 👍


ShaneEP
(MM club member)
2017-11-10 10:47 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Im trying. Got I about half way working. Been really busy at work this week. Hopefully will get some kind of score on the board before timer runs out.

JochenAdministrator
(KiX Supporter)
2017-11-11 08:28 AM
Re: Kixgolf - Digital Root Clocks: Private Round

Woohoo!!

already thought I had to post my own code in public round.
That never happened before, so please you two guys, don‘t make it too embarassing for me


ShaneEP
(MM club member)
2017-11-12 02:18 AM
Re: Kixgolf - Digital Root Clocks: Private Round

This is obviously not golfed down hardly at all...But figured any score was better than no score.

 Code:

KiXtart Version  = 4.67
KiXGolf Script   = kixgolf_drc.kix
Scoring Engine   = 3.3
OS               = Windows 10
CPU              = Intel Pentium III
Speed            = 2417 MHz
Memory           = 8192 MB

Tournament       = Digital Root Clocks
Processing Start = 2017/11/11 19:16:56.880
Processing End   = 2017/11/11 19:16:56.911
Duration         = 0000/00/00 00:00:00.030
# Tests Run      = 10
# Tests Passed   = 10
# Tests Failed   = 0
Result           = Passed
KiXGolf Score    = 685

Thank you for participating in KiXtart Golf!


ShaneEP
(MM club member)
2017-11-12 02:35 AM
Re: Kixgolf - Digital Root Clocks: Private Round

 Code:

KiXtart Version  = 4.67
KiXGolf Script   = kixgolf_drc.kix
Scoring Engine   = 3.3
OS               = Windows 10
CPU              = Intel Pentium III
Speed            = 2417 MHz
Memory           = 8192 MB

Tournament       = Digital Root Clocks
Processing Start = 2017/11/11 19:35:17.517
Processing End   = 2017/11/11 19:35:17.533
Duration         = 0000/00/00 00:00:00.015
# Tests Run      = 10
# Tests Passed   = 10
# Tests Failed   = 0
Result           = Passed
KiXGolf Score    = 561

Thank you for participating in KiXtart Golf!


ShaneEP
(MM club member)
2017-11-12 02:39 AM
Re: Kixgolf - Digital Root Clocks: Private Round

 Code:

KiXtart Version  = 4.67
KiXGolf Script   = kixgolf_drc.kix
Scoring Engine   = 3.3
OS               = Windows 10
CPU              = Intel Pentium III
Speed            = 2417 MHz
Memory           = 8192 MB

Tournament       = Digital Root Clocks
Processing Start = 2017/11/11 19:38:55.340
Processing End   = 2017/11/11 19:38:55.372
Duration         = 0000/00/00 00:00:00.032
# Tests Run      = 10
# Tests Passed   = 10
# Tests Failed   = 0
Result           = Passed
KiXGolf Score    = 541

Thank you for participating in KiXtart Golf!


ShaneEP
(MM club member)
2017-11-12 03:01 AM
Re: Kixgolf - Digital Root Clocks: Private Round

Probably the best I can do before the timer is up! Would probably have to start over to get it lower.
 Code:

KiXtart Version  = 4.67
KiXGolf Script   = kixgolf_drc.kix
Scoring Engine   = 3.3
OS               = Windows 10
CPU              = Intel Pentium III
Speed            = 2417 MHz
Memory           = 8192 MB

Tournament       = Digital Root Clocks
Processing Start = 2017/11/11 20:00:03.663
Processing End   = 2017/11/11 20:00:03.679
Duration         = 0000/00/00 00:00:00.016
# Tests Run      = 10
# Tests Passed   = 10
# Tests Failed   = 0
Result           = Passed
KiXGolf Score    = 540

Thank you for participating in KiXtart Golf!


ShaneEP
(MM club member)
2017-11-12 03:01 AM
Re: Kixgolf - Digital Root Clocks: Private Round

I'm sure there's a much more efficient way to do this. Show us how it's done Allen!

JochenAdministrator
(KiX Supporter)
2017-11-12 06:24 PM
Re: Kixgolf - Digital Root Clocks: Private Round

Private Round has ended.

plesase post your code there