Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
So in other words: If the first number is a zero you can put it directly in the outbox.
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.
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)
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.
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. :)
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.
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.
-- 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.
Yes you did. It took a lot of re-reading to understand the issue though.