Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: GoCode.io – A Golang Game in the Browser (gocode.io)
129 points by awb 48 days ago | hide | past | web | favorite | 47 comments

This was pretty enjoyable. It reminds me a bit of "return true to win" (https://alf.nu/ReturnTrue).

I think I cheated a bit on Level 7. I just copy-pasted the code that wrote to epochComms and changed it to write to interceptComms instead. I'm not quite sure what the intended solution is.

On Level 12, does Secret.extHash serve any purpose? It never gets read.

I was doing this on mobile (Chrome on Android) and I ran into a few odd problems. If you have two opening curly braces in a row and try to backspace to delete the first one, it instead inserts a newline and duplicates the rest of the line. That is, if you have "{{foo" with the cursor after the first curly brace and you press backspace you end up with two lines each saying "{foo". This doesn't happen for me on desktop.

Copy-paste also seems to be broken on mobile. You can't select anything and trying to paste is just ignored.

It would be nice if you go go back and view the hint after you've completed a level. Or even if you could try different solutions to a level after you've finished it. You may not always be happy with the first thing that works.

Thanks for the feedback!

It uses the Ace Editor: https://ace.c9.io/

I couldn't find a more mobile friendly code editor, but I'm happy to test out other recommendations as I'd love for it to be enjoyable on mobile too.

You've probably run across it and maybe even tried it, but I use CodeMirror for Codeframe [0] and it works well on the every mobile device I've tested on, and is pretty customizable.

[0] http://beta.codeframe.co/

Very cool! I like that you don't actually fix bad code, you just hack the hell out of it to get to your objective.

It's a fun and refreshing way to look at code when you're usually always striving for best practice, idiomatic, etc. Very game-y that way. :)

The idea that Epoch writes code under the fear that other parts of the code are malicious reminded me of


Cool, but I can't seem to edit the code using Vivaldi, Chrome, Firefox or Safari (or anything?)

I thought I had the same issue, until I realized that only certain lines are editable. On the initial page, only lines 13-16 allow editing, for instance.

It requires JavaScript to run. It works for me in all browsers. Try editing the text on the white background. If you still have trouble you can contact me here: https://www.ever.io/

Me neither (and I don't have JS blocked or anything). Still can run the code though.

Are you editing the code on the white background? Only certain sections are editable.

    var buttons = []string{"red", "blue", "green", "yellow", "purple"}

    > go run level_9.go

    Sending Code Sequence...
    1 : red
    2 : blue
    3 : green
    4 : yellow
    5 : purple

    Sorry, that's not correct
Not sure what the correct sequence is, if not that?

The story is a little misleading -- the correct sequence is not in fact "sitting right there in the code."

I "cheated" on some questions by causing the correct output to be printed without actually doing what the instructions recommend, but in this case, the path of the least resistance is probably to follow the instructions, including leveraging what the lightbulb hint recommends.

Additional Hint 1: Tbebhgvarf nera'g arprffnevyl rkrphgrq va gur beqre gung gurl'er fgnegrq

Additional Hint 2: Qb nf gur vafgehpgvbaf naq uvag fhttrfg naq svk gur enpr pbaqvgvba ol hfvat n zhgrk gb rafher gung bayl bar tbebhgvar ng n gvzr fyrrcf naq gura nccraqf gb gur neenl

Additional Hint 3: Lbh pna eranzr gur frgOhggba zrgubq naq znxr lbhe bja ercynprzrag gung pnyyf gur byq bar

If you want to "cheat": hfr lbhe oebjfre pbafbyr gb frr gur .tb svyrf gung ner ybnqrq juvpu pbagnva gur fgbel, pbqr, naq pbeerpg bhgchg.

Decode hints with https://rot13.com/

Thanks for the help! Though I would have phrased the first hint as "Gur qrfverq beqre vf gur beqre va juvpu gur tbebhgvarf ner rkrphgrq"

My initial solution for this was to sleep 20*x milliseconds in setButton. Because the later random sleep is up to 10 milliseconds this ensures that the operations are always done in the defined order.

But I guess that's not what they were after, the solution was indeed as simple as:

    qrsre z.Haybpx()

Another hint, a reddit discussion of a golang phenomenon this puzzle depends on: https://bit.ly/2rqqWkh

It's a bit annoying that it's depending on such an incidental behavior.

What are the concurrency guarantees of goroutines? ;)

I'm confused here too - is there some other desired behavior? I thought the goal here was to avoid race conditions and just reproduce that order, since that's what's in the source code...

> var buttons = []string{"red", "blue", "green", "yellow", "purple"}

There are none, right? So even if you add mutexes to the existing code in an attempt to remove race conditions, it will still have race conditions, and have no guaranteed output order, because you have no guarantee which order the goroutines will start in.

The obvious way to solve it in order to get the answer shown in the source code is

    if x == 0 {
        *sequence = []Button{{"red"}, {"blue"}, {"green"}, {"yellow"}, {"purple"}}
This way there is nothing concurrently touching sequence, nor is there anything concurrent touching rand, nor is anything relying on goroutine starting order, nor are there other race conditions. But yet the site says this is wrong.

It turns out there is a guaranteed order, because of the way this puzzle is executed. https://bit.ly/2rqqWkh

Where is this guarantee stated? I don't see anything on that page about a guarantee. Does the go spec make this guarantee?

How do we know how the puzzle is executed?

And if you're saying some guarantee exists that the last executes first, then the rest execute in order, that's empirically false:



I'm not saying it's a good guarantee.

You can click the lightbulb to get a hint. The way I solved it was with a Mutex.

Yeah I know about the hint. But the result the hint leads you to doesn't make sense. Using a Mutex removes data races, but it does not remove race conditions. By leaving the race condition in, the code is has output that cannot be relied on. But yet the challenge wants us to think that somehow the output has a specific value that can be relied on.

Maybe I'm an idiot, but I don't really get what level two is asking. I "solved it" in one line by directly returning the two numbers it's looking for. But that doesn't seem right at all.

If it works then that's probably right. Based on the hint I'm guessing they want you to set up meters and seconds such that if flows through the if statement but that seems a bit pointless.

I tried typing full on mobile and it just kept deleting words.

Tried on Chrome and FF on Android. Can't type in either.

Same for me on Android 8 using Brave browser.

Very cool hacking challenge! I solved all 12 levels with only looking at the very last hint... and "wasted" half of my Sunday :-D

This game reminds me a lot of untrusted [0], though it seems to be much less polished, and the solutions feel less interesting and elegant.

[0]: https://alexnisnevich.github.io/untrusted/

Yes, I was inspired by it. It's a great game. Did you finish GoCode? The problems do get more challenging.

Yup, assuming the Finale with rob is all there is to it. A couple of them were trickier (like in level 9, it was really not clear at all what the right output was supposed to be at first), but none of them seemed all that hard. None of them actually felt "fun".

I think it mostly felt less polished due to things like the lack of music and the fact that Go itself is a bad language for this sort of thing.

In Untrusted, there were often places where you could monkey-patch objects and come up with really creative solutions. There were some problems that I felt like I really had freedom to be creative.

In this game, the imports were always out of bounds for editing, so I could never pull in 'unsafe' and have any real fun. All the solutions felt far too restrictive. Sure, there were multiple ways to hack around things, but it never felt like there was room for a spark of real creative joy.

I think go is just a bad language for "fun". It's not optimized for being able to write interesting or elegant code. It's not optimized for having fun.

Not to discount your point, but I want to offer my opinion which is different.

I had fun _because_ it was more constrained. But I also like Go.

As an example, I solved level 6 in what I understand to be an unconventional way:

(spoiler alert)

I realized I could “get out” of readCodesFromKeypad function scope by ending it early and then writing the start of another top level function. Once I had access to global scope, I could add an init() function to modify the “crypto/rand.Reader” variable and assign to it an io.Reader that I could control. I was on mobile so I decided to take a shortcut and just overwrite the global passcode variable instead.

(end spoiler)

I may have “cheated”, but it felt creative and in spirit of the game, and it got me to the next level.

I just added two lines to the starting brute-force code:

    if v, _ := validateCode(passcode); v == 1 {
        return []string{passcode}

Yep. Based on the hint for that question, I expect this is the "normal" solution.

Oh heh, I declared another method then used that to set the passcode var (without the var being shadowed), return it to the hardcoded method name, and returned that.

  // readCodesFromKeypad - get codes from keypad input
  func readCodesFromKeypad() []string {
   var passcode string
   var codes = make([]string, 0)
  // Agent Getter - bypass keypad input
   // codes := streamKeypad()
  // Agent Getter - try brute force login
   // TODO: not finished, someone's coming...

      // use shadowed "passcode" to avoid unused var error
      return append([]string{passcode}, unshadowedMethod()...}[1:]
  func unshadowedMethod() []string {
      codes := []string{passcode}
   return codes

That's level 5.

Another similiar game is Deadlock Empire


Mission 4? I should probably be overriding the interface or something right? gotta get a record function in there somehow.. not as easy as `camera.record = () => { return 'Idle' }`

You're on the right track :)

In the top right, there's a lightbulb you can click to reveal a hint for each mission. For this level the tip says "RecordingDevice is an interface, so it should be possible to create your own type of Camera".

On Reddit there's a thread that also contains some additional tips for some of the missions: https://www.reddit.com/r/golang/comments/c2hsaj/operation_go...

Everything until 12 was something that I could sort of get without knowing Go, and then the difficulty magically jumped (which is subjective, but still).

I'm surprised you got things like `init()`, interfaces, json.Marshal, and channels without knowing Go. I'm assuming you looked things up/used hints?

Are solutions listed anywhere ?

Not officially, but there are some here: https://www.reddit.com/r/golang/comments/c2hsaj/operation_go...

Solutions listed anywhere? I'm curious what the expected solutions are.

Fun, but terrible on mobile

Is there any programming that isn't terrible on mobile?

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact