Omnimaga

Calculator Community => Contests => Community Contests => Topic started by: Juju on June 22, 2015, 12:00:01 am

Title: Code Golf: The Reboot #4
Post by: Juju on June 22, 2015, 12:00:01 am
Welcome to this week's Code Golf: The Reboot, the fourth incarnation of the challenge hosted by myself, Juju. Not @pimathbrainiac, @c4ooo nor @JWinslow23, the one and only @Juju. I have a situation for you tonight. Let's say you have a car. Unfortunately, you left your set of keys on the seat, and the car is locked. "Oh no, I locked my keith inside", you say, with a strong lisp. However, your car came with a numerical lock, five (5) keys numbered from 1 to 5 that can replace your keys if needed, no need to call the AAA, OnStar or whatever it's called in your country. The car is rather new and you didn't had time to check the manual for the default code and how to set it, but you know the code is four (4) numbers long and the lock checks after every keypress, as in, if you enter successively 1-2-3-4-5-1, it checks against the codes 1234, 2345 and 3451. You don't really have the time to try every combination one after the other, but you know of a sequence that will check against every code successively in a minimal number of keypresses, the de Bruijn sequence, as it's called. You have your calc/smartphone/laptop on you, as you've been taught to carry no less than 5 computers on you at all times, like a sensible person (http://www.mspaintadventures.com/?s=6&p=005097), so you write a little program to compute such a sequence and try it out.

Here's a sample output:
Code: [Select]
11112111311141115112211231124112511321133113411351142114311441145115211531154115
51212131214121512221223122412251232123312341235124212431244124512521253125412551
31314131513221323132413251332133313341335134213431344134513521353135413551414151
42214231424142514321433143414351442144314441445145214531454145515152215231524152
51532153315341535154215431544154515521553155415552222322242225223322342235224322
44224522532254225523232423252333233423352343234423452353235423552424252433243424
35244324442445245324542455252533253425352543254425452553255425553333433353344334
53354335534343534443445345434553535443545355435554444544554545555

The cyclic sequence (as in, it wraps around so at the end it's really ...4555511112...) should contain every 4-number sub-sequence as described above exactly once per cycle. Your output don't have to be exactly this, as in there's many, many sequences with the above properties, but it should have the same length. Also, no newlines other than where it should wrap around on the screen (I've put some here because it would mess up this post, don't do that at home). Your challenge is, of course, write the smallest program that generates such sequence. If the sequence don't fit it all on the screen, like on calcs, you can implement a pager (like less on UNIX systems) or output a string that can be scrolled, or anything that could work, be sure to ask me if you're not sure and tell instructions if it's not immediately obvious or requires user action.

All the usual rules applies, like no loopholes (http://meta.codegolf.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default). All non-calc languages will be scored with this counter (http://juju2143.ca/golf/) I wrote for your convenience. 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). PM me with your submission on Omnimaga and/or CodeWalrus, on every private messaging system you know you can reach me or if you know where I live or know me IRL, bring me a 3.5" floppy disk with the source enclosed. (Seriously, that would be epic and would definitely allow you a bonus.) I'll also count out the number of keypresses it took you to get to a particular code I won't disclose until the end, but it's just for fun :P And if you wanna get involved, I suggest you to check this thread (https://www.omnimaga.org/community-contests/code-golf-the-informationdiscussionplanning-thread/).

Good luck and have fun! You have until next Sunday, 11:59:59 PM EDT.

Next week with @JWinslow23, you found your keys, but you can't figure out which one it is...

Scores
 
Language Ranking
RankLangUserSizeDateCode
1Ruby@Juju1632015/06/22 15:29:00
Spoiler For Spoiler:
Code: [Select]
[/spoiler]



Ruby
RankUserSizeDate
1Juju1632015/06/22 15:29:00

Unfortunately, no one submitted any entry, no one got the key... And I win by default, apparently. I'll post my code soon, and you still can submit an entry at a later date.
Title: Re: Code Golf: The Reboot #4
Post by: Scipi on June 22, 2015, 08:52:07 pm
I might not be able to submit an entry because I have no idea how to generate de Bruijn sequences XD

I'll still make an attempt, though
Title: Re: Code Golf: The Reboot #4
Post by: Juju on June 22, 2015, 11:46:57 pm
I might not be able to submit an entry because I have no idea how to generate de Bruijn sequences XD

I'll still make an attempt, though
There's a lot of code and algorithms over the internet that generates de Bruijn sequences, I know it's kinda hard to come up with an algorithm yourself, so check one that already exists, study it and make your own golfed implementation. That's kind of the point. The Wikipedia page for the sequence describes a Python implementation, I think it's a good starting point.
Title: Re: Code Golf: The Reboot #4
Post by: Runer112 on June 23, 2015, 11:23:30 am
For those who want to test their solutions, you can feed your result to this program (http://cjam.aditsu.net/#code=6%2C1%3Es4m*q_3%3C%2B4ewf%7B%5C%3AXf%3Dee%7B1%3D%7D%2C0f%3D%3AP%2C1%3D!%7BXSP%60N%7D*%7D). It will output each sequence that shows up more than once or not at all with a list of the indices at which it shows up. Note that the program may take a few seconds to complete; when it's done, the "Run" button will be re-enabled.

For example, here's the output I get by deleting a random character from the example output in the first post:
Code: [Select]
1441 [58 271]
1442 ""
2144 ""
4144 [273 281]
4214 ""
4414 [272 280]
4421 ""
Title: Re: Code Golf: The Reboot #4
Post by: Juju on June 25, 2015, 11:08:50 pm
Reminder that I only recieved one entry. And it's mine. ._.
Title: Re: Code Golf: The Reboot #4
Post by: JWinslow23 on June 26, 2015, 08:02:24 am
Reminder that I only recieved one entry. And it's mine. ._.
I dunno about this for a challenge, really. Not many people understand how to make that kind of stuff :P

...I'll do SOMETHING in GS or CJam. it hasn't been a few minutes and I barely understand the algs out there, and I don't wanna steal already-golfed answers from StackExchange
Title: Re: Code Golf: The Reboot #4
Post by: c4ooo on June 27, 2015, 12:38:25 pm
There seems to not be much activity :(
On a side note, i dove by "keith road" today, ile see if i can get a pic of it on the way back XD
Title: Re: Code Golf: The Reboot #4
Post by: JWinslow23 on June 27, 2015, 01:24:28 pm
Well, no matter the activity on this one, this is only a minor hiccup. It's just a note to future challenge makers on what to try and avoid in their challenges: stuff people don't know about and is hard to do even if you do know about.
Title: Re: Code Golf: The Reboot #4
Post by: Juju on June 28, 2015, 03:33:58 am
Well, I did it myself and had no idea how to do it before, and thought the algorithm isn't that hard and easy to golf, figured you guys could do it... Oh well.
Title: Re: Code Golf: The Reboot #4
Post by: Juju on June 29, 2015, 12:19:47 am
Well, no one entred, that's a bummer. Thought you guys would do it anyway... Oh well. Stay tuned for the next code golf hosted by @JWinslow23 !
Title: Re: Code Golf: The Reboot #4
Post by: TIfanx1999 on June 29, 2015, 02:10:11 am
I *think* I got the idea, but I've been really sick this week. Didn't have a chance to attempt anything.
Title: Re: Code Golf: The Reboot #4
Post by: JWinslow23 on June 29, 2015, 04:15:37 pm
Challenge has been posted (https://www.omnimaga.org/community-contests/code-golf-the-reboot-5/) and (http://codewalr.us/index.php?topic=575) crossposted (http://www.cemetech.net/forum/viewtopic.php?p=237022)!