Human Resource Machine

Human Resource Machine

View Stats:
Protagonist Oct 17, 2015 @ 5:30pm
Zero terminated sum [spoilers]
As you can probably guess I'm up to the zero terminated sum problem.

It seems fairly straight forward until I run the sequence then it keeps giving me the same error, that it should end with a zero. But if I add the whole string it the result isn't a zero.

Could someone take a look at this sequence, I just can't see what I'm doing wrong so I'm unsure how to fix it.

-- HUMAN RESOURCE MACHINE PROGRAM --

a:
INBOX
COPYTO 0
b:
INBOX
JUMPZ c
ADD 0
COPYTO 0
JUMP b
c:
COPYFROM 0
OUTBOX
JUMP a


Please, don't give away the solution, I still want to solve it. I just want to know if theirs anything completely wrong with this sequence.
< >
Showing 1-15 of 15 comments
windblade Oct 17, 2015 @ 5:58pm 
The game includes an "empty" string (Input is just a zero, with no numbers before it) which this solution can't handle. If you get only a zero, the game wants you to output 0 as the sum.
Last edited by windblade; Oct 17, 2015 @ 5:58pm
qbicfeet Oct 17, 2015 @ 6:00pm 
They want you to add the 0 to the sum of the string as well, which results in the sum of empty strings (just one 0) being zero.

So in other words: If the first number is a zero you can put it directly in the outbox.
Protagonist Oct 17, 2015 @ 6:38pm 
OK, I'm a little confused. I'm using the zeros as markers for starting and ending a loop, is that not the correct way to do this?

The error always happens at the end of the final string, probably should have clarified that. Everything else is fine, even strings containing 1 zero. If I input the sum of the final string it's telling me it wanted a zero but the sum is not zero and never has been.

Try running it, you'll see what I mean.
Gigory Chadbert Oct 17, 2015 @ 6:45pm 
Originally posted by _-SpUtNiK-_:
OK, I'm a little confused. I'm using the zeros as markers for starting and ending a loop, is that not the correct way to do this?

The error always happens at the end of the final string, probably should have clarified that. Everything else is fine, even strings containing 1 zero. If I input the sum of the final string it's telling me it wanted a zero but the sum is not zero and never has been.

Try running it, you'll see what I mean.

Using them as end markers is correct, however if you encounter 2 0's in a row (which I think is guanteed at least once in this problem) - your outbox for the "empty" (aka - nothing from end marker to end marker) is a zero itself. Focus on a conditional to catch that when it happens.
windblade Oct 17, 2015 @ 6:47pm 
Yes, but the actual bug occured before the final string. Remember, 0 always marks the end of the string. Maybe an example will help:

Example Input: 1, 2, 3, 0, 3, 0, 0, 4, 1, 0
Example Input Expanded: 1, 2, 3, (ENDOFSTRING), 3, (ENDOFSTRING), (ENDOFSTRING), 4, 1, (ENDOFSTRING)
Correct Output: 6, 3, 0, 5
String 1: (1, 2, 3)
String 2: (3)
String 3: Empty
String 4: (4, 1)
Salty Catfish! Oct 17, 2015 @ 9:23pm 
I'm having the same problem...My formula correctly adds the contents of the last string like all the others, but I always receive an error that the last output I should have is a zero. So for example, if the inbox ends in "0 1 1 0" my formula puts a 2 in the outbox but the error says it should have been a zero. I'm stumped.
windblade Oct 17, 2015 @ 9:41pm 
Read the previous replies. A zero always, always, ALWAYS marks the END of a string.
So "0, 1, 1, 0" isn't one string, it's TWO strings. The string "0", and the string "1, 1, 0", so the output would be 0 for the first string, and then 2 for the second string.
Salty Catfish! Oct 17, 2015 @ 9:45pm 
Yes, I know that -- for simplicity's sake, consider it more as ending in "1 1 0" and the game telling me that I should be giving it a 0, not a 2, for the final output. Which doesn't match the examples the game gives at all.
windblade Oct 17, 2015 @ 9:57pm 
You're very likely just skipping an empty string. If the input is "1, 2, 0, 0, 1, 1, 0" then the output should be "3, 0, 2". If you output "3, 2", the game will error out, not because it ends with a zero, but because you skipped a zero.
RaveBomb Oct 17, 2015 @ 10:00pm 
I'm going to spell this out since I've been bashing my head on the same wall and I think I understand where the confusion is coming from.

Input example:
1 2 0 3 4 5 0 0 0 6 7 8 0

The output needs to be:
3 12 0 0 21

! + 2 = 3
3 + 4 + 5 = 12
0 ("empty" string)
0 ("empty" string)
6 + 7 + 8 = 21


The error comes from the program not properly handling 0 0. The program doesn't see it as TWO empty strings, it sees it as ONE string = "0"

EDIT: What windblade said. :)
Last edited by RaveBomb; Oct 17, 2015 @ 10:01pm
Gigory Chadbert Oct 17, 2015 @ 10:41pm 
Originally posted by RaveBomb:
The error comes from the program not properly handling 0 0. The program doesn't see it as TWO empty strings, it sees it as ONE string = "0"

Like I said 5 replies ago, focus on a conditional for a 0 0. Since the OP doesn't want a solution in here, I suggest using HRM's debug to SEE how the 0 0 fails, and then use a "jump if zero" to put your program at the right place, at the right time.
mreed2 Oct 18, 2015 @ 4:58am 
Actually, the problem here comes from trying to create a special case /when you don't need to/. Each and every time you read an input from inbox, whether it is the start of a string or in the middle of a string, you should be doing the exat same handling ("If the input is zero, jump to code that outputs a result -- otherwise, add it to the accumulated result and save it").

You /do/ need init code to clear the accumulator, but that init code should run /after/ you've sent the result to the outbox and /before/ you read anything new from the inbox. There is a reason why one of the memory locations is preset to zero -- use it.

Now, if you are trying to solve the speed challenge, things are different -- you can save cycles by using the first value read from the inbox initalize your accumulator, but... This makes your code much, much, more messy. In effect, you will need to unroll the first iteration through your loop in its entirity. But even there, you'll still have a "Jump if zero" occuring immediately after your "Inbox" statement.
Protagonist Oct 18, 2015 @ 7:14am 
Solved it, thanks for the help guys.

-- HUMAN RESOURCE MACHINE PROGRAM --

a:
INBOX
JUMPZ d
COPYTO 0
b:
INBOX
JUMPZ c
ADD 0
COPYTO 0
JUMP b
c:
COPYFROM 0
d:
OUTBOX
JUMP a


11/72 solution
Believe it or not, I solved it before mreed2 practically gives the answer away.

Theirs two empty strings immediately after each other, the second was slipping through in to the loop and being processed. It looked accurate, because it's a zero it didn't effect the sum, thats what stumped me for a little while.
RaveBomb Oct 18, 2015 @ 7:50am 
Originally posted by Faptech:
Originally posted by RaveBomb:
The error comes from the program not properly handling 0 0. The program doesn't see it as TWO empty strings, it sees it as ONE string = "0"

Like I said 5 replies ago, focus on a conditional for a 0 0. Since the OP doesn't want a solution in here, I suggest using HRM's debug to SEE how the 0 0 fails, and then use a "jump if zero" to put your program at the right place, at the right time.

Yes you did. It took a lot of re-reading to understand the issue though.
AstroRoll Oct 23, 2016 @ 2:40am 
What's incredibly frustrating with this is that the Boss specifically tells you a string cannot contain ZERO (because "zero means something special")... and gives you an example of an "empty string" (two zeros in a row). So based on this information, the output shouldn't ever contain zeros, because the zeros are specifically said to be used as a marker and are not a part of the string; an "empty string" should result in nothing, not a zero. This is why it was so hard for the OP and others to grasp the solution.
Last edited by AstroRoll; Oct 23, 2016 @ 2:57am
< >
Showing 1-15 of 15 comments
Per page: 1530 50