|
|
|||||||
============= The Challenge: Quicksum ============= A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data. For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces. A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets "ACM" and "MID CENTRAL": Code: ACM: 1*1 + 2*3 + 3*13 = 46 MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650 A download is available at http://s91376351.onlinehome.us/kixtart/KiXgolf_Quicksum.zip ============= Inputs & Outputs ============= Input: A packet containing 1 to 255 characters Output: An integer denoting the Quicksum of the input packet ======= 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 accompagny the KiXtart golf challenge. Some test scripts may not be included in the publicly available test suite but may be utilized as part of the official KiXgolf score verification. 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 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. ================================================================ KiXtart GOLF - The Duration of the Competition ================================================================ Open ended combined private/public round. There's no private coding round per se but you can definitley hold off posting your code solutions until a couple of other participants have posted KiXgolf scores A download is available at http://s91376351.onlinehome.us/kixtart/KiXgolf_Quicksum.zip |
||||||||
|
|
|||||||
Jens... What's the point of the vartype check here: if $iOutput=$iResult and vartype($iResult)=2 My results are failing because the vartype=3 For example: Quote: Running Test 1... Expecting 46 Recieved 46 Vartype 3 Done Running Test 2... Expecting 650 Recieved 650 Vartype 3 Done Running Test 3... Expecting 4690 Recieved 4690 Vartype 3 Done Running Test 4... Expecting 75 Recieved 75 Vartype 3 Done Running Test 5... Expecting 434 Recieved 434 Vartype 3 Done Running Test 6... Expecting 1960 Recieved 1960 Vartype 3 Done Your solution failed 6 of 6 tests. |
||||||||
|
|
|||||||
If my results are correct... KiXGolf Score = 89 |
||||||||
|
|
|||||||
KiXGolf Score = 85 |
||||||||
|
|
|||||||
Jens, I don't think that we are able to produce Vartype 2 results (integer), You should change the verification to vartype = 3 (long integer) btw. first result : Code: Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution failed 6 of 6 tests. KiXtart KiXtart Version = 4.53 KiXGolf Script = KIXGOL~1.KIX Computer OS = Windows 2000 Professional CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz Speed = 2793 MHz Memory = 504 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 09:14:26.343 Processing End = 2007/07/23 09:14:26.359 Duration = 0000/00/00 00:00:00.015 KiXGolf Score = 128 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
KixGolf Score = 114 |
||||||||
|
|
|||||||
109 |
||||||||
|
|
|||||||
And ..... 97 |
||||||||
|
|
|||||||
93 Still some strokes left to catch Allen |
||||||||
|
|
|||||||
91 |
||||||||
|
|
|||||||
90 Nice simple challenge |
||||||||
|
|
|||||||
87 |
||||||||
|
|
|||||||
87 |
||||||||
|
|
|||||||
85 Now I should have the same as Allan |
||||||||
|
|
|||||||
KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 12:50:07.203 Processing End = 2007/07/23 12:50:07.218 Duration = 0000/00/00 00:00:00.014 KiXGolf Score = 88 |
||||||||
|
|
|||||||
Uh Oh... can we expect a score less than ours? |
||||||||
|
|
|||||||
KiXGolf Score = 87 |
||||||||
|
|
|||||||
KixGolf Score = 145 :P |
||||||||
|
|
|||||||
Great, KiXgolf Shouldn't the rules be modified to the game? Originally Posted By: sealeopard 7) During the private coding phase, no code is allowed to be posted. Violations result in disqualification of said player. Originally Posted By: sealeopard There's no private coding round per se but you can definitley hold off posting your code solutions until a couple of other participants have posted KiXgolf scores
Code: Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_qs.kix Computer OS = Windows XP Professional CPU = Intel Pentium Model 15 Speed = 1995 MHz Memory = 2040 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 12:33:25.817 Processing End = 2007/07/23 12:33:25.817 Duration = 0000/00/00 00:00:00.000 KiXGolf Score = 93 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
lol. already got 3 totally different codes at 87 :P |
||||||||
|
|
|||||||
Oh yeah, not posted official result yet. This result was with modified kixgolf_qs.kix in line 69 to: if $iOutput=$iResult and vartype($iResult)=3 Code: Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = KIXGOL~1.KIX Computer OS = Windows 2000 Professional CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz Speed = 2793 MHz Memory = 504 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 13:02:05.171 Processing End = 2007/07/23 13:02:05.187 Duration = 0000/00/00 00:00:00.015 KiXGolf Score = 85 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
k, now I have 2 saved versions of 85. Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_qs.kix Computer OS = Windows XP Professional CPU = Intel Pentium Model 13 Speed = 1861 MHz Memory = 1014 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 14:08:21.015 Processing End = 2007/07/23 14:08:21.031 Duration = 0000/00/00 00:00:00.016 KiXGolf Score = 85 |
||||||||
|
|
|||||||
In contradiction to the rules, I understand there is no private coding phase and it is allowed to post code, isn't it? |
||||||||
|
|
|||||||
Yeah I think so. This is just a warmup |
||||||||
|
|
|||||||
Can't wait to post... I just do not see shorter ways. |
||||||||
|
|
|||||||
Is it allowed to change Function a($) to i.e. Function a($b) ? |
||||||||
|
|
|||||||
Will make appropriate correction for the VARTYPE() test. Yes, the variable names inside the UDF can be changed, rule #12. |
||||||||
|
|
|||||||
Here is my code good for a KiXGolf Score of 93 Code: Function a($b) Dim $, $c For $ = 0 to Len($b) $c = Asc(SubStr($b,$,1))-64 $a = IIf($c<0,0,$c)*$ + $a EndFunction |
||||||||
|
|
|||||||
mine and probably Allans and Jooels 85: Code: Function a($i) dim $, $_ for $ = 1 to len($i) $_ = asc(substr($i,$))-64 if $_ > 0 $a = $a + $ * $_ ; endif ; next EndFunction |
||||||||
|
|
|||||||
Witto, here is yours for a score of 91 Code: Function a($b) Dim $, $c For $ = 0 to Len($b) $c = Asc(SubStr($b,$))-64 $a = IIf($c<0,0,$c)*$ + $a EndFunction |
||||||||
|
|
|||||||
Could have guessed that Asc() only evaluates the first character in a string. |
||||||||
|
|
|||||||
|
||||||||
|
|
|||||||
Here's mine for a score of 121 Code: Function a($) Dim $x, $y $x = 1 While $x <= Len($) $y = Asc(SubStr($,$x,1)) If $y>64 AND $y<91 $a=$a+($x*($y-64)) EndIf $x=$x+1 Loop EndFunction |
||||||||
|
|
|||||||
At first glance: drop the loop at the end |
||||||||
|
|
|||||||
|
||||||||
|
|
|||||||
Originally Posted By: Witto At first glance: drop the loop at the end Thx for the suggestions but ehm, I don't mean to be ingratefull or anything it was just my 2nd attempt overall, haven't had the time yet to optimize since I am at work. This was just getting it working |
||||||||
|
|
|||||||
The loop at the end, the 3rd parameter of asc(), two parentheses, starting with null placing the increment at the top saves us the endif, results in 121 - 25 = 96 Code: Function a($) Dim $x, $y While $x <= Len($) $x=$x+1 $y = Asc(SubStr($,$x)) If $y>64 $a=$a+$x*($y-64) ; EndIf ; Loop EndFunction |
||||||||
|
|
|||||||
Anyway with Witto's suggestions 110: Edit: Witto's suggestions failed the tests. Here are Some of witto's and some of Jochen's suggestions put together for a score of 117 Code: Function a($) Dim $x, $y $x = 1 While $x <= Len($) $y = Asc(SubStr($,$x)) If $y>64 $a=$a+($x*($y-64)) EndIf $x=$x+1 EndFunction |
||||||||
|
|
|||||||
the For/Next makes the $=$+1 redundant Because of that, you can drop the preceeding EndIf |
||||||||
|
|
|||||||
edited my last post |
||||||||
|
|
|||||||
Arend, -no need to increment $ -the parentheses surrounding the multiplication are superflous as the priority rule of multiplication before addition is valid here too -AND $y<91 can also be ommitted |
||||||||
|
|
|||||||
91: Code: Function a($) Dim $x, $y For $x = 0 to Len($) $y = Asc(SubStr($,$x)) If $y>64 $a=$a+($x*($y-64)) EndFunction |
||||||||
|
|
|||||||
90: Code: Function a($b) Dim $, $y For $ = 0 to Len($b) $y = Asc(SubStr($b,$)) If $y>64 $a=$a+($*($y-64)) EndFunction Presumably final code, basically not mine anymore but Witto's and Jochen's code. |
||||||||
|
|
|||||||
Now you have twice 64 in your code substract it directly here $y = Asc(SubStr($b,$))-64 Now evaluate for > 0 If $y>0 $a=$a+($*$y) |
||||||||
|
|
|||||||
Originally Posted By: Witto Now you have twice 64 in your code substract it directly here $y = Asc(SubStr($b,$))-64 Now evaluate for > 0 If $y>0 $a=$a+($*$y) that makes 87: Code: Function a($b) Dim $, $y For $ = 0 to Len($b) $y = Asc(SubStr($b,$))-64 If $y>0 $a=$a+($*$y) EndFunction |
||||||||
|
|
|||||||
I don't see why you still insist on parenthesing your multiplications |
||||||||
|
|
|||||||
Originally Posted By: apronk Presumably final code, basically not mine anymore but Witto's and Jochen's code. Don't think so. The solutions are very resembling. I think it is a good exercise to see how we think and to get to know the little tricks that can golf the score |
||||||||
|
|
|||||||
Originally Posted By: Jochen I don't see why you still insist on parenthesing your multiplications True, not needed anymore 85: Code: Function a($b) Dim $, $y For $=0 to Len($b) $y=Asc(SubStr($b,$))-64 If $y>0 $a=$a+$*$y EndFunction Witto: You are right, this was my first KixGolf participation |
||||||||
|
|
|||||||
That gives you at least 1 point for participating |
||||||||
|
|
|||||||
My slightly different approach. More shots (86), but I get to see more of the unusual scenery Code: Function a($) Dim $i,$s While $ $i=$i+1 $s=Asc($)-64 $=SubStr($,2) $a=$a+$i*$s*($s>) EndFunction |
||||||||
|
|
|||||||
I've got a respectable 99 for my first ever go at kixgolf. I'm happy. when do we post code? [edit] Oop's just refereshed the list and saw all the code. |
||||||||
|
|
|||||||
Just reviewed some code and got down to 90 Is it really ok to not close If's and other loops? Any way, my code is: Code: Function a($) dim $q, $w for $q = 1 to len($) $w=asc(substr($,$q,1))-64 if $w>0 $a=$a+($w*$q) endfunction |
||||||||
|
|
|||||||
that looks like the code Jochen posted. $a+$w*$q is the same as $a+($w*$q) Maybe you can replace $q or $q by $. |
||||||||
|
|
|||||||
Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_qs.KIX Computer OS = Windows Vista Business Edition CPU = AMD Athlon(tm) 64 X2 Dual Core Processor 5000+ Speed = 2604 MHz Memory = 2048 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 10:17:54.661 Processing End = 2007/07/23 10:17:54.677 Duration = 0000/00/00 00:00:00.016 KiXGolf Score = 83 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
Good score Allen, any clues? |
||||||||
|
|
|||||||
After a clarification, Is Code: function a($b) legal? I didn't think you could edit the base code. So, I'm at 86, or 85 if I cheat. |
||||||||
|
|
|||||||
I'm waiting on a few others to post scores yet... Here's a hint acmp. () |
||||||||
|
|
|||||||
Had a genius moment: Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_qs.kix Computer OS = Windows XP Professional CPU = Intel(R) Pentium(R) 4 CPU 3.00GHz Speed = 2992 MHz Memory = 1022 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 15:52:58.464 Processing End = 2007/07/23 15:52:58.510 Duration = 0000/00/00 00:00:00.046 KiXGolf Score = 83 Thank you for participating in KiXtart Golf! Could be 82 with the cheat! |
||||||||
|
|
|||||||
Very Nice Richard, here is a 85 based on yours Code: Function a($) Dim $i,$s While $ $i=$i+1 $s=Asc($)-64 $=Right($,~) $a=$a+$i*$s*($s>) EndFunction |
||||||||
|
|
|||||||
wait a minute... I didn't give you that good of a hint... hmmmm must be more to find |
||||||||
|
|
|||||||
woot how did you squeeze out 2(3) more strokes ??? |
||||||||
|
|
|||||||
Now I have good code I'm not too keen to post either. I removed my () from the math's bit as they were unnecessary. Then the light bulb went on and I shaved another 3 chars. |
||||||||
|
|
|||||||
hmm... 83 sounds weird. need to do some testing. my split(join()) udf will never get there though... it's totally stuck at 85 |
||||||||
|
|
|||||||
Here we go... Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_qs.kix Computer OS = Windows XP Professional CPU = Intel(R) Pentium(R) 4 CPU 3.00GHz Speed = 2992 MHz Memory = 1022 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 16:16:49.784 Processing End = 2007/07/23 16:16:49.799 Duration = 0000/00/00 00:00:00.014 KiXGolf Score = 81 |
||||||||
|
|
|||||||
Using Function a($b) is no cheat See rule 12 |
||||||||
|
|
|||||||
yep, just checked and updated. I'm getting into this. |
||||||||
|
|
|||||||
also score 85 Code: Function a($b) Dim $, $c For $ = 0 to Len($b) $c = Asc(SubStr($b,$))-64 $a = $a + $c * $ * ($c>) EndFunction |
||||||||
|
|
|||||||
Yep. had this as well included into mine ... |
||||||||
|
|
|||||||
This is a complete different approach, isn't it ? |
||||||||
|
|
|||||||
$a = 1 ? "vartype = " + vartype(cint($a)) ? "vartype = " + vartypename(cint($a)) $a = int($a) ? "vartype = " + vartype($a) ? "vartype = " + vartypename($a) Produces a Long (vartype=3). Is this a Kix4.52 bug? |
||||||||
|
|
|||||||
Sadly, I've got to do some real work With the variable mod my score is 82. Catch you guys later tonight. |
||||||||
|
|
|||||||
ok, i can't let you guys have all the fun (83): Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.51 KiXGolf Script = kixgolf_qs.kix Computer OS = Windows XP Professional CPU = Intel(R) Pentium(R) D CPU 3.20GHz Speed = 3200 MHz Memory = 2048 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 11:58:05.262 Processing End = 2007/07/23 11:58:05.277 Duration = 0000/00/00 00:00:00.014 KiXGolf Score = 83 Thank you for participating in KiXtart Golf! Press any key to continue... |
||||||||
|
|
|||||||
and yes a different, but not completely different approach |
||||||||
|
|
|||||||
Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = KIXGOL~1.KIX Computer OS = Windows XP Professional CPU = Intel Pentium Model 15 Speed = 2400 MHz Memory = 2048 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 20:47:28.656 Processing End = 2007/07/23 20:47:28.656 Duration = 0000/00/00 00:00:00.000 KiXGolf Score = 81 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
you dawg! |
||||||||
|
|
|||||||
hehe ... updated above with a better runtime (did some processor intensive stuff during last run) |
||||||||
|
|
|||||||
don't think it's a bug as it was reported years ago... can't remember the answers or anything but remember playing with it. kix has never (at least not in kix2001 nor in kix2010) had vartype 2. |
||||||||
|
|
|||||||
It seems very strange to have a CINT function that does not create an integer. Quote: CINT Action Returns an expression that has been converted to a Variant of subtype Integer. Syntax CINT (expression) Parameter Expression Any valid expression. Returns Variant of subtype Integer. Remarks CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. |
||||||||
|
|
|||||||
ok here is my 83: Code: ;! Function a($) dim $b if $ $b=asc(right($,1))-64 $a=a(left($,~))+len($)*$b*($b>) EndFunction ;! ;! ; end Quicksum |
||||||||
|
|
|||||||
Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_qs.KIX Computer OS = Windows Vista Business Edition CPU = AMD Athlon(tm) 64 X2 Dual Core Processor 5000+ Speed = 2604 MHz Memory = 2048 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 15:22:21.179 Processing End = 2007/07/23 15:22:21.194 Duration = 0000/00/00 00:00:00.015 KiXGolf Score = 82 and 81 with variable mod. |
||||||||
|
|
|||||||
HEHEE!!! Quote: Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_qs.kix Computer OS = Windows XP Professional CPU = Intel Pentium Model 13 Speed = 1861 MHz Memory = 1014 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/23 22:26:29.765 Processing End = 2007/07/23 22:26:29.781 Duration = 0000/00/00 00:00:00.016 KiXGolf Score = 79 |
||||||||
|
|
|||||||
Benny69, I have no idea why that works What is going on? I guess the left($,~) is some sort of walk through the string... But I just can't see how this works. Any chance of an explination? |
||||||||
|
|
|||||||
I still think we can get below 80... [edit/rant: I knew it! Dang it Jooel!!! [/rant] |
||||||||
|
|
|||||||
... Looking forward to it but I'll have to go soon (back tomorrow). What happens now? how long does this section continue and when do I need to post code for validation? sorry for ht enewbie quesitons, but I'm a newbie at kixgolf |
||||||||
|
|
|||||||
btw, just to show different type of code... Code: Function a($b) dim $ for $=1 to len($b) $a=$a+$*split(asc(substr($b,$))-64,"-")[0] EndFunction I still hope someone can get rid of the dim totally. doesn't look nice anyways, this array way was 85. |
||||||||
|
|
|||||||
acmp, left($,~) chops off the right most chr so ACM becomes AC, then it is sent back into the loop and then i am calling the function to create the count down a(left($,~)) |
||||||||
|
|
|||||||
Thanks Benny69 |
||||||||
|
|
|||||||
$a=$a+$*split(asc(substr($b,$))-64,"-")[0] Jooel... you are one smart basta! Seeing this... I know 79 can be beat too.... just got to figure it out before you do! |
||||||||
|
|
|||||||
~ is not operator or something. figured in some previous kixgolf tournament that one can use it as -1 in some cases. that is, if your parameter has nothing else, NOT-inversion from nothing becomes true, which translates to -1. and that's 1 stroke shorter than saying left($,-1) |
||||||||
|
|
|||||||
Jeez Don't log in for a day and look what happens... If work ever slows down I might get to try... |
||||||||
|
|
|||||||
k, if someone shortens my 79, be my guest. I can't keep on thinking about this, otherwise my sudoku time gets shrinked too much. Code: Function a($) dim $b while $ $b=$b+1 $a=$a+$b*(asc($)-64)*($>#) $=right($,~) EndFunction |
||||||||
|
|
|||||||
Jooel... Here is your 85 down to 83/82 Code: Function a($) dim $b for $b=1 to 0^$ $a=$a+$b*split(asc(substr($,$b))-64,"-")[0] EndFunction |
||||||||
|
|
|||||||
And here is my 82/81 Code: Function a($) dim $b if $ $b=asc(right($,1))-64 $a=a(left($,~))+($b>)*$b*(0^$) ;endif EndFunction |
||||||||
|
|
|||||||
wow Allen, ours is very similar |
||||||||
|
|
|||||||
ugghhh....Must pull away from computer... must work.... (dang golf!) |
||||||||
|
|
|||||||
here is 81: Code: Function a($) dim $b if $ $b=asc(right($,1))-64 $a=a(left($,~))+($b>)*$b*($^) EndFunction |
||||||||
|
|
|||||||
nice... I never thought of that... here is my other entry with your genius: 83/82 Code: Function a($) dim $i,$b for $i=1 to $^ $b=asc(substr($,$i))-64 if $b>0 $a=$a+$i*$b ;endif ;next EndFunction |
||||||||
|
|
|||||||
Wonder why nobody has thought of this yet .... Here's my 81 Code: Function a($i) dim $, $_ for $ = 1 to 255 $_ = asc(substr($i,$))-64 $a = $a + $ * $_ * ($_>) ; next EndFunction |
||||||||
|
|
|||||||
hey, is this a bug: Code: Function a($i) dim $, $_ for $ = 1 to 0 $_ = asc(substr($i,$))-64 $a = $a + $ * $_ * ($_>) ; next EndFunction the for loop should run from 1 to upperlimit of int and then start from negative end and finally stop at 0. but, instead, it does not go to the loop at all!?!? |
||||||||
|
|
|||||||
If I understand you correctly, I don't think I've ever been able to get it to increment negatively without putting a step -1. |
||||||||
|
|
|||||||
I have so much to learn. What fun tomorrow will be. |
||||||||
|
|
|||||||
allen, it's a positive increment. what I mean, if you start 1, either it counts 4 billion loops to reach zero or it does loop infinetly. but starting from 1 can't be right away 0, as my math says 1=0 is false. thus, a bug. |
||||||||
|
|
|||||||
Your understanding of math/programming is well beyond mine... no doubt about it. I guess I could see what you mean about infinity, but I guess I would never see how it is a positive increment. 0 is less than 1 (I think anyway ) |
||||||||
|
|
|||||||
well, positive increment it is if I don't specify negative step, right? so, it doesn't matter what is the final number, it will count positively. now, you wonder why I expect it to come back to zero at some point? that's because once it reaches 2 147 483 647, it can't add no more numbers, it's the limit. thus, adding one more to that will result in -2 147 483 647 and -2 147 483 646 after that, until it would reach zero. anyway, like said, it doesn't matter what is the X in "to X", kix should always keep on incrementing until it hits that value. and as 0 is smaller than the starting number of 1, it should just keep on looping. approx. 4 294 967 294 times to be exact. |
||||||||
|
|
|||||||
Interesting Jooel. Back to Golf...I'm surprised there have not been any new scores posted. |
||||||||
|
|
|||||||
Looks like you guys have been enjoying the warm-up |
||||||||
|
|
|||||||
Interesting Code Dale, there is no loop!??! Will have to have a look on it... or maybe a stare edit: I don't get it ... there is no loop but if I comment if $ I get a stack overflow error edit some more: Oh, recursively calling itself, didn't see that |
||||||||
|
|
|||||||
Here's my 81 Code: Function a($b) Dim $, $w For $ = 1 to 255 $w=Asc(SubStr($b,$))-64 if $w>0 $a=$a+$w*$ EndFunction I've really got to get my head around these recursive function calls to see if it can be improved. You chaps have some mean tricks up your sleeves. |
||||||||
|
|
|||||||
Benny's code reduced to 78 Hey Jooel - no DIM Code: Function a($) if $ $a=asc(right($,1))-64 $a=a(left($,~))+len($)*$a*($a>) EndFunction |
||||||||
|
|
|||||||
Jens, am I allowed to introduce a second required parameter to the udf and change the test script to pass an additional value ? If yes, there would be a shiny 71 score edit: I think not as the rules clearly state that optional parameters are allowed, Jens? |
||||||||
|
|
|||||||
Neat trick there Richard. |
||||||||
|
|
|||||||
Jochen, Rule 12: 12) Parameter names of the UDF's can be changed and additional optional parameters can be added. Go for it. |
||||||||
|
|
|||||||
Well optional is the culprit here. optional scores 8 so the improvement would be negative (84). If required would be possible.... |
||||||||
|
|
|||||||
Anyway, just for the records: Code: Function a($,optional $b) $b = $b + 1 if $ $a=a(right($,~),$b)+$b*(asc($)-64)*($>!) EndFunction scores 84 |
||||||||
|
|
|||||||
Jochen, What is the $>! doing? And, is there anywhere where these tricks are documented? |
||||||||
|
|
|||||||
Ok, reworked my own code for a nice 78 score Code: function a($) dim $i for $i = 1 to 255 $a = $a + $i * (asc($)-64) * ($>!) $ = right($,~) endfunction Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = KIXGOL~1.KIX Computer OS = Windows 2000 Professional CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz Speed = 2793 MHz Memory = 504 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/24 10:39:21.640 Processing End = 2007/07/24 10:39:21.656 Duration = 0000/00/00 00:00:00.016 KiXGolf Score = 78 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
Yo, the ($>!) is just validating if the character $ starts with has a higher 'value' than ! (Not every string needs quotes). So if $ starts with a space character the expression results in 0 (! = ascii 33, space = 32), and if it starts with a Letter it results in 1 This feature can be utilized for eg. sorting functions... |
||||||||
|
|
|||||||
This feels a bit like cheating, but hey, it's a 77 Code: function a($) dim $i for $i = 1 to 99 $a = $a + $i * (asc($)-64) * ($>!) $ = right($,~) endfunction Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = KIXGOL~1.KIX Computer OS = Windows 2000 Professional CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz Speed = 2793 MHz Memory = 504 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/24 10:52:16.140 Processing End = 2007/07/24 10:52:16.156 Duration = 0000/00/00 00:00:00.016 KiXGolf Score = 77 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
Thanks for explaining, I substituted the ! for 0 and found it still worked so I was assuming it was something like that. Code: for $i = 1 to 255 glad I could help |
||||||||
|
|
|||||||
'coz it is cheating! |
||||||||
|
|
|||||||
Originally Posted By: acmp Code: for $i = 1 to 255 glad I could help Hmmm, I posted that yesterday evening |
||||||||
|
|
|||||||
my bad, I'll get more coffee, should help me stay on track. I didn't notice your earlier post, I followed from your 9:16 to 9:39 (both today) please accept my apologies. |
||||||||
|
|
|||||||
you're welcome |
||||||||
|
|
|||||||
Another 77 based on Dales' code with mods from Richard Code: function a($) if $ $a=asc(right($,1))-64 $a=a(left($,~))+($a>)*$a*(0^$) endfunction Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.53 KiXGolf Script = KIXGOL~1.KIX Computer OS = Windows 2000 Professional CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz Speed = 2793 MHz Memory = 504 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/07/24 13:11:07.406 Processing End = 2007/07/24 13:11:07.421 Duration = 0000/00/00 00:00:00.014 KiXGolf Score = 77 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
btw, 0^$ is a pretty clever way to say len($), Dale. Have to keep this in mind. |
||||||||
|
|
|||||||
Thanks Richard, You Da Man! thanks, but that was Allen's, mine was ($^): 76 Code: ;! Function a($) if $ $a=asc(right($,1))-64 $a=a(left($,~))+($^)*$a*($a>) EndFunction ;! ;! ; end Quicksum |
||||||||
|
|
|||||||
Ay Caramba !!! |
||||||||
|
|
|||||||
Jochen, if you wanted to cover all lengths, yours could be: 79 Code: ;! Function a($) dim $i for $i=1 to ($^) $a=$a+$i*(asc($)-64)*($>!) $=right($,~) EndFunction ;! |
||||||||
|
|
|||||||
Man... go to sleep and miss all the fun. |
||||||||
|
|
|||||||
Well, I have already covered all lengths with for $i = 1 to 255 (78), or could cover them with for $i = 1 to 0^$ (78 too), but i prefer to insist on my 'cheat' with for $i = 1 to 99 which scores 77 |
||||||||
|
|
|||||||
Or 78 Code: Function a($) dim $i for $i=1 to 0^$ $a=$a+$i*(asc($)-64)*($>!) $=right($,~) EndFunction |
||||||||
|
|
|||||||
Hello? |
||||||||
|
|
|||||||
You posted while I was working... man, tough crowd. |
||||||||
|
|
|||||||
|
||||||||
|
|
|||||||
Just lurking around but so far I'm impressed. |
||||||||
|
|
|||||||
Mart, Witto, Gargoyle, apronk, Shawn, Doc, Drill come on guys want to see what you got, you guys going to play? I think you could bring some fresh ideas. |
||||||||
|
|
|||||||
they are not gonna play. they don't have a change, so they will just keep on lurkin |
||||||||
|
|
|||||||
If there was time to play I'd give it a go but I'm just to damn busy setting up an inventory script at work so I'll be online but can't play and do the inventory stuff at the same time. Lurking a bit is possible because I can hide that as looking for ways to implement some part of the inventory script. My CEO would like to see the inventory stuff done and does not care about KixGolf at all Depending on the challenge maybe the next one will be my first KixGolf game. |
||||||||
|
|
|||||||
Oh yeah, I'm also doing some painting around the house. Sanding, filling holes and gapes, wait for filler to dry, sanding again, put on some primer, wait for primer to dry, sand once more, paint first layer of right colour paint, wait for paint to dry, do some more sanding and paint the final layer of the right colour paint. I'm not looking for an excuse not to play but it all takes huge amounts of time you know |
||||||||
|
|
|||||||
Your code is beautifull, Benny. I am still looking what it exactly does. Could you elaborate on this line? I.E. what does the XOR do? $a=a(Left($,~))+($^)*$a*($a>) |
||||||||
|
|
|||||||
Originally Posted By: Benny69 Mart, Witto, Gargoyle, apronk, Shawn, Doc, Drill come on guys want to see what you got, you guys going to play? I think you could bring some fresh ideas. Hi Benny - no don't have time to play. I'm already doing 13+ hour days at work and trying to balance work and home and KiX |
||||||||
|
|
|||||||
$a=a(Left($,~))+($^)*$a*($a>) its using recursion to call itself, basically function a() is calling function a() until it runs out of letters. the ~ is a shortcut for -1 0^$ or $^ is a shortcut for len($) ;I have no idea how/why this works, but someone figured it out in one of the last golfs ($a>) = ($a>0) |
||||||||
|
|
|||||||
Thanks Allen very well put, and i think it was Jooel or Shawn that showed me that one, one of them might elaborate more clearly. |
||||||||
|
|
|||||||
Jochen: Your "99" won't cut it as the specs call for support of up to 255 characters in the Inputs & Outputs section Code: [b]============= Inputs & Outputs =============[/b] Input: A packet containing 1 to 255 characters |
||||||||
|
|
|||||||
Also, ($a>) = (0|$a) = ($a|) Not sure if it's interesting but I noticed that OR behaves the same as XOR for the len() thing. No chars saved, but never mind. |
||||||||
|
|
|||||||
Oh I see, so my scores are 78 for my own and 77 for adapting Dales/Allens (?) |
||||||||
|
|
|||||||
I would love to play - but I am in the middle of implementing our new web filtering and doing our Virtual Office project (almost 200 workers at home full time now). Oh then there is the family - etc etc... But I will keep lurking. |
||||||||
|
|
|||||||
Originally Posted By: acmp Also, ($a>) = (0|$a) = ($a|) Not quite: Code: break on $=-1 ($|) ? ($>) get $ returns -1 0 |
||||||||
|
|
|||||||
Oops, Just noticed the code I pinched was not the XOR at all it was ($>). XOR would be ($^) so, using a text string Code: break on $="-1" ($|) ? ($^) get $ returns 2 2 But if $ is an integer both OR and XOR return the value of the integer. Good job we're using strings. |
||||||||
|
|
|||||||
I'm running out of ideas how this can be solved differently... well, at least promising ideas to shorten the code |
||||||||
|
|
|||||||
acmp, Shouldn't that be $=-1 you wrote $="-1" You made it a string Code: Break on $=-1 ($|) ? ($^) Get $ returns Code: -1 -1 |
||||||||
|
|
|||||||
Exactly. IF a string is provided both OR and XOR return the lenght of the string, if an integer is used the value of the integer is returned. |
||||||||
|
|
|||||||
OK, I see |
||||||||
|
|
|||||||
wicked... think the next golf round will be out of my reach. at least it will be hard, if all of you guys participate. |
||||||||
|
|
|||||||
I give up. The last thing I worked with was this 79 code (nothing really new) Can't improve anymore... Code: function a($) if $ $a = a(left($,~)) + ($^) * (asc(right($,1))-64) * (trim($)=$) endfunction |
||||||||
|
|
|||||||
Code: * (trim($)=$) nice test. |
||||||||
|
|
|||||||
Originally Posted By: acmp Code: * (trim($)=$) nice test. Have to be careful though - the algorithm will fail if there is a trailing space in the string |
||||||||
|
|
|||||||
hmm... why trim()? |
||||||||
|
|
|||||||
forget it, stupid q. anyhow, this would work: Code: $a = a(left($,~)) + ($^) * (asc(right($,1))-64) * (rtrim($)=$) |
||||||||
|
|
|||||||
and this would also yield 79: Code: function a($) if $ $a=right($,1) $a = a(left($,~)) + ($^) * (asc($a)-64) * ($a>!) endfunction |
||||||||
|
|
|||||||
No Jooel, the Rules state clearly: Quote: A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. So the trim is perfectly fitting as we are only interested in trailing spaces and know that there can be no leading one |
||||||||
|
|
|||||||
right. sorry. but wasn't me who said yours didn't work... |
||||||||
|
|
|||||||
I know it looks like everybody already has this solved, but I wanted to check it out just to see how I'd do. Is there somewhere else I can get the download? The original URL is giving me a 404. Thanks! |
||||||||
|
|
|||||||
Try again. Seems that the last upload didn't take. I re-uploaded the ZIP file. |
||||||||
|
|
|||||||
Originally Posted By: Jochen No Jooel, the Rules state clearly: Quote: A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. So the trim is perfectly fitting as we are only interested in trailing spaces and know that there can be no leading one Oops! That was me, not Jooel. |
||||||||
|
|
|||||||
Ja, I'm not resentful there, though Jooel posted a code (rtrim) that implicitly follwed your opinion by saying "this would work". |
||||||||
|
|
|||||||
right... but, you can't say my rtrim version doesn't work... |
||||||||
|
|
|||||||
I don't |
||||||||
|
|
|||||||
Nor me. BTW Jochen, where can I get one of those big blue "mother and child" ear-rings that you are modelling in your avatar? I'm bored with the small one that I have in at the moment. |
||||||||
|
|
|||||||
Well, not knowing all the the little tricks (EndIf and Next not needed, ASC() only evaluating the first character of a string) I get a 96 on my own merits. Where can I find a list of some of these "quirks" you guys have found? Code: Function a($t) Dim $p, $ For $p = 1 to len($t) $ = asc(SubStr($t,$p,1))-64 If $ > 0 $a = $a + $p * $ EndIf Next EndFunction Running Test 1...Done Running Test 2...Done Running Test 3...Done Running Test 4...Done Running Test 5...Done Running Test 6...Done Your solution passed all tests KiXtart KiXtart Version = 4.50 KiXGolf Script = kixgolf_qs.kix Computer OS = Windows XP Professional CPU = Intel(R) Pentium(R) 4 CPU 3.00GHz Speed = 2992 MHz Memory = 2040 MB KiXGolf Scoring Engine Scoring Engine = 3.3 KiXtart Golf Score Tournament = Quicksum Processing Start = 2007/08/01 11:43:47.213 Processing End = 2007/08/01 11:43:47.213 Duration = 0000/00/00 00:00:00.000 KiXGolf Score = 96 Thank you for participating in KiXtart Golf! |
||||||||
|
|
|||||||
well done, there is no documented list of 'quirks' (not really quirks, just coding experience). |
||||||||
|
|
|||||||
Shouldn't we call those codign tricks a "handicap", just to keep the Golf theme going ? |