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″]
Condensed
[spoiler title=”Code”]
[code lang=”hack”]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;
[/code]
[/spoiler]
No duplicates
[spoiler title=”Code”]
[code lang=”hack”]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;
[/code]
[/spoiler]
Squares
[spoiler title=”Code”]
[code lang=”hack”]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;
[/code]
[/spoiler]
Rotated
[spoiler title=”Code”]
[code lang=”hack”]
[/code]
[/spoiler]
Overlap
[spoiler title=”Code”]
[code lang=”hack”]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;
[/code]
[/spoiler]
7 thoughts to “Hacked app code solutions – puzzle packs – Hacking contest”
I don’t see any solve for puzzle Rotated so Ill share mine
Probably not the better solution but its working 🙂
[hack]
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;
[/hack]
very nice! I like recursive methods but I’m terrible at thinking them up, my method looked like this…
[hack]
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;
[/hack]
I would like to post my solution for Overlap, which I found less tricky than the one published:
[hack]
return input[0][0] input[1][0];
[/hack]
I have found better solution for overlap
[code]
Return input[0] [0] <input [1] [1]&&input [0] [1] >[1] [0]
[/code]
Hello,
Can someone explain to me the Overlap pattern please ?
Don’t understand…
Thanks
Overlap was fairly straightforward.
I wish i knew how to post code snippets.
1 input.sortwith (function var_a, var_b -> var_a [0] input [1][0]
Overlap was fairly straightforward.
I wish i knew how to post code snippets.
1 input.sortwith (function var_a, var_b -> var_a [0] input [1][0];