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″]
Equals
[spoiler title=”Code”]
[code lang=”hack”]input[0] == input[1];
[/code]
[/spoiler]
Times 10 plus 2
[spoiler title=”Code”]
[code lang=”hack”]input * 10 + 2;
[/code]
[/spoiler]
Only threes
[spoiler title=”Code”]
[code lang=”hack”]var_a = [];
while var_b++ < input {
if mod(var_b, 3) == 0 {
var_a.push(var_b);
}
}
var_a;
[/code]
[/spoiler]
ZipMerge
[spoiler title=”Code”]
[code lang=”hack”]var_a = [];
var_b = input[0];
var_c = input[1];
while var_d < max(var_b.length, var_c.length) {
if var_d < var_b.length {
var_a.push(var_b[var_d]);
}
if var_d < var_c.length {
var_a.push(var_c[var_d]);
}
var_d++;
}
return var_a;
[/code]
[/spoiler]
[spoiler title=”Alternative Code”]
[code lang=”hack”]while var_b < max(input[0].length, input[1].length) {
var_c = 0;
while var_c < 2 {
if var_b < input[var_c].length {
var_a.push(input[var_c][var_b]);
}
var_c++;
}
var_b++;
}
return var_a;
[/code]
[/spoiler]
Missing letter
[spoiler title=”Code”]
[code lang=”hack”]var_a = "":
while var_b < input[0].length {
if var_b != input[1] {
var_a = var_a + input[0][var_b];
}
var_b++;
}
return var_a;
[/code]
[spoiler title=”Alternative Code”]
[code lang=”hack”]var_a = "":
while var_b < input[0].length {
if var_b != input[1] {
var_a = var_a + input[0][var_b];
}
var_b++;
}
return var_a;
[/code]
[/spoiler]