Omnimaga

Calculator Community => Contests => Community Contests => Topic started by: pimathbrainiac on June 08, 2015, 04:56:49 pm

Title: [ENDED] (Results Soon) Code Golf - The Reboot #2
Post by: pimathbrainiac on June 08, 2015, 04:56:49 pm
Challenge #2: Motion Commotion
The challenge: Make a program that moves a pixel around the screen.

Inputs:
You may either use the arrow keys or wasd for input.

Outputs:
Each time a key is pressed, a pixel moves around the screen as follows:
up/w: up 1 pixel
down/s: down 1 pixel
left/a: left 1 pixel
right/d: right 1 pixel
If a key is held, it doesn't matter. 1 pixel of movement per press.

Scoring:
All non-calculator programs will be scored through this counter: http://juju2143.ca/golf/ (http://juju2143.ca/golf/)
Assembly programs will be scored on binary size (excluding the header), and Basic/Axe programs will be scored bn on-calc source size (once again, excluding the header).
Good luck, and may this contest move you!

Rankings
1) lirtosiast - 27 Bytes (TI-Basic)
2) ben_g - 47 Bytes (TI-Basic)
3) Siapran - 139 Bytes (PICO-8)
4) Juju - 144 Bytes (PICO-8)
5) LDStudios - 153 Bytes (PICO-8)
6) Scipi - 154 Bytes (GBA C)
7) alberhrocks - 253 Bytes (Pygame)
8 ) alberthrocks - 397 Bytes (SDL C)

Language Ranking
1) TI-Basic (27 Bytes)
2) PICO-8 (139 Bytes)
3) GBA C (154 Bytes)
4) Pygame (253 Bytes)
5) SDL C (397 Bytes)
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 08, 2015, 05:27:11 pm
Sounds fun. What do you mean by pixel, at least on PC? An actual pixel? Or it can be a *?
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 08, 2015, 05:28:30 pm
Sounds fun. What do you mean by pixel, at least on PC? An actual pixel? Or it can be a *?

An actual pixel, preferably black.
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 08, 2015, 05:32:17 pm
Sounds fun. What do you mean by pixel, at least on PC? An actual pixel? Or it can be a *?

An actual pixel, preferably black.
In a window or on the whole screen? Anyway, sounds like it requires a few graphic libraries.
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 08, 2015, 05:33:04 pm
Sounds fun. What do you mean by pixel, at least on PC? An actual pixel? Or it can be a *?

An actual pixel, preferably black.
In a window or on the whole screen? Anyway, sounds like it requires a few graphic libraries.

Either works, and yeah, that's the point. This one gives advantages to calcs.
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 08, 2015, 05:48:01 pm
Yeah, I see, or any language with integrated graphics :P

Also some more questions: I have to erase the pixel before moving it, right? Also can I allow it to go out of bounds?

EDIT: pimath says yes and no no and yes, respectively. Sorry for all the questions, I think I'm done :P
Title: Re: Code Golf - The Reboot #2
Post by: Scipi on June 08, 2015, 07:03:16 pm
I've taken a stab at it in C again and my first attempt is 155 bytes. I've targeted the GBA to make things much shorter.
Title: Re: Code Golf - The Reboot #2
Post by: ordelore on June 09, 2015, 11:09:01 am
Is there any specific size the window should be if we are making a computer program?
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 09, 2015, 11:24:46 am
Is there any specific size the window should be if we are making a computer program?

No. That is not a restriction.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 09, 2015, 03:09:14 pm
Do we need to initialize the cursor at any specific location, do we need to clear the screen first, and can we assume that the only pressed keys will be up, down, left, and right?
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 09, 2015, 03:45:30 pm
no, no, and yes.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 09, 2015, 04:04:00 pm
Okay, I have 34 bytes in TI-BASIC, and that includes clearing the screen and starting the cursor at (0,0).

30 bytes if we don't need to initialize the cursor and it only works for a few seconds :P
Title: Re: Code Golf - The Reboot #2
Post by: Ivoah on June 09, 2015, 04:24:02 pm
11 bytes in TI-BASIC :p
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 09, 2015, 05:22:32 pm
I fixed my solution; now it doesn't repeat keys.
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 09, 2015, 05:23:39 pm
Ivoah: Wow! (assuming your solution is correct)

My answer is actually wrong because the keys repeat, and it will cost about 5 bytes to fix.

Well he was wrong. Don't worry :P Same thing with the key repeat and also a perceived loophole that wasn't actually there
Title: Re: Code Golf - The Reboot #2
Post by: LDStudios on June 09, 2015, 05:46:22 pm
153 bytes in PICO-8 (sorry Juju ^.^)
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 10, 2015, 07:11:58 pm
Dammit. How.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 10, 2015, 09:55:42 pm
Do we need to initialize the cursor at all (is it fine if the position of the cursor is the same as it was last session, and the program throws an error if a certain variable has an invalid value?)

Edit: I was told that we don't.

Is it acceptable if moving to the 5984 other pixels on the graph screen works, but not the single pixel (0,0)?

Edit: Never mind, I wasn't able to save that byte.
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 11, 2015, 12:43:46 am
153 bytes in PICO-8 (sorry Juju ^.^)
Wait, did you do the "If a key is held, it doesn't matter. 1 pixel of movement per press." rule? Otherwise, I'm down to 162 bytes now :P
Title: Re: Code Golf - The Reboot #2
Post by: LDStudios on June 11, 2015, 06:31:04 am
153 bytes in PICO-8 (sorry Juju ^.^)
Wait, did you do the "If a key is held, it doesn't matter. 1 pixel of movement per press." rule? Otherwise, I'm down to 162 bytes now :P
I just used btnp, that was the closest thing to doing that I could figure, I applaud you if you had found a better way of doing that ^.^
EDIT: Nevermind, thought of a good way to do that, I guess my old entry is invalid then, but I think I can implement this without throwing on too many extra characters :P
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 11, 2015, 12:05:25 pm
Yeah, BTNP still returns true every 4 frames, which is not what we want.

EDIT: 153 bytes! Which is the same score you got, but with the 1 pixel of movement per press thing xD

EDIT: 149! I forgot to remove one useless declaration. That's pretty crazy.
Title: Re: Code Golf - The Reboot #2
Post by: LDStudios on June 11, 2015, 04:14:36 pm
Yeah, BTNP still returns true every 4 frames, which is not what we want.

EDIT: 153 bytes! Which is the same score you got, but with the 1 pixel of movement per press thing xD

EDIT: 149! I forgot to remove one useless declaration. That's pretty crazy.
dam.. now that i fixed key presses, I'm at 202
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 11, 2015, 04:38:18 pm
I'm down to 144, almost on par with the PICO-8 guy (https://twitter.com/lexaloffle/status/609060659494461440). :P
Title: Re: Code Golf - The Reboot #2
Post by: Scipi on June 11, 2015, 05:46:29 pm
I'm down to 137 bytes :3
Title: Re: Code Golf - The Reboot #2
Post by: TIfanx1999 on June 11, 2015, 07:12:29 pm
I'm curious though, I think you'd have to initialize the pixel somewhere on the screen(IE set an intial value fo the coordinates). Otherwise, it's possible your program will error from the start if the pixel is trying to display out of bounds. Also, just submitted an entry in TI-BASIC. How is size counted for TI-BASIC? Does the program name add to the size(My program name is a single character)?
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 11, 2015, 07:22:30 pm
I'm told (this is the way JWinslow23 did it, anyway) that the program size is equal to the sum of the size of each token in your code, or equivalently the size shown on [2nd][MEM], minus the size of the program name, minus nine bytes. So the name doesn't matter.

I asked pimath about initializing the cursor, and they said it was unnecessary.
Title: Re: Code Golf - The Reboot #2
Post by: TIfanx1999 on June 11, 2015, 07:24:44 pm
So how large is a single char program name, and why minus nine additional bytes?
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 11, 2015, 07:26:06 pm
The TI operating system has some sort of nine-byte header that it uses to store information about the program; that shouldn't count.

The size of a program name is the number of characters in it; one character=one byte.
Title: Re: Code Golf - The Reboot #2
Post by: TIfanx1999 on June 11, 2015, 07:29:11 pm
Ah, ok. Thanks. If I drop initializing the first pixel that puts me at 60 bytes.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 11, 2015, 07:33:24 pm
Art_of_camelot, did you remember to avoid key repeat? That was tricky for me.
Title: Re: Code Golf - The Reboot #2
Post by: TIfanx1999 on June 11, 2015, 07:36:09 pm
Oh, I misinterpreted what that line meant. I thought it meant that key repeat was ok.
*edit*Hmm... I'm not sure how to make this work without key repeat. Other than doing something really bloated or silly. I'll have to give it some thought.
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 11, 2015, 08:48:42 pm
Well me and ben_g must have the same program because that is exactly what I got in ti basic.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 11, 2015, 08:51:38 pm
I could write literally 1030 distinct 57-byte solutions, so I'm not sure that ben_g's is the same as yours.

That's without the header, right?
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 11, 2015, 09:31:15 pm
Actually I got mine down to 43 without the header and name. I used a bit of an annoying way to remove key repeat though. It still follows all of the rules.

Also 1030  *.*
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 11, 2015, 10:01:07 pm
Just be very sure you actually avoided any key repeat, because pimath is (justifiably) strict at ensuring it works.

Actually, about 1070. Of course I can't really write them all out, but I could theoretically.
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 11, 2015, 10:09:59 pm
Yes I am sure key repeat doesn't work. 10^70 just because of placement?
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 11, 2015, 10:20:54 pm
No, not just placement—there are only a few dozen ways at most to rearrange statements in a given algorithm.
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 11, 2015, 10:23:14 pm
OK. I wasn't sure if placement was enough. Also since the op hasn't been updated in a while what's the winning number so far?
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 11, 2015, 10:27:22 pm
Yeah, sorry about that. It will be updated tomorrow. I just have to sift through a ton of entries and my parents are keeping me busy.
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 11, 2015, 10:29:11 pm
Can't wait! I'll submit mine if there's any chance of it winning. Maybe I'll find some way to cut it down some more.
Title: Re: Code Golf - The Reboot #2
Post by: TIfanx1999 on June 12, 2015, 12:25:06 am
Well, I have a working solution now, but holy bloat city. It's sitting at 100 bytes. :'( I'm sure there's a simpler solution that I'm just not seeing. At least it works now though. :D
Title: Re: Code Golf - The Reboot #2
Post by: Siapran on June 12, 2015, 04:34:27 am
139 bytes in pico8

actually I could try lua bytecode
Title: Re: Code Golf - The Reboot #2
Post by: Jim Bauwens on June 12, 2015, 01:25:46 pm
127 bytes in TI-Nspire Lua.
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 12, 2015, 01:59:09 pm
41 bytes in ti basic. If only I could lower the size of my getKey stuffs.
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 12, 2015, 02:01:43 pm
Updated the rankings for all the people who sent me PMs with the source.
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 12, 2015, 02:06:23 pm
@lirtosiast that is rediculous. My entire getKey is larger than that. I guess I could cheat with a 1 pxl window and have it throw err. Domain on a keypress but that's not exactly fair.

Also thanks pimath for updating it. I guess I'll submit because I'm in second place.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 12, 2015, 02:13:21 pm
I would have had 26, but on one out of every literally hundreds of billions of keypresses that solution sometimes moves the pixel over by one.

A small hint: In my official solution, there is only one "getKey", and I don't store it to any variable, not even Ans.
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 12, 2015, 02:17:30 pm
I think I know how you did it now. I bet that if I tried it it would end up being bigger than my current setup. I'll try though.
Title: Re: Code Golf - The Reboot #2
Post by: ordelore on June 12, 2015, 02:26:29 pm
254 Bytes in Axe Parser.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 12, 2015, 02:55:58 pm
Finally an Axe answer. That's the source, not the machine code, right?
Title: Re: Code Golf - The Reboot #2
Post by: ordelore on June 12, 2015, 02:57:33 pm
Wait, source is what we're being judged on?!?
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 12, 2015, 02:58:19 pm
Axe is supposed to be counted in Source bytes...
Title: Re: Code Golf - The Reboot #2
Post by: ordelore on June 12, 2015, 03:00:38 pm
Never mind, 84 bytes.
Title: Re: Code Golf - The Reboot #2
Post by: Scipi on June 12, 2015, 10:19:38 pm
I did an attempt in TIS-100 (http://store.steampowered.com/app/370360/) and got 392 bytes :P (337 if not counting header/extra whitespace in the save file)
Title: Re: Code Golf - The Reboot #2
Post by: TIfanx1999 on June 12, 2015, 11:31:42 pm
Resubmitted a working one without key repeat. 87 bytes now. Gonna keep trying and try to shrink it down. A different approach seems in order. Also @ everyone: You should submit your entry regardless of it being the smallest or not. This contest is about having fun, learning, and see what others did that you could have done better. It'll be good to see everyone's code at the end. ;)
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 13, 2015, 12:08:30 am
I agree with Art_of_camelot. The existence of a better solution shouldn't prevent anybody from submitting one.
Title: Re: Code Golf - The Reboot #2
Post by: Siapran on June 13, 2015, 05:38:59 am
133 chars in pico8_0.1.1
Title: Re: Code Golf - The Reboot #2
Post by: JWinslow23 on June 13, 2015, 10:11:00 am
Axe is supposed to be counted in Source bytes...
I've always counted Axe as the final program size. For various reasons.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 13, 2015, 10:49:57 am
If we count Axe as machine code size, then we should score it in the same category as assembly, which gives it a distinct disadvantage.

EDIT: Sorry, my clumsy fingers on mobile accidentally rated this post one star. :-\ Is there a way to undo it?
Title: Re: Code Golf - The Reboot #2
Post by: c4ooo on June 13, 2015, 07:33:36 pm
Can I infer that the user has certain variables set to certain value?

EDIT: Sorry, my clumsy fingers on mobile accidentally rated this post one star. :-\ Is there a way to undo it?
By having everyone rate it 5-star   :D

Edit: Also, I was able to save four bytes, but now do to the get key system, sometimes when you press a key the pixel does not move, and you have to spam the key. Will that be allowed where you have to spam the key in order for it to move? :P
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 13, 2015, 09:05:08 pm
c4ooo: Let me guess: two getKeys near each other that both need to register in order to update the cursor?

CKH4, I'm interested to see your 41-byte solution and how similar it is to one of my earlier attempts.
Title: Re: Code Golf - The Reboot #2
Post by: c4ooo on June 13, 2015, 09:08:03 pm
c4ooo: Let me guess: two getKeys near each other that both need to register in order to update the cursor?
Well, both DO NOT need to register in order to update the cursor, and I realy can't say anything more or else I will reveale to much    8)
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 13, 2015, 09:10:56 pm
Wait a minute... you shaved four bytes off your solution, not my 27-byte solution, right?
Title: Re: Code Golf - The Reboot #2
Post by: c4ooo on June 13, 2015, 09:13:41 pm
Yea, my solution. Although I am one of the "project authors" , AOTM only @pimathbrainiac has the entries, and even if I had them, I would never take someone's entry and resubmit it, even if I optimized it. :P

Edit: I guess it doesn't really matter if I shave 4 bytes, couse ether way, I get get second place :D
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 13, 2015, 09:43:54 pm
So you have at most 36 bytes now, considering CKH4's 41 byte solution? That's below what I could get for a "sane" entry.
Title: Re: Code Golf - The Reboot #2
Post by: c4ooo on June 13, 2015, 09:51:46 pm
Nope, I have 45 without my 4byte optimization, the person in second place has 2 more  :)
Also, I decided to call it a day submitted my entry  :D
Edit:
So you have at most 36 bytes now, considering CKH4's 41 byte solution? That's below what I could get for a "sane" entry.
Well, pimathbrainiac has not updated the list, so I thought I had second when actually I have third place :(
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 13, 2015, 10:26:27 pm
Golf your solution by one more byte. You can do it!
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 13, 2015, 10:28:39 pm
Mine might not count because of the poor getKey and a memory leak but if it does I'm proud of it.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 13, 2015, 10:30:07 pm
pimath said that solutions should work for an indefinite period of time and an indefinite number of key presses. If those weren't required I'd have 24 :P
Title: Re: Code Golf - The Reboot #2
Post by: CKH4 on June 13, 2015, 10:36:00 pm
Mine works for an indefinite number of keypresses but only runs for about a minute. Otherwise I get 43.
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 14, 2015, 03:48:07 pm
I guess the contest is over now. When the code is up I'll post an explanation for my solution, as well as a couple of earlier attempts.
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 14, 2015, 06:57:53 pm
Yeah. The contest is over. I will post up the results and solutions in just a minute.
Title: Re: Code Golf - The Reboot #2
Post by: JWinslow23 on June 14, 2015, 07:00:09 pm
Yeah. The contest is over. I will post up the results and solutions in just a minute.
Can't wait for Juju's contest. :)
Title: Re: Code Golf - The Reboot #2
Post by: pimathbrainiac on June 14, 2015, 07:02:42 pm
Actually, c4ooo is up next, then Juju.

EDIT: the results might not be up until tomorrow. @c4ooo post your contest tomorrow regardless of whether or not the results are posted when you get on.
Title: Re: Code Golf - The Reboot #2
Post by: c4ooo on June 14, 2015, 08:03:17 pm
Actually, c4ooo is up next, then Juju.

EDIT: the results might not be up until tomorrow. @c4ooo post your contest tomorrow regardless of whether or not the results are posted when you get on.
Don't worry, will do 12PM sharp, also did you get my entry?
Title: Re: Code Golf - The Reboot #2
Post by: Juju on June 14, 2015, 08:14:47 pm
Actually, c4ooo is up next, then Juju.
Yep, gotta wait until next week for mine :P
Title: Re: Code Golf - The Reboot #2
Post by: lirtosiast on June 14, 2015, 11:56:43 pm
Here are some of my attempts at this contest, in chronological order, along with explanations.
Spoiler For 40 byte solution:
While 1
getKey
If Ans
Y-i^sum(cumSum(Ans={85,41,81→Y
Pxl-On(imag(Y),real(Y
End


This was my first real (after working for an hour or so) solution once I fixed key repeat by using WASD instead of arrow keys. I had tried using two separate variables, but it seemed that using the complex plane would be smaller, even considering the two-byte cost of the real( and imag( tokens, because raising i to a power eliminates the cost of looking up the cursor change corresponding to a particular key. You can see that up, left, down, and right correspond to W, A, S, and D keys, which are key codes 85, 41, 81, and 51 respectively.

Spoiler For 33 byte solution:
While 1
getKey
If Ans
Y-i^int(4fPart(Ans/7→Y
Pxl-On(real(Y),-imag(Y
End


I began thinking about the fact that we could assume WASD are the only pressed keys, and found I could abuse it here. The WASD key codes are all different modulo 7, so taking i to that power would give 1, i, -1, and -i; luckily, they came in the right order.

Spoiler For 31 byte solution:
While 1
getKey
If Ans
Y-i^int(4cos(8Ans→Y
Pxl-On(real(Y),imag(Y
End


Same sort of idea as the previous solution, but I used a "randomizer" function, because I knew the cosines of large interger numbers would be unpredictable. I basically searched through every token and every multiplier in the book, and finally found one that worked. These changes saved one byte in the Y-modifying line, and one from not needing to negate the imag(.

I started to think I was done golfing, but then I saw that, with a mathematical way to ignore a getKey value of zero, I could eliminate the If Ans line, and if I only used one getKey, I could include it in the algorithm and also store the cursor position in Ans instead of Y, saving five bytes.

Spoiler For 27 byte solution:
While 1
Ans-iPart(i^int(48ln(getKey-1
Pxl-On(real(Ans),imag(Ans
End


This one is honestly just magic.

Spoiler For 26 byte "solution":
If it weren't for rounding errors causing the cursor to move to the side every trillion keypresses, I would be able to eliminate the iPart(:

26 bytes:
While 1
Ans+i^int(28ln(getKey-1
Pt-On(real(Ans),imag(Ans
End


And of course replacing the While 1 with recursion would save another two bytes, but crash after a few seconds.

The 1070 57-byte solutions I had in mind were all the 26-byte one (before I knew it was invalid), but with the 1 in While 1 replaced with length("[some 30-byte string], of which there are about 245^30 because there are about 245 printable one-byte tokens.

EDIT: I wonder if we'll ever get the results.