ForumTechnical Corner ► King Put's Code Mini-Golf & Speedway
I figured I'd start this since, worst-case scenario, I have a fun little weekly project to post on the side.

Welcome to King Put's Code Mini-Golf & Speedway

Voted the 252nd Greatest Idaho-Registered Attraction of 1987

Admittedly, the green is a little faded and most of the go-karts don't run, but don't let that (or the vagrant bathing in the water features) turn you off! We're just as great as any other Code Golf competition! Even moreso, since our reputation and ownership of less than ten golf balls means that you can hardly try and still feel good about yourself!

How This Works
Here at King Put's, we don't rent out our golf clubs for a single round. Rather, you get One Entire Week to post a solution to any given problem. Solutions are due at 12:00 UTC on the next Friday. New Problems will be posted whenever our minimum-wage staff stop snorting Smarties in the break room.

And remember how I said we rent our golf clubs? That's a lie! We actually don't own any golf clubs, since those were used to replace the blades of our windmill. We really just sell you a license to use your own. You can use any golf-club (language) you want to, regulation or not. The only requirement is that there is no sharing golf-clubs, so all solutions sharing a language must be unique in program structure. The first working solution in a given language will get the distinction of being "uncopyable".

In order to prove that your golf club is working and not secretly a frozen snake (we don't play Canadian golf here, buckaroo), you must publicly post your solution on the forum. Solution "order" will go by timestamp of the post, so you may only claim code once it is up. Notably, iterations on code that improve or change the execution in noticable ways do not count as "copycats". If you spot an improvement and are the first to post the revised edition, it's yours.

Finally, because we are a family-friendly establishment and not because we accept bribes from players (VenMo: KingPutsCodeGolf), there are no winners or losers. Particularly because different languages have different rules and minimum program sizes, the only goal is to have fun in a recreational (non-competitive) manner. You can compete if you wish, but winners will not be recorded. If you do wish to compete, however, our old, not-mildew-stained score cards judged on three properties: Runtime Complexity, Code Compression, and Readability. Feel free to use that to refine your code as you wish.

That's it! Welcome to King Put's, have fun, and avoid hole nine as it's currently infested with rabid raccoons! Please follow this thread if you wish to be updated as new problems come out!

Hole 1: Skipping Shopper

Joanna enjoys cooking, but is on a tight budget. In order to save both time and money, she has a specific algorithm she employs while at the supermarket. When starting in an aisle, she picks an item and looks at its price. She then skips an amount of items equal to that price, and looks at the next item. She is also very stubborn and will only start looking at the first five items in the aisle. She needs your help figuring out the optimal starting place!

The input will be a single line of up to one-hundred space-delimited integers with values between one and one-hundred.

You will output the ideal starting position (one-indexed!) and the cheapest item Joanna will find on that path.


6 5 4 3 2 1 3 3 3 3 3


6 5 4 3 2 1 3 3 3 3 3
        ^   ^     ^


3 7 5 6 4 8 2 6 4 1 4 1


3 7 5 6 4 8 2 6 4 1 4 1
^     ^           ^ ^

Solutions are due 11:59PM UTC on Friday, Apr. 7 2023

shopper.c [O(n) runtime, 189 bytes]

Language: C
#include <stdio.h>
int main(){int b[100],i=0,s=0,m=101,c=-1;do{c++;}while(scanf("%d ",b+i++)!=EOF);for(int k=0;k<5;){i=k++;while(i<c){if(b[i]<m){m=b[i];s=k;}i+=b[i];}}printf("%d\n%d",s,m);}

This will be used as a benchmark program
Dang, starting it off with something that looks like a DP problem? Might stop by every once in a while to see some of these problems.

EDIT: though looking at it, the constraint that she only looks at the first 5 elements for starting items makes it less DP than expected.
There's no runtime limits technically speaking, so it doesn't really fit DP unless you are trying to optimize.

The whole point of the thread is to allow optimization and compression to be fostered by the same problem.

EDIT: I think complete search is the only viable approach here anyway, since a DP array adds substantial length without asymptotic changes
Language: Brainfuck
, > +++++ +++++ [ < [ -> +++++ +++++ < ] > - ]
> [ > ++++++++++ < - ]
> [ > ++++++++++ < - ]
> [ > ++++++++++ < - ]
> [ > ++++++++++ < - ]
> < [ - < < + > > [ -> + < ] < [ -> + < ] < [ -> + < ] < [ -> + < ] < - ]
[ < [ - > + < ] > - ]
[ - < + > ] > .
[ - < + > ] > .

i can almost guarantee that this code does not work

I just copy and pasted the problem into chat GPT because i cant code
Does not work at all. Actually, that leading comma isn't even an accepted brainfuck directive.
ChatGPT is terrible at brainfuck; I can confirm
I have a terrible language to write in, and I dont want to attempt to code it in.
I'm programming that in the language I made. One moment.
#!/usr/bin/env sh
printf '%s\n' '#include <stdio.h>' 'int main(){int b[100],i=0,s=0,m=101,c=-1;do{c++;}while(scanf("%d ",b+i++)!=EOF);for(int k=0;k<5;){i=k++;while(i<c){if(b[i]<m){m=b[i];s=k;}i+=b[i];}}printf("%d\n%d",s,m);}'|cc -xc -&&(read a;printf "$a"|./a.out)

Not patching that loophole, 'cause it's funny.
Could you tell us people who dont know how to code what it is?
Could you tell us people who dont know how to code what it is?

It's basically taking the example C program that Kyle gave and telling the computer "build and run this script" instead of actually writing a solution in his chosen language.
Had a feeling, with what appeared to be making the environment a shell environment and shell commands.
1. prints the program to stdout
2. pipes stdout into a compiler
3. reads stdin into a variable $a
4. prints the variable into stdout
5. pipes stdout into the compiled program

Funny loophole that effectively allows you to copy any solution into a "separate" language via shell scripting, thus making it valid.
I doubt I'll finish in time, but I am working on a brainfuck implementation of this algorithm
yesssss i hope you finish
There was an attempt at writing a solution in ><>. Unfortunately, it would be both a longer runtime and more characters used, so I gave up lol
The Dummy solution is gonna be so fucking good. I just need to get my stupid fucking baby brain to understand the problem. After that? 6502. I know I can do it.

My Dummy code will be untestable because I have yet to write a compiler for it. In the process of learning LLVM for just that though.
i dont even understand the problem
Unfortunately, it would be both a longer runtime and more characters used, so I gave up lol

Whole point of this thread is that is is non-competetive. The point is writing the solutions and challenging yourself, not competing with others.
And because the course is going through some hard times and can't really afford winner prizes for any competitions.
Kylljoy said:
Whole point of this thread is that is is non-competetive. The point is writing the solutions and challenging yourself, not competing with others.

Hm, then maybe I'll give it another chance. Gonna be difficult though.
Forum > Technical Corner > King Put's Code Mini-Golf & Speedway