12
\$\begingroup\$

Your goal is to write a program that prints the string abc in two languages. However, while the full code will print abc in one language (we'll call it Language 1), the other one (Language 2) must print abc if (and only if) every other character is skipped starting from the second character. If the full code is run in language 2, it must throw an error. If the skipped code is run in language 1, likewise, it must throw an error.

Rules and Clarification

  • Trailing newlines are allowed.
  • Output must be lowercase.
  • "Run" means compiled for compiled languages.
  • We will define "throwing an error" as outputting nothing to STDOUT and something to STDERR.

Test Cases

Language 1: 12345 -> abc
Language 1: 135 -> error
Language 2: 135 -> abc
Language 2: 12345 -> error

Scoring

The shortest code in bytes wins (the full code, not the skipped code).

Edit: I have clarified the rules based on feedback in the comments. The existing answers should still be valid.

\$\endgroup\$
  • \$\begingroup\$ Is trailing whitespace allowed in the output? \$\endgroup\$ – Arnauld Oct 25 '19 at 15:17
  • 2
    \$\begingroup\$ What precisely counts as an error? Is outputting nothing to STDOUT and something to STDERR sufficient? Consider this potential submission, where the Foo program that "errors" encounters an error that doesn't cause the program to halt, but it has no other output. \$\endgroup\$ – FryAmTheEggman Oct 25 '19 at 17:46
  • 1
    \$\begingroup\$ Are we to interpret "run" as "compiled" for compiled languages? Otherwise the implication would be that both shortened and full programs must compile in both languages, but throw run-time errors upon execution if the wrong length. \$\endgroup\$ – gastropner Oct 30 '19 at 0:50
  • \$\begingroup\$ Can we output in uppercase (ABC instead of abc)? \$\endgroup\$ – Grimmy Oct 31 '19 at 13:45

11 Answers 11

8
\$\begingroup\$

brainfuck, 28 26 bytes

a+b[c-/[/---<]>>- ]<-.+.+.

Try it online!

Got the bf code from here.

Fails in Ink due to Expected target for new thread but saw '.+.+.'.

ink

abc//-<>-]-++

Try it online!

Ink will just print abc and the rest is a comment.

Fails in brainfuck due to mismatched bracket.

|improve this answer|||||
\$\endgroup\$
6
\$\begingroup\$

Keg, 21 19 bytes (19 17 characters)

abc#1 / ╘ " a b c

Try it online!

Simply prints abc and the rest is a comment.

Fails in MathGolf due to an undefined operator overload of /. / can not work on an integer (1) and a string( pushed via the space instruction.)

MathGolf

ac1/╘"abc

Try it online!

Does a bunch of nonsense, then deletes the whole stack. "abc pushes abc and the stack has an implicit output.

Fails in Keg due to the failure of implicit-outputting a floating-point number in its character form.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Keg! \$\endgroup\$ – Lyxal Oct 25 '19 at 22:32
5
\$\begingroup\$

Japt and Pyth, 20 bytes

Both are shortenings of common scripting languages, nice

Japt: "_a_b_c_"v ë2,1 +[] (TIO, error in Pyth)

Pyth: "abc" 21 [ (TIO, error in Japt)

|improve this answer|||||
\$\endgroup\$
3
\$\begingroup\$

PHP and Emoji, 21 chars, 30 bytes

Full:

⛽_a_b_c_🚘➡➡;echo abc;

Skipped:

⛽abc🚘➡eh b;

PHP, Full - Try it online! Prints: abc

Emoji, Skipped - Try it online! Prints: abc

PHP, Skipped - Try it online! Error: PHP Parse error: syntax error, unexpected 'b' (T_STRING)

Emoji, Full - Try it online! Error: IndexError: pop from empty list

|improve this answer|||||
\$\endgroup\$
3
\$\begingroup\$

C++ (gcc) / C (gcc), 87 bytes

Full (C++)

//*
#import<cstdio>
main(){puts("abc"/*//
m_a_i_n_(_)_{_p_u_t_s_(_"_a_b_c_"_/*/


) ; }

Skipped (C)

/*#motcti>mi({us"b"*/main(){puts("abc"//
);}

Full C++, Working

Skipped C++, Error

Full C, Error

Skipped C, Working

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

JavaScript (V8) and PHP, 29 bytes

Full:

print`abc`;'e_c_h_o_ _a_b_c';

Skipped:

pitac;echo abc;

JavaScript, Full - Try it online! Prints: abc

PHP, Skipped - Try it online! Prints: abc

JavaScript, Skipped - Try it online! Error: SyntaxError: Unexpected identifier

PHP, Full - Try it online! Error: abc: command not found

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

CJam and Gaia, 15 bytes

(CJam only cares about printable ASCII, so Gaia's codepage can be used to encode both programs)

Full:

 'a'b'c'” 'ọ;e<

Works in CJam

Errors in Gaia

Reduced:

 abc”'ọe

Works in Gaia

Errors in CJam

Explanation

This takes some advantage of the fact that ' defines a character literal in both languages.

Full program:

We push 5 characters: a, b, c, , and . ; deletes the and e< leaves the minimum of c and , which is c. The remaining characters (abc) are joined together and output implicitly.

In Gaia, everything up to is a string literal. We then push the char , and then copy (;) the string literal back to the top and attempt to eval it (e). This throws an error because the last character in that string is ', which is improper syntax (a character literal after it is expected).

Reduced program:

(or, more specifically, byte 0xFB) is not defined, so the program terminates with an error.

In Gaia we get the string literal  abc (with leading space). We then push the character and eval it, which is the command for trim. This leaves plain abc on the stack, which is implicitly output.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Turing Machine Code and Whitespace, 85 bytes

Full

 	 0 _	a	r 1 ; ; ;	;
	
 1 _ b r 2	;	; ; ; ;	; ;
	
 2 _ c * 3	;	; ; ; ;	;	;
	;
 ; ;



Works in Turing Machine Code
Errors in Whitespace: Prelude.!!: index too large

Reduced












Works in Whitespace
Errors in Turing Machine Code: Halted. No rule for state '0' and symbol '_'.

Takes advantage of the fact that Turing Machine Code ignores most white space and Whitespace pretty much ignores everything else.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Backhand and ><>, 39 bytes

Full

8.cv*c0*~]!]/]:::[@:1[+ooo2o+@o.3.+.o.;

Prints abc in Backhand

Errors in ><>

Skipped

8c*0~!/::@1+o2+o3+o;

Prints abc in ><>

Errors in Backhand

Explanation

Backhand doesn't execute the instructions one by one. In the full version, it goes 3, then the v instruction turns it to two steps. In the skipped version, this has the consequence that only the first instruction overlaps with the full version.

When you run the skipped version on Backhand, it divides by zero. Errors in backhand don't stop the program, so I added a stop command, which makes ><> a bit harder. (It's still a command in ><>, just not a good one.)

><>, on the other hand, does not skip instructions. In the full version, a . means jump. Fish is a 2D language, so it pops two arguments. However, only 1 thing was pushed (because of 8). Thus, something smells fishy....

How I get around some of the commands in ><> is simple. When 0 is executed, it pushes 0, then it immediately removes it. Then it skips the next command, which is a mirror. Finally, it duplicates twice, meaning 3 of the same thing is in the stack, which means @, which cycles the top 3 items in the stack, does absolutely nothing.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Hi! Welcome to CGCC! I hope you enjoy your stay! \$\endgroup\$ – Lyxal Jan 20 at 9:27
  • 1
    \$\begingroup\$ An interesting way of doing it, but both ><> and Backhand have the " operator, which should make it a lot easier to push strings. You can do something like this for 29 bytes, though I'm sure that's easily golfable, perhaps by swapping the two languages \$\endgroup\$ – Jo King Jan 21 at 2:45
  • \$\begingroup\$ I only found out about backhand having it after I made this. \$\endgroup\$ – PkmnQ Jan 21 at 4:53
  • \$\begingroup\$ Errors in backhand don't stop the program, uhh, they do though \$\endgroup\$ – Jo King Mar 6 at 0:33
1
\$\begingroup\$

naz / 7, 54 bytes

6a6a5a5m1a5a1a5a1o5s1a5a1o5s1a5a1o0m3a4a1a2a2a7a4a0a3a

This has to be the most esoteric answer I've submitted so far.

Explanation of the full code (works in naz)

6a6a5a5m1a5a1a5a     # Set the register to a value of 97 ("a")
1o                   # Output once
5s1a5a1o             # Output "b"
5s1a5a1o             # Output "c"
0m3a4a1a2a2a7a4a0a3a # Extra arithmetic to allow for a valid 7 program

Fails in 7: 6 command run with no bar in the frame at /opt/7/7.pl line 605, <> chunk 1.

The reduced code (works in 7)

665515151515151510341227403

Try it online!

Fails in naz: error: attempt to chain number literals

I can't give a very accurate explanation of the reduced code due to my relatively poor understanding of 7. I invite anyone who can make sense of it to improve this post.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

GolfScript / MathGolf, 15 bytes

Here is a golfing language one in pure ASCII. (I guess the best score possible is 15 bytes...)

"abc"#; " a b c

Try it online!

GolfScript explanation

"abc"           # Start a string
     #          # Create a comment (rest is a comment)
      ; " a b c

MathGolf explanation

"abc"           Start a string
     #;         Perform expoentiation between the string and the input (implicitly a string)
                This isn't defined yet, so it throws an error
                Discarding the value won't be executed
        " a b c So does this

MathGolf/GolfScript, 8 bytes

"b";"abc

Try it online!

MathGolf Explanation

"b";     # Push b and then discard the value
    "abc # Push abc and then implicitly print

GolfScript explanation

"b";     # Push b and then discard the value
    "abc # Unterminated string, throws an error
|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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