!7 sS testCases; p { testCases = loadSnippet(#1013119); L lines = lines(testCases); L l = indexesOfLinesBeginningWithDoubleArrow(lines); int i = 0, cases = 0; for (int line : l) { S question = lines(subList(lines, i, line)); S answer = trimDropPrefixTrim("=>", lines.get(line)); i = line+1; assertContainsCodeTokensIC(answer, callAnswerFunctionVerbose(question)); ++cases; } print("OK (" + n2(cases, 'case) + ")"); } answer { // parsing new L parts; L l = tok_splitAtSpacedDashes_old(s); parts.addAll(tok_splitAtAndFromMiddle(l.get(0))); parts.add(l.get(1)); // loop pnl(parts); new L output; new Executor e; for (S part : parts) { print(part); e.process(part); L out = cloneAndClearList(e.output); printLinesWithIndent(" => ", out); output.addAll(out); } try answer lines(output); } sclass Executor { int length = -1; // unknown new L output; void say(S s) { output.add(s); } void process(S s) { L tok = javaTok(s); // interpretation int i = findCodeTokensIC(tok, ""/*, "elements"*/); if (i >= 0) { int n = parseInt(tok.get(i)); S before = get(tok, i-2); if (eqic(before, "add")) ret with length += n; if (eqic(before, "remove")) ret with length -= n; ret with length = n; } if (hasCodeTokensIC(tok, "empty")) ret with length = 0; if (hasCodeTokensIC(tok, "add", "one")) ret with ++length; if (hasCodeTokensIC(tok, "remove", "one")) ret with --length; if (hasCodeTokensIC(tok, "how", "long")) say("The list is " + n2(length, "element") + " long"); } }