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

35
\$\begingroup\$

Java, 62 bytes

interface M{static void main(String[]a){System.out.print(1);}}

Try it online.

05AB1E, 62 bytes

\agXeYTVXι@nfgTg\Vιib\Wι`T\a₂Fge\aZNPT₃nFlfgX`!bhg!ce\ag₂$₃.pp

Uses the 05AB1E encoding, with the codepoints all decreased by 13:

  • interface M{static void main(String[]a){System.out.print(1);}} has the codepoints [105,110,116,101,114,102,97,99,101,32,77,123,115,116,97,116,105,99,32,118,111,105,100,32,109,97,105,110,40,83,116,114,105,110,103,91,93,97,41,123,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,49,41,59,125,125]
  • \agXeYTVXι@nfgTg\Vιib\Wι`T\a₂Fge\aZNPT₃nFlfgX`!bhg!ce\ag₂$₃.pp has the codepoints [92,97,103,88,101,89,84,86,88,19,64,110,102,103,84,103,92,86,19,105,98,92,87,19,96,84,92,97,27,70,103,101,92,97,90,78,80,84,28,110,70,108,102,103,88,96,33,98,104,103,33,99,101,92,97,103,27,36,28,46,112,112].

Try it online.

Explanation:

Java:

interface M{                   // Full program:
  static void main(String[]a){ //  Mandatory main-method:
    System.out.print(          //   Print without trailing newline:
      1);}}                    //    Print 1

05AB1E:

\                  # Discard the top of the stack (no-op, since it's already empty)
                   #  STACK: []
 a                 # Check if it only consists of letters (resulting in falsey/0
                   # for an empty string "", which is used implicitly without input)
                   #  STACK: [0]
  g                # Push and push its length, which is 1
                   #  STACK: [1]
   X               # Push variable `X`, which is 1 by default
                   #  STACK: [1,1]
    e              # Push the number of permutations n!/(n-r)! with both 1s, which is 1
                   #  STACK: [1]
     Y             # Push variable `Y`, which is 2 by default
                   #  STACK: [1,2]
      T            # Push builtin 10
                   #  STACK: [1,2,10]
       V           # Pop and store it in variable `Y`
                   #  STACK: [1,2]
        X          # Push variable `X` again, which is 1 by default
                   #  STACK: [1,2,1]
         ι         # Uninterleave using the 2 and 1, resulting in ["2"]
                   #  STACK: [1,["2"]]
          @        # Check whether 1 is >= ["2"], resulting in [0]
                   #  STACK: [[0]]
           n       # Square it
                   #  STACK: [[0]]
            f      # Get a list of all prime factors (none for 0), which results in []
                   #  STACK: [[[]]]
             g     # Pop and push its length
                   #  STACK: [1]
              T    # Push builtin 10
                   #  STACK: [1,10]
               g   # Pop and push its length
                   #  STACK: [1,2]
                \  # Discard it
                   #  STACK: [1]
                 V # Pop and store it in variable `Y`
                   #  STACK: []

From here on out I can't really explain it anymore, since it does things I wasn't expecting:

ι                  # Uninterleave (would take either one or two arguments, but since the
                   # stack is empty, it somehow remembered the 1 that was previously on
                   # the stack and results in ["1"] - 
                   # A program `ι` without input would result in an error instead..)
                   #  STACK: [["1"]]
 i                 # If-statement, which will be entered if the top is 1;
                   # since it's ["1"] instead of 1, it won't enter
                   #  STACK: []
  b\Wι`T\a₂Fge\aZNPT₃nFlfgX`!bhg!ce\ag₂$₃.pp
                   #  No-ops within the if-statement
                   # It again somehow remembers the previous ["1"] that was on the stack,
                   # which is output implicitly as result
\$\endgroup\$
3
  • 3
    \$\begingroup\$ Ok, nevermind, the perl one didn't take the most effort, this did. \$\endgroup\$
    – PkmnQ
    Commented Jun 12, 2020 at 10:40
  • 2
    \$\begingroup\$ @PkmnQ Tbh, it wasn't that much effort. :) I simply created the Java program, and then first used this program to check all possible variations of decreasing codepoints using ASCII encoding (which weren't very useful), and then I used this program to check all possible variations of decreasing codepoints using 05AB1E's encoding, for which this -13 resulted conveniently in ["1"]. Writing the explanation above took more effort to be completely honest. ;) \$\endgroup\$ Commented Jun 12, 2020 at 11:57
  • 1
    \$\begingroup\$ And if none of those would have worked, I could have changed the class-name M to something more convenient to try and make it output 1. \$\endgroup\$ Commented Jun 12, 2020 at 12:02
32
\$\begingroup\$

05AB1E, 3 bytes

1*1

(Works in Japt too.)

Try it online!

Japt, 3 bytes

6/6

Try it online!

Derived from the 05AB1E program by shifting by 5 Unicode codepoints.

The Japt program performs division, but don't be fooled into thinking that the 05AB1E program is performing multiplication. The * (square) operator acts only on the first 1; the output is actually just an implicit print of the second 1.

The same idea works with the 05AB1E/Japt program pairs 1-1 and 3/3 (shift 2) and 1+1 and 5/5 (shift 4).

\$\endgroup\$
4
  • 6
    \$\begingroup\$ It can indeed be done in 1 byte, but I like your approach more. :) Maybe this challenge should have been code-bowling instead of code-golf, since that's much more impressive imo. \$\endgroup\$ Commented Jun 12, 2020 at 7:46
  • 1
    \$\begingroup\$ @KevinCruijssen Thanks. I agree it's not particularly impressive, especially since it was a complete stab in the dark - it just happened to work in the first two languages I picked! Very lucky choice :) \$\endgroup\$
    – Dingus
    Commented Jun 12, 2020 at 7:55
  • 2
    \$\begingroup\$ @KevinCruijssen Code bowling will quickly break with two programs of arbitrary length, each being a repetition of single built-in. \$\endgroup\$
    – Bubbler
    Commented Jun 12, 2020 at 7:59
  • 1
    \$\begingroup\$ @Bubbler Good point. Creating a good code-bowling challenge is also pretty hard to begin with, since there are so many edge-cases you have to keep in mind. \$\endgroup\$ Commented Jun 12, 2020 at 8:03
19
\$\begingroup\$

Python 3, 19 17 bytes

-2 bytes thanks to Jonathan Allan

#]pal )!␛
exit(1)

Try it online!

Shifted +8

+exit(1)#␒m␣q|091

Try it online!

where ␛, ␒ and ␣ are literal \x1b, \x12 and \x80 bytes respectively.

Not much by the way of trickery going on here except prepending the print in the shift version with a + so that when we shift it the first character of the second program to the # character it doesn't send any characters into a negative codepoint (if we naïvely shifted e back to #, ( would be sent to \x- which doesn't exist). Outputs by exit code.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ If you output via exit code you save 2 bytes: +exit(1)#□m□q|091. \$\endgroup\$ Commented Jun 12, 2020 at 22:20
  • \$\begingroup\$ @JonathanAllan Thanks! Avoids the error too because you exit first - nice. \$\endgroup\$
    – boboquack
    Commented Jun 13, 2020 at 6:53
16
\$\begingroup\$

05AB1E, 2x 1 byte

Without an input, any of these single characters will output 1, so just pick two you like. :)

  • 1 (self explanatory): Try it online.
  • X (variable, which is 1 by default): Try it online.
  • (!= 1 check; without input it will do "" != 1, resulting in truthy/1): Try it online.
  • @ (>= check; without input it will do "" >= "", resulting in truthy/1): Try it online.
  • Q (== check; without input it will do "" == "", resulting in truthy/1): Try it online.
\$\endgroup\$
13
\$\begingroup\$

APL (Dyalog Unicode), 2x2 bytes

*0
+1

Try it online!

*0 computes e^0, and +1 computes complex conjugate of 1. *0 has Unicode codepoint 42 and 48, and +1 has 43 and 49, so the two are different by exactly one.

Also works in many different flavors of APL, including... (copied from Adám's APL bounty)

Dyalog APL Classic/Unicode/Extended/Prime, APL2, APL+, APLSE, GNU/APL, Sharp APL, sAPL, SAX, NARS, APLX, A+, dzaima/APL, ngn/APL, APL\iv, Watcom APL, or APL\360.

... which makes this a polyglot of at least 19 languages!

\$\endgroup\$
3
  • \$\begingroup\$ A whole lot more languages. \$\endgroup\$
    – Adám
    Commented Jun 12, 2020 at 8:19
  • \$\begingroup\$ That's beautiful. \$\endgroup\$
    – David
    Commented Jun 12, 2020 at 20:50
  • \$\begingroup\$ Also works in Jelly \$\endgroup\$ Commented Aug 8, 2021 at 3:11
12
\$\begingroup\$

Unary, 84 bytes

000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Outputs the character with codepoint 1 (equivalent brainfuck: +.). Since Unary cares only about the length of the program, a shift of any number will not change the output.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This comes very close to violating a standard loophole:Using a language's lack of features to trivialize a challenge \$\endgroup\$
    – Brian
    Commented Jun 12, 2020 at 18:39
  • 7
    \$\begingroup\$ @Brian I wouldn't call "cares only about the length of the program" a lack of features: a Unary program can do anything a Brainfuck program can do (and Brainfuck is a Turing complete language), even though the Unary program is usually long enough its length has to be expressed in scientific notation. \$\endgroup\$ Commented Jun 12, 2020 at 19:37
  • \$\begingroup\$ I do appreciate that other users are making an effort to check the validity of my answer, though. \$\endgroup\$ Commented Jun 14, 2020 at 0:48
12
\$\begingroup\$

HTML, 8 bytes

<ol><li>


05AB1E, 8 bytes

!TQ#!QN#

Try it online!


Jelly, 8 bytes

([X*(XU*

Try it online!


Jelly, 8 bytes

5he75eb7

Try it online!


Jelly, 8 bytes

;nk=;kh=

Try it online!


05AB1E, 8 bytes

@spB@pmB

Try it online!


Jelly, 8 bytes

H{xJHxuJ

Try it online!


05AB1E, 8 bytes

Outputs ["1"].

Q„SQ~S

Try it online!


05AB1E, 8 bytes

V‰†XV†ƒX

Try it online!


05AB1E, 8 bytes

X‹ˆZXˆ…Z

Try it online!


05AB1E, 8 bytes

]_]Š_

Try it online!


05AB1E, 8 bytes

a”‘ca‘Žc

Try it online!


05AB1E, 8 bytes

e˜•ge•’g

Try it online!


05AB1E, 8 bytes

kž›mk›˜m

Try it online!


("Pffffft! Of course I know how 05AB1E and Jelly work! I totally didn't just brute-force a bunch of combinations on TIO. That would be crazy! It would never work!")

\$\endgroup\$
1
  • \$\begingroup\$ So many! You deserve to be accepted as the best answer. Unfortunately, I'm not the one who made this question \$\endgroup\$
    – PkmnQ
    Commented Jul 10, 2020 at 6:57
9
\$\begingroup\$

CSS, 48 bytes

body:after{content:"1"}z|ancx9`esdqzbnmsdms9!0!|

cpez;bgufs|dpoufou;#2#~{}body:after{content:"1"}

\$\endgroup\$
1
  • 3
    \$\begingroup\$ The second code is not even close to valid CSS, but CSS parsers are so lax it works. Wow. \$\endgroup\$
    – D. Pardal
    Commented Jun 12, 2020 at 21:30
8
\$\begingroup\$

!@#$%^&*()_+, 4 bytes

1@/>

Try it online!

Explanation

1    # Pushes 1
 @   # Prints top of the stack (1)
  /> # Pushes some meaningless stuff

Shifted +2

3B1@

Try it online!

Explanation

3B   # Pushes some meaningless stuff
  1  # Pushes 1
   @ # Prints top of the stack (1)
\$\endgroup\$
7
\$\begingroup\$

Pyth, 2 bytes

s1

Try it online!

Pyth, 2 bytes, Shifted +1

t2

Try it online!


First Program translates to floor(1)
Second Program translates to 2 - 1

\$\endgroup\$
7
\$\begingroup\$

Whitespace, 2 x 18 bytes

" " " ␋ ␌
␋   ␌
" ␋ 

Try it online..

All codepoints decreased by 2 will result in:

 ␟ ␟ ␟  ␇
␈   ␇
␈ ␟ ␇

Try it online.

Both programs contain unprintables. The first program contains characters with the codepoints: [34,32,34,32,34,32,11,9,12,10,11,9,12,10,34,32,11,9]. The second program with codepoints: [32,30,32,30,32,30,9,7,10,8,9,7,10,8,32,30,9,7]. In Whitespace, all characters except for spaces (codepoint 32), tabs (codepoint 9), and newlines (codepoint 10) are ignored, so both programs are actually the following:

SSSTN
TN
ST

Where S, T, and N are spaces, tabs, and newlines respectively.

This program will:

  • SSSTN: Push 1
  • TNST: Print it as integer to STDOUT

It's actually possible to create 3 x 27 bytes, 4 x 36 bytes, and even 5 x 45 bytes programs by having the codepoints apart by 2, still resulting in the same basic program above after all non-whitespace characters are ignored.

\$\endgroup\$
3
  • \$\begingroup\$ Does anyone know how to display unprintables in a stackexchange answer? IIRC I've seen it in an answer here on codegolf once before, but I have no idea what markup to use to accomplish it anymore. \$\endgroup\$ Commented Jun 12, 2020 at 8:15
  • 2
    \$\begingroup\$ We used the characters from the Control Pictures block in Add a language to a polyglot to represent ESC, formfeed and vertical tab. Including a hexdump is probably the better option. \$\endgroup\$
    – Potato44
    Commented Jun 12, 2020 at 13:16
  • \$\begingroup\$ @Potato44 Thanks. Added the unicode unprintable characters to my answer. :) \$\endgroup\$ Commented Jun 14, 2020 at 14:13
7
\$\begingroup\$

J, 3 2 bytes

=0

Monadic = means self-classify. It compares each item with each other item to see if it's the same. 0 is 0. It returns 1.

Shifted +1

>1

Unboxes 1, which does nothing, because it wasn't in a box in the first place.

Alternate 2-byters:

!1 (1 factorial) shifted by 2 is #3 (amount of items in 3)

!0 (0 factorial) shifted by 2 is #2 (amount of items in 2) shifted by 7 is *9 (sign of 9)

\$\endgroup\$
5
  • \$\begingroup\$ 2 bytes: !1#3 \$\endgroup\$
    – Adám
    Commented Jun 12, 2020 at 8:23
  • \$\begingroup\$ Also !0*9 \$\endgroup\$
    – Adám
    Commented Jun 12, 2020 at 8:26
  • \$\begingroup\$ @Adám Didn't see your comments while editing. I'll add those as alternate 2-byters. \$\endgroup\$
    – PkmnQ
    Commented Jun 12, 2020 at 8:27
  • \$\begingroup\$ 3 programs with !0 -> #2 -> *9 \$\endgroup\$
    – xash
    Commented Jun 14, 2020 at 22:24
  • \$\begingroup\$ That also means #1 and *8, and #0 and *7 are also valid pairs. \$\endgroup\$
    – PkmnQ
    Commented Jun 16, 2020 at 8:35
7
\$\begingroup\$

JavaScript (web), 19 bytes

Form #1

`kdqs_0_:`;alert`1`

Form #2 (#1 shifted by +1)

alert`1`;a<bmfsua2a

This took me longer than what I'd like to admit, but it was a fun challenge. 😁

Form #2 throws a ReferenceError, but that seems to be allowed.

\$\endgroup\$
6
\$\begingroup\$

brainfuck, 3 bytes

Outputs the character with the codepoint 1. This is allowed by default.

(+.

Try it online!

Shifted +3

+.1

Try it online!

Explanation

The + character increments the current item of the tape, and . outputs that value as a character. All other characters are ignored.

\$\endgroup\$
6
\$\begingroup\$

Polyglot, 3 bytes

Shift of 2. Works in R, Octave, Japt, and probably others.

1+0
3-2

Try it online (Octave)

Try it online (R)

Try it online (Japt)

\$\endgroup\$
5
\$\begingroup\$

Japt, 1 byte

Among many others:

1

Test it

Ä

Test it

l

Test it

\$\endgroup\$
5
\$\begingroup\$

R, 4 bytes

\061\043\030\077

(octal bytes, equivalent to: '1' '#' CAN '?')

Shifted -14:

\043\025\012\061

(octal bytes, equivalent to '#' NAK LF '1')

Unshifted program consists of number 1 (which is outputted unchanged), followed by # (comment character) and 'comments' of CAN (ASCII code \030) and '?'.

Shifted +14 program consists of # (comment character) and 'comment' of NAK (ASCII code \025), followed by a new line. On the next line is the number 1 (which is outputted unchanged).

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

echo -e '\061\043\030\077' >prog1.r
echo -e '\043\025\012\061' >prog2.r
Rscript prog1.r
# [1] 1
Rscript prog2.r
# [1] 1
\$\endgroup\$
4
\$\begingroup\$

naz, 4 bytes

1a1o

Explanation

1a # Add 1 to the register
1o # Output once

05AB1E, 4 bytes

2b2p

A shift of 1 Unicode codepoint forward from the original.

Explanation

2    # Push 2
 b   # Convert to binary
  2  # Push 2
   p # Push isPrime(2)
# ...after which the result is output implicitly
\$\endgroup\$
4
\$\begingroup\$

Jelly, 1 byte

¬ (logical NOT) vs (increment)

Try ¬ online! or Try online!

This works because given no input a Jelly program has a default argument of 0.

There are \$\binom{21}{2}=210\$ different pairs of single-byte programs to choose from since there are \$21\$ single bytes on Jelly's code-page which yield 1 with no input:

\$\endgroup\$
4
\$\begingroup\$

Io, 6 bytes

1print

Try it online!

Commentator, (Shifted -17)

 _aX]c

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ ...I'm interested in learning commentator now. \$\endgroup\$
    – PkmnQ
    Commented Jun 12, 2020 at 10:34
3
\$\begingroup\$

Keg, 1 byte (SBCS)

1

Try it online!

Implicitly outputs 1

Shifted +198

🄂

Try it online!

Uses the push'n'print to print 1

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

Batch, 27 17 bytes

:_]bi�+�4
@echo 1

The : introduces a label of unprintables, so the line is ignored, and the second line prints 1. Shifted by 6:

@echo 1
:�Fkinu&7

Much the same, except this time the second line is ignored.

Unfortunately I've mangled the unprintables. Sorry about that. Feel free to fix it.

\$\endgroup\$
1
  • \$\begingroup\$ Was waiting for a batch one to come around! Well done. \$\endgroup\$
    – Graviton
    Commented Jun 13, 2020 at 6:15
3
\$\begingroup\$

;#+, 4 bytes

9n;p

Try it online!

;#+, 4 bytes, Shift +2

;p=r

Try it online!


Explanation

; - increments the counter
p - outputs the counter as a number

9, n, = and r are not commands in ;#+ so they can be ignored.

\$\endgroup\$
2
\$\begingroup\$

V (vim), 6 bytes

i1<esc><nul>h0
\$\endgroup\$
2
\$\begingroup\$

bc (?), 3 bytes

1+0

Shift 2:

3-2

Use as echo 1+0 | bc in bash.

\$\endgroup\$
2
\$\begingroup\$

pdfTeX -halt-on-error, 1 byte

_

and

^

Both versions will throw an error as _ and ^ are only allowed in math-mode. Will return a 1 as exit code (due to the error).

\$\endgroup\$
2
\$\begingroup\$

Perl 5 -p, 8 bytes + 1 byte/keypress input = 9 bytes

Edit: -2 bytes and much nicer printable programs thanks to Dom Hastings

Each program requires input of 1 byte, or a single carriage-return keypress. I've counted this as +1 byte, but I'm not terribly sure how valid this is...

$_++#^**

Try it online!

Shifted +1:

%`,,$_++

Try it online!

One might (validly) argue that since the extra input/keypress is part of the byte-count, it should also be shifted along with the codepoints of the program. Fortunately, there are inputs for which this works Ok:

echo 'a' | perl -pe '$_++#^**'
# 1
echo 'b' | perl -pe '%`,,$_++'
# 1
\$\endgroup\$
3
  • \$\begingroup\$ Nice, I did look into this, but wasn't sure about input being valid either... If it is, you can use a shift of 1 (again, lets avoid unprintables :P) for these two: tio.run/##K0gtyjH9/18lXltbOU5L6/9/rn/5BSWZ@XnF/3ULAA tio.run/##K0gtyjH9/181QUdHJV5b@/9/rn/5BSWZ@XnF/3ULAA \$\endgroup\$ Commented Jun 15, 2020 at 12:58
  • 1
    \$\begingroup\$ Those versions are a big improvement! I'm very ashamed that I didn't find that solution, which is much nicer (especially for the printability). Will update answer with acknowledgement, while anyway cautiously waiting to see whether there's any consensus about (non-) validity... \$\endgroup\$ Commented Jun 15, 2020 at 13:10
  • \$\begingroup\$ No problem! I'm sure there was a consensus about this a while ago, but I couldn't find the right meta post... Perl's syntax is frighteningly forgiving, `` $` `` is probably a syntax error in more utility languages than it's not! I'm enjoying this challenge... \$\endgroup\$ Commented Jun 15, 2020 at 13:25
2
\$\begingroup\$

JavaScript, 3

3-2 becomes 2,1 shifted by -1.
1+0 becomes 2,1 shifted by +1.

Which is cool because 1+0 shifted by one becomes 2,1 shifted by one becomes 3-2 all three produce 1


let code = '1+0';
console.log (code, eval(code));
code = code.split('').map(c => String.fromCharCode(c.charCodeAt(0) + 1)).join('');
console.log (code, eval(code));
code = code.split('').map(c => String.fromCharCode(c.charCodeAt(0) + 1)).join('');
console.log (code, eval(code));

\$\endgroup\$
3
  • \$\begingroup\$ Would this work, and be the same size, for any sngle digit integers (a,b) where a=b+1? \$\endgroup\$
    – ouflak
    Commented Jun 15, 2020 at 15:43
  • 1
    \$\begingroup\$ @ouflak No, because in the case of 2,1 the expression evaluates to the second value, which has to be one. It only works with 0 and 2. \$\endgroup\$
    – C5H8NNaO4
    Commented Jun 15, 2020 at 18:22
  • \$\begingroup\$ This isn't actually outputting anything though. Are you sure you don't mean a Javascript REPL rather than actual Javascript? \$\endgroup\$
    – Jo King
    Commented Jul 10, 2020 at 1:42
2
\$\begingroup\$

CJam, 1 byte

1
X

For whatever reason, CJam has X as a builtin for 1, and since it outputs implicitly, you can just use those two. However, I thought it'd be more interesting to find a 2-byte solution.

XR

Try it online!

Offset by +38:

2,

Try it online!

Explanations:

X    Push 1 to the stack
 R   Push an empty array to the stack
     (implicit) Output the stack
2    Push 2 to the stack
 ,   Pop and push range from 0 to 1 less than the popped number
     (implicit) Output the stack

Note that this is not only my first time golfing, but also my first time coding a program (well, programs) in CJam, so let me know how I did!

\$\endgroup\$
2
\$\begingroup\$

Hexagony, 5 bytes

=-1!@

Try it online!

Hexagony, 5 bytes, Shifted -12

1!%4

Hexdump:

00000000  31 21 25 15 34     |1!%.4|

Try it online!

Explanation

Because of the small size and lack of mirrors, the programs are mostly executed linearly.

Non-shifted Program

=       Reverse direction of memory pointer
 -      Sets the current memory edge to the difference of the left and right neighbors (0 - 0 = 0)
  1     Multiply current memory edge by 10 then add 1 (0 * 10 + 1 = 1)
   !    Outputs the value of current memory edge to stdout as an integer
    @   Terminate the program

Shifted Program

1       Multiply current memory edge by 10 then add 1 (0 * 10 + 1 = 1)
 !      Outputs the value of current memory edge to stdout as an integer
  %     Sets the current memory edge to the modulo of the left and right neighbours
        (1 % 0) causes program to exit because of division by 0
    4   Does not matter since the program as already exited
\$\endgroup\$
0

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.