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.

[toc heading_levels=”2″]

Erase target

[spoiler title=”Code”]

[code lang=”hack”]var_a = "";
var_b = input[0];
var_c = input[1];
while var_d < var_c.length {
if var_c[var_d] != var_b {
var_a = var_a + var_c[var_d];
}
var_d++;
}
return var_a;
[/code]

[/spoiler]

Where’s waldo

[spoiler title=”Horrible Code”]

[code lang=”hack”]var_a = ["w", "a", "l", "d", "o"]
var_b = 0;
var_d = 0;
while var_c < input.length {
if input[var_c] != var_a[var_b] {
var_b = 0;
if input[var_c] == var_a[var_b] {
var_d = var_c;
var_b++;
}
else {
var_d = -1;
}
var_c++;
}
else {
if var_b == 0 {
var_d = var_c;
}
if var_b == 4 {
return var_d;
}
var_b++;
var_c++;
}
{
return var_d;
[/code]

[/spoiler]

Alone

[spoiler title=”Code – Concise 350, Complex 250″]

[code lang=”hack”]var_b = [];
while var_c++ < input.sort[input.length-1] + 1 {
var_b.push(0);
}
foreach var_c in input {
var_b[var_c]++;
}
while var_d < var_b.length {
if var_b[var_d] == 1 {
return var_d;
}
var_d++;
}
[/code]

[/spoiler]
[spoiler title=”Alternative Code”]

[code lang=”hack”]

[/code]

[/spoiler]

Count words

[spoiler title=”Code – Concise 710, Complex 350″]

[code lang=”hack”]while var_a < input.length {
if input[var_a] == " " {
var_b++;
}
var_a++;
}
return var_b + 1;
[/code]

[/spoiler]

Split strings

[spoiler title=”Code – Concise 410, Complex 350″]

[code lang=”hack”]var_c = "";
var_b = [];
while var_a < input.length {
if input[var_a] == "-" {
var_b.push(var_c);
var_c = "";
}
else {
var_c = var_c + input[var_a];
}
var_a++;
}
var_b.push(var_c);

[/code]

[/spoiler]

7 thoughts to “Hacked app code solutions – puzzle packs – FBI Job

  • Kahn

    Here is my solution for Where is Waldo

    [hack]
    var_a = "";
    while var_b < input.length – 4 {
    while var_c < 5 {
    var_a = var_a + input[var_b + var_c];
    var_c++;
    }
    if var_a == "waldo" {
    return var_b;
    }
    var_b++;
    var_c=0;
    var_a="";
    }
    [/hack]

    Reply
    • Joseph

      Here’s my Where’s Waldo code:

      [hack]
      var_a = "waldo";
      var_b = input;
      while var_c < var_b.length {
      var_d = true;
      var_e = 0;
      while var_e < var_a.length {
      if var_b[var_c + var_e] != var_a[var_e] {
      var_d = false;
      }
      var_e++;
      }
      if var_d {
      return var_c;
      }
      var_c++;
      }[/hack]

      Reply
      • Nonono

        While var_a < input.lenght -1 {
        If input [ var_a] == "w" {
        If input [ var_a + 1] == "a" && input [ var_a + 2] == "l" && input [ var_a +3] == "d" && input [ var_a +4 ] == "o" {
        Var_b= var_a;
        }
        }
        }

        Reply
      • Nonono

        While var_a < input.lenght -1 {
        If input [ var_a] == "w" {
        If input [ var_a + 1] == "a" && input [ var_a + 2] == "l" && input [ var_a +3] == "d" && input [ var_a +4 ] == "o" {
        Var_b= var_a;
        }
        }
        Var_a++;
        }
        Return var_b;

        Reply
  • spaceship

    What is the meaning “&lt” and “&quot” and how can i type them in in the app? I have already solved this but i want tó try out different solutions

    Reply
    • Andrew

      Somewhere down the line the code got mangled and converted into html elements. They should have been < and > and ” symbols

      Reply
  • Stephen

    Your code for “Count Words” breaks if I pass it an empty string. I know that’s not one of the test data, but still, consider this:

    var_o = 0;
    if input.length > 0 {
    var_o++;
    while var_c < input.length {
    if input[var_c] == " " {
    var_o++;
    }
    var_c++;
    }
    }
    var_o;

    Reply

Leave a comment

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