Hacked app code solutions – puzzle packs – Hacking contest

As I mentioned elsewhere, the learning curve for Hacked is probably a bit steep for new coders. I didn’t just want to give you the answers outright. I’ve included hints to help where you might get stuck, all wrapped in spoiler tags. Teach a man (or woman) to fish! I’ve also included comments in the code blocks, which you can’t do in the app, but may help those who are just starting out with coding. Ignore them when typing them into the hackpad.

Note that while I tend to use the keyword “return” for better readability/understanding, you don’t always need it when the final action is to output your answer, which will save you some keystrokes and score you more points.

Condensed

Code

function f1: var_a, var_b, var_c {
  var_a = var_a + var_b;
  if var_c > 1 {
    var_a = var_a + var_c;
  }
  return var_a;
}

var_a = "";
var_b = input[0];
while var_c < input.length {
  if input[var_c] != var_b {
    var_a = f1(var_a, var_b, var_d);
	var_d = 1;
  }
  else {
    var_d++;
  }
  var_b = input[var_c];
  var_c++;
}
var_a = f1(var_a, var_b, var_d);
return var_a;

[collapse]

No duplicates

Code

while var_a < input.length {
  var_b = var_a + 1;
  while var_b < input.length {
    if input[var_a] == input[var_b] {
      input.remove(var_b);
      var_b--;
    }
    var_b++;
  }
  var_a++;
}
return input;

[collapse]

Squares

Code

var_a = [];
var_b = 2;
var_c = pow(var_b, 2);
while var_c < input + 1 {
  var_a.push(var_c);
  var_b++;
  var_c = pow(var_b, 2);
}
return var_a;

[collapse]

Rotated

Code


[collapse]

Overlap

Code

var_a = input[0][0];
while var_a < input[0][1] {
  var_c = input[1][0];
  while var_c < input[1][1] {
    if var_a == var_c {
      return true;
    }
    var_c++;
  }
  var_a++;
}
return false;

[collapse]

3 thoughts on “Hacked app code solutions – puzzle packs – Hacking contest

  • Kahn

    I don’t see any solve for puzzle Rotated so Ill share mine
    Probably not the better solution but its working 🙂

    function f1: input {
      var_a = [];
      while var_b  f1(var_a));
    while var_a++ < input[0].length {
      if input[0].push(input[0].remove(0)) == input[1] {
        return true;
      }
    }
    false;
    
    Reply
    • Joseph

      very nice! I like recursive methods but I’m terrible at thinking them up, my method looked like this…

      var_a = []
      var_b = []
      while var_c < input[0].length {
          var_a.push(input[0][var_c]);
          var_b.push(input[1][var_c]);
      }
      foreach var_d in var_a {
          var_b.insert(0, var_b.pop)
          if var_a == var_b {
              return true;
          }
      }
      return false;
      
      Reply
  • Daniel

    I would like to post my solution for Overlap, which I found less tricky than the one published:

    return input[0][0]  input[1][0];
    
    Reply

Leave a comment

Your email address will not be published. Required fields are marked *

  • Facebook
  • Google+
  • LinkedIn
  • Twitter
  • YouTube
  • IMDb