-2
\$\begingroup\$

So simple: Provide some code that outputs foo and with the reversed source outputs bar. But before you come up with something like this boring python 2:

print "foo"#"rab" tnirp

you should know the score: You multiply the number of bytes with (1 + dead bytes), where dead bytes are bytes that can be changed to most other characters without changing the behaviour in the current execution direction (in the sense that more can be changed than not). This is valid for comments or labels or code after some exit statement or such workarounds (you know what I mean, so don't feel a hero because your language has some feature with a different name to ignore code). I want to see your creativity in reusing code depending on the direction!

Examples for score count

  • In the example above, the # is no dead code, because you cannot simply replace it, but the following 11 bytes are dead code, thus we get a score of 23 * (1+11) = 276! Valid, but not so nice anymore.
  • A sh answer like echo foo # rab ohce would score a slightly better 190.
  • An sed answer s:^:foo:;:rab:^:s misuses the : label to hide code, but the label is still dead code, resulting in a score of 136.
  • foo//rab in /// has the open // as valid exit, so this would have only three bytes of dead code, reaching a score of 32.

Rules

  • Dead code can be different for both directions, so for scoring, the number of dead bytes for the worse direction is counted: If you have three deads bytes forward, but 7 backwards, your multiplier will be 8.
  • Your code must not output anything visible after the foo or bar, just something like whitespaces or newlines.
  • foo and bar can be lowercase or uppercase, as you like
  • Your program has to end execution by itself, so don't try to loophole through some infinite loop after output!
  • Don't use any non-empty input, of course.
  • Why do I add +1 to the dead bytes? Because I don't want a zero score for living-code-only answers like this /// solution (actual score 65):
    foo/./::://:/\//:f.o.b.a.r::/\// //\/::r.a.b.o.f://\/://:::/./rab
  • Did I mention the smallest score wins?
\$\endgroup\$
17
  • \$\begingroup\$ Please note that sandbox comments have been resolved. \$\endgroup\$
    – Philippos
    Commented Jan 5 at 11:36
  • \$\begingroup\$ Just to clarify - in print(["foo","bar"][0]), ,"bar" is dead code? \$\endgroup\$ Commented Jan 5 at 11:42
  • 2
    \$\begingroup\$ In which direction is dead code counted? \$\endgroup\$ Commented Jan 5 at 11:47
  • 8
    \$\begingroup\$ What do you mean by "most other characters"? \$\endgroup\$
    – Adám
    Commented Jan 5 at 12:05
  • 1
    \$\begingroup\$ Dear close-voters and downvoters: In the sandbox, this challenge has received three upvotes after clarification. If there are still some things unclear, there is the possibility to ask for clarification; I did answer immediately (even though giving a definition of »most« may seem superfluous). Voting to close without commenting on why is not good for the site. \$\endgroup\$
    – Philippos
    Commented Jan 5 at 15:24

2 Answers 2

4
\$\begingroup\$

Charcoal, 8 bytes, score 32

bar←←oof

Try it online! Outputs foo. Explanation: The first word is overprinted in reverse by the reversed second word. The second is needed to overprint and the first is needed to overprint in the correct location, but the first word can be e.g. any three ASCII characters.

foo←←rab

Try it online! Outputs bar.

\$\endgroup\$
3
\$\begingroup\$

Vyxal 3, 11 * 6 = 66, 10 * 5 = 50

"rab""foo"

Forwards

"oof""bar"

Backwards

\$\endgroup\$
4
  • \$\begingroup\$ "rab""foo" seems to work \$\endgroup\$ Commented Jan 5 at 12:53
  • 2
    \$\begingroup\$ I'd argue the score is 40 since "s aren't dead bytes, changing them mostly result in different outputs. \$\endgroup\$
    – math scat
    Commented Jan 5 at 13:22
  • \$\begingroup\$ Thank you. Can you please add a link to an online tool for verification? \$\endgroup\$
    – Philippos
    Commented Jan 5 at 13:52
  • \$\begingroup\$ @Philippos This solution felt kind of trivial, so I didn't put it, but you asked, so here you go! \$\endgroup\$
    – Joao-3
    Commented Jan 5 at 14:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.