29
\$\begingroup\$

Your task

In your language of choice: create a program that outputs 1

This 1 may either be a string or value equivalent to the number one.

The shifting catch

If you take the unicode codepoint (or whatever codepoint encoding your languages uses if not UTF) for each character in your program, and shift each of those values by the same non-zero amount, then the result will be another program (potentially executable in different language) that also outputs 1.

Find the unicode codepoint of a character: here.

E.g;

If your program looked like: X?$A, and somehow output 1, and it also miraculously outputs 1 after shifting all of it's Unicode indices up by, say, 10; then that process of shifting looks like this:

original program: X?$A

letter    codepoint  shift   new-codepoint   new-letter

X            88       +10        98          b   
 ?           63                  73          I
  $          36                  46          .
   A         65                  75          K

new program: BI.K

Note: The Unicode codepoint will often be represented in the form similar to U+0058. 58 is the hexadecimal codepoint . In decimal, that's 88. The link above will list 88 under the UTF (decimal) encoding section. That is the number you want to increment or decrement!

Examples of valid outputs

1
"1"
'1'
[1]
(1)
1.0
00000001
one

Note: If your language only supports the output of true as an equivalent to 1, that is acceptable. Exit-codes are also valid outputs.

Scoring

  • This is , so lowest bytes wins!
  • Brownie points for creativity & if the two programs are in separate languages.
\$\endgroup\$
17
  • 3
    \$\begingroup\$ What if a language uses a different encoding instead of UTF-8 (i.e. Jelly, 05AB1E, Charcoal, etc.)? Do we still use the unicode codepoints, or the codepoints of the used language? \$\endgroup\$ Commented Jun 12, 2020 at 7:16
  • 3
    \$\begingroup\$ @KevinCruijssen For the sake of making this challenge not impossible, you can use either. \$\endgroup\$
    – Graviton
    Commented Jun 12, 2020 at 7:17
  • 3
    \$\begingroup\$ If two distinct 1-char programs in a language output 1, wouldn't it win the challenge? (or how about a 0-char program?) \$\endgroup\$
    – Bubbler
    Commented Jun 12, 2020 at 7:19
  • 4
    \$\begingroup\$ Can I have a shift of 0? \$\endgroup\$
    – lyxal
    Commented Jun 12, 2020 at 8:21
  • 3
    \$\begingroup\$ @Lyxal A shift of 0 would not satisfy “… then the result will be another program …”, nor would a 0 byte answer. \$\endgroup\$ Commented Jun 12, 2020 at 20:11

44 Answers 44

1
2
2
\$\begingroup\$

TI-BASIC, 2 bytes

not(0
iPart(1

Both display 1. Using one-byte TI-BASIC tokens and their hexadecimal values. not( has a value of 0xB8, iPart( has a value of 0xB9, 0 has a value of 0x30, and 1 has a value of 0x31.


Alternatives (assuming fresh state on calculator):

  • 2 bytes: not(A and e^(H
  • 2 bytes: e^(A and 10^(C
  • 2 bytes: not(A and 10^(J
  • 2 bytes: e^(A and cosh(L
  • 2 bytes: 10^(A and cosh(J
  • 2 bytes: int(1 and 10^(A
  • 2 bytes: int(1 and cosh(J
  • 2 bytes: abs(1 and cosh(I
  • 2 bytes: iPart(1 and cosh(B
  • 2 bytes: not(0 and cosh(B
\$\endgroup\$
1
\$\begingroup\$

Brainetry, 23 bytes

Golfed version (both lines end with a space):

# # # #  
# # # # # # # 

We must shift the #s so they become spaces for the program to work again, so the required shift is -3.

The base program from which I derived the above:

This Brainetry program takes 
no input and prints the codepoint 1. 
\$\endgroup\$
1
\$\begingroup\$

Turing Machine Code, 19 bytes

0 _ 1 r 1
1!'!2!s!2

Try it online!

Nothing too fancy. If the code is shifted by -1, the second line transforms into the code of the first line. The first line transforms into an unexecutable bit of code. The interpreter can, and does, run just fine with unexecutable code dispersed here and there, and so it is just executing the same code either way.

\$\endgroup\$
1
\$\begingroup\$

Perl -M5.010, 13 bytes

Perl 5, 21 bytes

 say 1#BELp^vGS.

BEL = ASCII 'BEL' character, octal byte \0007 GS = ASCII 'GS' character, octal byte \0035

Shifted +3:

#vd|#4&
say 1

Same approach as my R answer, but with slightly (+4 characters) more verbose outputting in Perl -M5.010.
Equivalent Perl 5 program-pair (using print instead of say) is print 1#BELmofkqGS. and, shifted +3, #sulqw#4&LFprint 1.

Test at bash command-line using echo (or gecho):

echo -e ' say 1#\0007p^v\0035.' > prog1.pl
echo -e '#vd|#4&\0012say 1' > prog2.pl
perl -M5.010 prog1.pl
# 1
perl -M5.010 prog2.pl
# 1
\$\endgroup\$
1
\$\begingroup\$

Perl 5 + -M5.10.0, 11 bytes

Uses a shift of 3.

p^v,, say//

Try it online!

say//#vd|22

Try it online!

Explanation

p^v computes the bitwise XOR of p and v then calls say//. // returns 1 because the empty string exists within $_ (which is the empty string).

In the shifted program, say// is called immediately and the rest of the program is commented out.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Really nice that you've managed to avoid non-printable characters. \$\endgroup\$ Commented Jun 15, 2020 at 9:23
  • \$\begingroup\$ Thanks! The a made it more tricky than I'd have liked, print would have been much easier! \$\endgroup\$ Commented Jun 15, 2020 at 10:55
1
\$\begingroup\$

Retina, 1 byte

^

Try it online!

Shifted by 30:

|

Try it online!

\$\endgroup\$
1
\$\begingroup\$

PHP + -d output_buffering=on, 21 bytes

<?=1;#;><*na^bkd`m'(:

Try it online!

Shifted by 1:

=@>2<$<?=+ob_clean();

Try it online!

Using the same technique as my Shifting Oritented Programming answer, it's possible to get all 256 shifts for 5,366 bytes:

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Befunge-93, 7 bytes

Original code:

>1.@B03

Try it online!

Shifted by -2:

</,>@.1

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You don't have to have a separate character for >/< when you can turn the 1 into <, e.g. 1.@5#& shifted by 11 \$\endgroup\$
    – Jo King
    Commented Jul 10, 2020 at 1:40
1
\$\begingroup\$

Stax, 1 bytes

æ

Run and debug it

Stax, 1 bytes

1

Run and debug it

I'm not sure what the offset is, but any two single-character programs can be shifted to each other.

\$\endgroup\$
1
\$\begingroup\$

><> x2, 6 bytes

Uses a shift of 11.

1n;0c&

Puts 1 on the stack, outputs it as a number and stops.

<yF;n1

< makes the direction change and start executing code from the end of the line. Puts 1 on the stack, outputs it as a number and stops.

\$\endgroup\$
2
  • \$\begingroup\$ @JoKing you're right, that's better. Edited, thanks ! \$\endgroup\$
    – Aaron
    Commented Jul 10, 2020 at 13:05
  • \$\begingroup\$ Actually, you can do one byte better by not swapping directions at all and reusing the ; as a 1. 1n;xE shifted by -10 to get 'd1n; \$\endgroup\$
    – Jo King
    Commented Jul 10, 2020 at 13:27
1
\$\begingroup\$

Javastack , 1 byte

1

Vyxal, 1 byte

Vyxal pads the stack with 0s when there's no input, so the list includes but is not limited to...

  • - 0 incremented
  • ċ - 0 != 1
  • - 0 >= 0
  • - 0 <= 0
  • = - 0 == 0
  • ¬ - !0
  • - 0 % 3 == 0
  • - 0 % 2 == 0
  • - 0 % 5 == 0
  • L - len(str(0))
  • - 1 - 0
  • e - 0 ** 0
  • ż, if I can output in a singleton list
\$\endgroup\$
4
  • \$\begingroup\$ Actually, 1 in Vyxal wouldn't be valid for this challenge, because there needs to be a shift of at least 1 in the codepoints of the two programs \$\endgroup\$
    – lyxal
    Commented Aug 8, 2021 at 3:22
  • \$\begingroup\$ @exedraj Oh true \$\endgroup\$
    – emanresu A
    Commented Aug 8, 2021 at 4:04
  • \$\begingroup\$ @pxeger Any of the chars in the Vyxal list \$\endgroup\$
    – emanresu A
    Commented Aug 8, 2021 at 20:01
  • \$\begingroup\$ Oh I missed that it could be a different langauge \$\endgroup\$
    – pxeger
    Commented Aug 8, 2021 at 20:01
1
\$\begingroup\$

TypeScript's type system, 8 bytes

type F=1

Vyxal 2, 8 bytes

‹←↓u0VMA

Try it Online!

Each character is offset by +16 in Vyxal 2's codepage.

The TypeScript program actually outputs 1 in Vyxal as well, but the shift must be nonzero.

The TypeScript type system program was very easy to write. I found the Vyxal program using this code, changing the offset by 1 and rerunning until I found a working program.

The first 6 characters of the Vyxal program do nothing particularly logical, but end up with 0 on the stack (which is quite common for random characters with no particular meaning). M tries to map over a list by a function, but with no list or function given, it just outputs an empty list. A checks if all items in the list are truthy, which for an empty list returns 1.

\$\endgroup\$
0
\$\begingroup\$

Same code for javascript and brainfuck (shifted 0)

JavaScript (V8), 152 bytes

+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[1.>>0]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

Try it online!

brainfuck, 152 bytes

+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[1.>>0]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ For which non-zero codepoint shift does it output 1? \$\endgroup\$
    – ouflak
    Commented Jun 15, 2020 at 15:46
  • 2
    \$\begingroup\$ Shift must be non-zero :/ \$\endgroup\$
    – Graviton
    Commented Jul 9, 2020 at 23:14
  • \$\begingroup\$ If it's shifted zero then it's just a polyglot \$\endgroup\$
    – Jo King
    Commented Jul 10, 2020 at 1:48
0
\$\begingroup\$

Text, 1 byte

1

①

Ⅰ

If one is valid then there's no reason and aren't

\$\endgroup\$
1
  • \$\begingroup\$ Add other expressions of 1 in one character here \$\endgroup\$
    – l4m2
    Commented Jan 3 at 6:58
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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