# Omnimaga

## Calculator Community => Contests => Community Contests => Topic started by: JWinslow23 on June 29, 2015, 03:47:53 pm

Title: [ENDED] Code Golf - The Reboot #5
Post by: JWinslow23 on June 29, 2015, 03:47:53 pm
Everybody back off, I'm taking back this contest :P

Hello, Omnimaga/CodeWalrus/Cemetech/my girlfriend/whoever is seeing this right now, and welcome to the fifth installment of...
Code Golf: The Reboot

As you can see, I'm neither @pimathbrainiac NOR @c4ooo , NOT EVEN @Juju , but I am the original @JWinslow23, the one who came up with this silly idea in the first place almost a year ago. (https://www.omnimaga.org/community-contests/code-golf-contest-1/) However, don't expect me to host next time, or basically for the next few competitions. How it works is, there's this cycle of hosts that will successively host this competition, starting with pimath. Somewhere in that loop, there's yours-truly, with a challenge on deck to give you. This is that.

Don't know what code golf is? Check out this contest thread (https://www.omnimaga.org/community-contests/code-golf-the-reboot-1/) OR this really old contest thread (https://www.omnimaga.org/community-contests/code-golf-contest-1/) for an explanation. Don't know what code is? Then you will not understand this website in general :P

Challenge 5

Problem

You, a person with a lisp, go to your car, and unlock it with the keys...but there's one problem...you don't have your keys with you.

"Oh no...I lotht my keith! Where'th my car keith?" you exclaim in nervousness. You know that you have more than one pair, but you can't for the life of you find any of them.

Suddenly, you remember...each of your keys had a number on it 10 or above, each of which you call a Keys Number, or "Keith Number". Now, these numbers have a special property:

For a number N with D digits, if you arranged the digits to make a Fibonacci-like sequence where the digits of N are the first few terms, and each number is the sum of the D preceding digits, it would have N somewhere in the sequence.

Examples:

14 is a Keith Number:
Code: [Select]
`N = 14D = 21 + 4 = 54 + 5 = 95 + 9 = 14`197 is a Keith Number:
Code: [Select]
`N = 197D = 31 + 9 + 7 = 179 + 7 + 17 = 337 + 17 + 33 = 5717 + 33 + 57 = 10733 + 57 + 107 = 197`1337 is NOT a Keith Number:
Code: [Select]
`N = 1337D = 41 + 3 + 3 + 7 = 143 + 3 + 7 + 14 = 273 + 7 + 14 + 27 = 517 + 14 + 27 + 51 = 9914 + 27 + 51 + 99 = 19127 + 51 + 99 + 191 = 36851 + 99 + 191 + 368 = 70999 + 191 + 368 + 709 = 1367`Your mission: Help yourthelf find your keith!

Make a program that, given an integer input 10 or above, will tell you whether or not it is a Keith number.

Any output is permitted, but the output must be different for a truthy and falsy result, and the two different outputs must be specified to me so I know the difference. Finally, if the size of the program is exactly 1337 bytes...then that'd be kinda cool... :P

Scoring

All non-calc languages will be scored with this counter (http://juju2143.ca/golf/).
Assembly and compiled Axe programs will be scored on binary size (minus the header), and TI-BASIC will be scored on on-calc source size (again, minus the header).

Submission

PM me over on Omnimaga, Cemetech, or CodeWalrus, or tell my girlfriend and have her dictate the code to me. (If you take the latter option, I will give your code a -90% point bonus. I'm serious.)

Good luck! Remember, don't steal code from others; I want everyone to not fib and not cheat.

TI-BASIC
 Rank User Size Date 1 @lirtosiast 43 Jul 01 2015 02:25:25 pm 2 @PT_ 43 Jul 02 2015 01:24:20 pm 3 @mr womp womp 97 Jun 30 2015 09:13:00 pm

Lua
 Rank User Size Date 1 @Adriweb 152 Jun 30 2015 02:06:20 am

Javascript
 Rank User Size Date 1 @Adriweb 112 Jun 30 2015 02:06:20 am

Java
 Rank User Size Date 1 @c4ooo 190 Jul 01 2015 12:32:49 pm

Ruby
 Rank User Size Date 1 @Juju 150 Jun 30 2015 04:57:53 pm

Python
 Rank User Size Date 1 @Cumred_Snektron 83 Jul 01 2015 10:37:07 am

Language Ranking
 Rank Lang User Size Date 1 TI-BASIC @lirtosiast 43 Jul 01 2015 02:25:25 pm 2 Python @Cumred_Snektron 83 Jul 01 2015 10:37:07 am 3 Javascript @Adriweb 112 Jun 30 2015 02:06:20 am 4 Ruby @Juju 150 Jun 30 2015 04:57:53 pm 5 Lua @Adriweb 152 Jun 30 2015 02:06:20 am 6 Java @c4ooo 190 Jul 01 2015 12:32:49 pm

As I am having trouble with formatting, everyone's code has been put in a Pastebin paste here (http://pastebin.com/iEQkmzcP).
Title: Re: Code Golf - The Reboot #5
Post by: c4ooo on June 29, 2015, 06:30:06 pm
Can the output for "false" be an infinite stream of "false"-s?
And can the output for "true" be an infinite stream of "false"-s? with a "true" somewhere in the middle?
Other than that i'm about done :D
Title: Re: Code Golf - The Reboot #5
Post by: JWinslow23 on June 29, 2015, 07:54:06 pm
Can the output for "false" be an infinite stream of "false"-s?
And can the output for "true" be an infinite stream of "false"-s? with a "true" somewhere in the middle?
Other than that i'm about done :D
No. The stream cannot be infinite. But it must somehow be unique for true and false, and distinguishable.

Oh, and it must be the same for all truthy and falsy results.
Title: Re: Code Golf - The Reboot #5
Post by: c4ooo on June 29, 2015, 08:05:57 pm
Can the output for "false" be an infinite stream of "false"-s?
And can the output for "true" be an infinite stream of "false"-s? with a "true" somewhere in the middle?
Other than that i'm about done :D
No. The stream cannot be infinite. But it must somehow be unique for true and false, and distinguishable.
Actually my conditional exit turned out to be smaller then an infinite one :P

Oh, and it must be the same for all truthy and falsy results.
However this part may trip me up about 20 bytes :(
Edit: I presume the only input provided is the integer to be tested, 'N' and that 'D' is not provided. Am i right?
Title: Re: Code Golf - The Reboot #5
Post by: JWinslow23 on June 29, 2015, 08:43:10 pm
Can the output for "false" be an infinite stream of "false"-s?
And can the output for "true" be an infinite stream of "false"-s? with a "true" somewhere in the middle?
Other than that i'm about done :D
No. The stream cannot be infinite. But it must somehow be unique for true and false, and distinguishable.
Actually my conditional exit turned out to be smaller then an infinite one :P

Oh, and it must be the same for all truthy and falsy results.
However this part may trip me up about 20 bytes :(
Edit: I presume the only input provided is the integer to be tested, 'N' and that 'D' is not provided. Am i right?
Yes. D is simply to illustrate the number of digits in a way that wasn't int(log(N))+1 :P
Title: Re: Code Golf - The Reboot #5
Post by: c4ooo on June 29, 2015, 10:04:29 pm
Entry submitted, 217 bytes in java. 8) ;D
And also JWinslow please count compiled programs (axe included) in source size. @pimathbrainiac and I now both agree that all compiled languages should be counted in source size.
Edit: do you have a Programing Puzzles & Code Golf acount on stack overflow? If not can i cross post the question?
Title: Re: Code Golf - The Reboot #5
Post by: Runer112 on June 30, 2015, 09:21:55 am
Are the following acceptable truthy and falsy results:
• 2 and 0
• no error and error
• 1 and no output

Is there a minimum input value up through which the program must return correct results?
Title: Re: Code Golf - The Reboot #5
Post by: Adriweb on June 30, 2015, 11:05:36 am
Lua, 152
JS, 112.

(counted both with the "function K(n)" header)
Title: Re: Code Golf - The Reboot #5
Post by: JWinslow23 on June 30, 2015, 11:31:12 pm
Entry submitted, 217 bytes in java. 8) ;D
And also JWinslow please count compiled programs (axe included) in source size. @pimathbrainiac and I now both agree that all compiled languages should be counted in source size.
Edit: do you have a Programing Puzzles & Code Golf acount on stack overflow? If not can i cross post the question?
Noted. Will change rules accordingly.
Also, if I do, I don't use it anymore.
Are the following acceptable truthy and falsy results:
• 2 and 0
• no error and error
• 1 and no output
Is there a minimum input value up through which the program must return correct results?
2 and 0 is acceptable, no error and error is not acceptable acceptable only if the output is the same for every truth and the same for every false, 1 and no output is acceptable. Also, the output for truth and false must be the exact same to the letter for every truth and false result.
And the minimum (also for determining them in the first place; 1 digit numbers are trivially Keith numbers) is 10. Which is not a Keith number (1+0, 0+1, 1+1, 1+2, 2+3, 3+5, 5+8...).
Lua, 152
JS, 112.

(counted both with the "function K(n)" header)
Counting the header (deducting the header only applies to TI-83/84/+/SE submissions) and accepting.
Title: Re: Code Golf - The Reboot #5
Post by: JWinslow23 on June 30, 2015, 11:59:24 pm
Updated!
Title: Re: Code Golf - The Reboot #5
Post by: Runer112 on July 01, 2015, 09:06:48 am
And the minimum (also for determining them in the first place; 1 digit numbers are trivially Keith numbers) is 10. Which is not a Keith number (1+0, 0+1, 1+1, 1+2, 2+3, 3+5, 5+8...).

I meant is there a required point at least through which the program must behave correctly? Does an entry have to work for all inputs up to 100? 1000? 1000000?
Title: Re: Code Golf - The Reboot #5
Post by: c4ooo on July 01, 2015, 12:28:45 pm
If anyone want to know why there was some secrecy between me and JWinslow last night it was because i asked him if i could cross post this to Code golf on stackoverflow, and he said yes, except he did  not any 1 to find out. I ended up not doing it because there already is a keith testing challenge on the stackoverflow network :P
Title: Re: Code Golf - The Reboot #5
Post by: JWinslow23 on July 01, 2015, 12:40:03 pm
And the minimum (also for determining them in the first place; 1 digit numbers are trivially Keith numbers) is 10. Which is not a Keith number (1+0, 0+1, 1+1, 1+2, 2+3, 3+5, 5+8...).

I meant is there a required point at least through which the program must behave correctly? Does an entry have to work for all inputs up to 100? 1000? 1000000?
The program should work up to 5752090994058710841670361653731519, or the maximum the language allows (e.g. for TI-BASIC, up to 14 digit numbers are perfectly acceptable).
Title: Re: Code Golf - The Reboot #5
Post by: JWinslow23 on July 03, 2015, 04:11:20 pm
Bump.

Just a reminder, the contest ends officially at midnight EST tomorrow!

I have a (non-official, non-counted-at-all-but-I'll-still-show-it-at-the-end) entry in Golfscript that measures out to 40 bytes. A challenge for the next day...can YOU do better?
Title: Re: [ENDED] Code Golf - The Reboot #5
Post by: JWinslow23 on July 05, 2015, 02:15:31 pm
The contest is over! I hope everybody had fun with this challenge! :D
Title: Re: [ENDED] Code Golf - The Reboot #5
Post by: lirtosiast on July 05, 2015, 02:58:59 pm
PT_: I'm impressed! My own solution using ΔList(cumSum( was 44 bytes because I forgot to take the ΔList(cumSum( out of the augment(. Combining my solution and yours, we have this in 42 bytes, which seems to be optimal:

Input N
int(10fPart(.1N10^(iPart(seq(A,A,~log(N),0
While N≠max(Ans
∆List(cumSum(augment(Ans,{sum(Ans
End
N=max(Ans