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″]
Count As
[spoiler title=”Code”]
[code lang=”hack”]while var_a < input.length {
if input[var_a] == "a" {
var_b+;
}
var_a+;
}
return var_b;
or simpler still:
while var_a < input.length {
if input[var_a++] == "a" {
var_b+;
}
}
var_b;
[/code]
[/spoiler]
Find the one
[spoiler title=”Code”]
[code lang=”hack”]while var_a < input.length {
if input[var_a] == 1 {
return var_a;
}
var_a++;
}
[/code]
[/spoiler]
Sum
[spoiler title=”Code”]
[code lang=”hack”]foreach var_a in input {
var_b = var_b + var_a;
}
return var_b;
[/code]
[/spoiler]
End by zero
[spoiler title=”Code”]
[code lang=”hack”]return mod(input, 10) == 0;
[/code]
[/spoiler]
Reverse
[spoiler title=”Code”]
[code lang=”hack”]var_a = "";
var_b = input.length – 1;
while var_b > -1 {
var_a = var_a + input[var_b–]
}
return var_a;
[/code]
[/spoiler]
One thought to “Hacked app code solutions – Puzzle pack – Easy Peasy”
Count As: it’s var_a++. not +.