58
\$\begingroup\$

As is well known,

Chuck Norris counted to infinity. Twice

Besides,

Chuck Norris can count to infinity backwards.

Also, although perhaps less known, Chuck Norris can speak a little Spanish in addition to English.

The challenge

Write a program (or function) that can be run in two different languages. In one language the program should output the sequence

1, 1, 2, 2, 3, 3, 4, 4, ...

and in the other language it should produce the sequence (including leading zeros)

1, 2, ..., 9, 01, 11, 21, 31, ..., 89, 99, 001, 101, 201, ...

Rules

  • Programs or functions are allowed, in any programming language. Standard loopholes are forbidden.
  • Different versions of the same language (such as Python 2/3) don't count as different languages. Related languages (such as C/C++ or Matlab/Octave) do count as different.
  • No input will be taken.
  • The program should continue to output terms of the sequence until stopped by the user. Since the program will not stop by itself, output cannot be produced at the end. It must be produced while the program runs, either continuously or in batches.
  • Output can use STDOUT or equivalent, or can be displayed in a graphic window. Any non-numeric separator between sequence terms is allowed, as long as each term can be clearly distinguished from its neighbouring terms. It is also acceptable if the screen is cleared between terms.
  • Either sequence can start at 0 instead of 1. In that case, in the "twice" sequence the 0 should be repeated, just like the other numbers.
  • Leading zeros are significant in the "backwards" sequence. For example, the tenth term is 01; neither 1 nor 001 are acceptable.
  • If the two languages use different character encodings, the program is defined by its bytes, not its characters. That is, the bytes should be the same in the two languages.
  • Shortest code in bytes wins.
\$\endgroup\$
  • 8
    \$\begingroup\$ Downvoters, any suggestion for improvement? \$\endgroup\$ – Luis Mendo Jun 16 '17 at 21:10
  • 29
    \$\begingroup\$ Chuck Norris is too powerful to count, if he did, the first number he'd count would exceed infinity and shatter the realm of known mathematics. Therefore, I refuse to compete. \$\endgroup\$ – Magic Octopus Urn Jun 16 '17 at 21:55
  • 11
    \$\begingroup\$ @carusocomputing, very wise given the world-wide shortage of push-ups since Chuck Norris did them all. \$\endgroup\$ – Wossname Jun 16 '17 at 22:17
  • 33
    \$\begingroup\$ Chuck Norris can complete this challenge in 0 bytes. He can just look at the computer and the computer does whatever he wants. \$\endgroup\$ – Kodos Johnson Jun 17 '17 at 0:47
  • 17
    \$\begingroup\$ Chuck Norris didn't try to win this challenge, he just allowed you to lose. \$\endgroup\$ – Nat Jun 17 '17 at 13:10

18 Answers 18

18
\$\begingroup\$

05AB1E / Jelly,  14  13 bytes

-1 byte thanks to Adnan (avoid triplicate with non-popping print)

Raw bytes (hexadecimal):

31 5b 3d 3d 3e 5d fc 06 b6 3b 87 08 15

In 05AB1E's code-page:

1[==>]üε¶;‡ηΩ

Try it online!

In Jelly's code-page:

1[==>]‘©Ṛ;⁷®ß

Try it online!

How?

The 05AB1E program prints the double count with each entry separated by newlines:

1[==>]üε¶;‡ηΩ
1             - push 1 onto the stack
 [            - start infinite loop:
  =           - print top of stack
   =          - print top of stack
    >         -   increment the top of the stack (pop(1), x+=1, push)
     ]        - end the infinite loop
      üε¶;‡ηΩ - this code is never executed nor is it parsed

The Jelly program prints the reversed count with each entry separated by newlines.

The parser will treat a valid literal between [ and ] as the enclosed literal, otherwise these bytes are undefined tokens and as such become equivalent to tokens separating the code into lines. ==> does not parse as a literal, so the code is effectively:

1 - link 1 (not executed but parsed)
1 - literal 1

==> - link 2 (not executed but parsed)
=   - left equals right? (vectorises)
 =  - left equals right? (vectorises)
  > - is greater than the right argument? (vectorises)

‘©Ṛ;⁷®ß - Main link: no arguments
‘       - increment (implicit 0 on left increments to 1 on the first pass)
 ©      - copy the result to the register and yield it
  Ṛ     - reverse, this has an implicit decimal list build, e.g. 142 -> [2,4,1]
    ⁷   - a newline character
   ;    - concatenate, e.g. [2,4,1] -> [2,4,1,'\n']
     ®  - recall the number from the register, e.g. 142
        - The chain has reduced to one item of arity 0, causing a pre-evaluation print:
        -     ...and since the list contains a character it gets smashed together
        -     e.g. [2,4,1,'\n'] prints 241 followed by a newline character
      ß - call this link with the same arity, e.g. as a monad with left = 142
\$\endgroup\$
  • \$\begingroup\$ I haven't checked if it works for Jelly, but if it does work, you can replace Ð,, by ==. \$\endgroup\$ – Adnan Jun 18 '17 at 21:13
  • \$\begingroup\$ That should parse in Jelly. I had looked in info.txt for a non-popping print, and did not see that. Thanks. \$\endgroup\$ – Jonathan Allan Jun 18 '17 at 21:18
26
\$\begingroup\$

Python 2/C (clang), 109 107 100 84 95 88 89 88 87 84 bytes

i=0;
#/*
while 1:i+=1L;print`i`[::-1]
'''*/
a(){for(;;)printf("%i %1$i ",++i);}//'''

Python: Try it online!

C: Try it online!

The L in the Python code is part of the delimiter.

Explanation:

In the C code, It first sets i to 0. Then, it starts a comment (# is valid code in C for #include statements) where the Python code goes. At the end of the comment, it defines a function that forever increments a variable and prints it twice, space-delimited. It then begins a comment.

In the Python code, i=0; sets i to zero. Python ignores the next line because # starts a single-line comment. It then forever increments it and turns it into a long a number and prints its reversed string representation. The 'L' from the long is part of the delimiter. After that, it starts a multi-line string to comment the C code, that ends later.

 

-2 bytes thanks to @LuisMendo. -7 bytes thanks to @ZacharyT. -6 more bytes thanks to @ZacharyT. +11 bytes to fix a bug thanks to @mbomb007. -7 bytes thanks to @Doorknob. +1 byte to fix a bug thanks to @Doorknob. -1 byte thanks to @yoann. -1 more byte thanks to @yoann. -3 bytes thanks to @Cyoce.

\$\endgroup\$
  • \$\begingroup\$ Hmm, I think that you could use recursion in C code - a(i){printf("%i %i ",i,i);a(i+1)} \$\endgroup\$ – enedil Jun 16 '17 at 23:43
  • \$\begingroup\$ Why not to use while loop for C code? \$\endgroup\$ – enedil Jun 17 '17 at 17:36
  • \$\begingroup\$ @enedil It takes more bytes. \$\endgroup\$ – Comrade SparklePony Jun 17 '17 at 20:21
  • \$\begingroup\$ I think you can use `i` instead of str(i) \$\endgroup\$ – Cyoce Jun 18 '17 at 8:02
  • \$\begingroup\$ You can use for(;;)printf("%i %1$i ",i++); to save one byte. The 1$ is a positional argument that tells printf to display the first argument (after the format string). \$\endgroup\$ – yoann Jun 18 '17 at 11:09
12
\$\begingroup\$

Jelly/Pyth, 15 bytes

.V1_`b;"1üÉÉ$

Unprintables are mangled by the SE software, so here's a hexdump:

00000000: 2e56 315f 6062 3b22 7f31 fcc9 c924 0b    .V1_`b;".1...$.

Run with jelly f file and pyth file respectively.

Explanation

First comes the Pyth part. .V runs an infinite loop over the incrementing sequence starting from its input, which is here 1. Then we reverse (_) the stringified (`) loop index (b) and implicitly output it. The ; is there to end the loop, and the " is necessary to treat the rest of the program as a string literal so that the parser doesn't choke on it.

The Jelly part will be explained by first translating the remainder of the program from the Jelly codepage:

¶1‘ṄṄ$¿

The acts as a line feed, effectively ignoring the first part of the program by making it a link that is never called. Then we start at 1 and run a while loop (¿) that uses ṄṄ$ (print twice) as its condition, and increments () the value as the loop body.


Incidentally, replacing the Pyth part with 1[DR,>] would create a valid Jelly/05AB1E submission in 14 bytes, but the current interpeter contains a bug that prevents this.

\$\endgroup\$
  • 1
    \$\begingroup\$ @JonathanAllan You're right, that was the trailing newline added by my text editor. \$\endgroup\$ – Doorknob Jun 18 '17 at 21:10
11
\$\begingroup\$

Perl/JavaScript, 87 bytes

s=0;print=console.log;m=s;$_=s=s=s=m;while(++$_){print((m/s,$_+`
`+$_||/&&reverse.$/))}

Perl

s/0;print/console.log;m/s;$_=s/s/s/m;while(++$_){print((/s,$_+`
`+$_||/&&reverse.$/))}

A mechanism I've used a lot in JS/Perl polyglots is to abuse the fact that substitution can accept pretty much any delimiter, using = means I can use the initial pointless substitutions (first replacing 0;print with console.log;m with a flag of /s in $_, which is currently undef), then setting $_ to the result of replacing s with s in multiline mode (/m), which is 0. Now $_ is 0 and I start the while loop, this then increments $_. Next I call print, passing in a regular expression that matches (due to || at the end which matches an empty string) and use the && operator to then send the reverse of $_ concatenated with a newline ($/ is pre-initialised to "\n"). This counts to infinity backwards.

JavaScript

s=0;print=console.log;m=s;$_=s=s=s=m;while(++$_){print((m/s,$_+`
`+$_||/&&reverse.$/))}

Lots of variable assignments here, masked in the Perl s/// calls. I set up variables s and m as 0, alias console.log to print, run some pointless division, set $_ to 0 and begin the while loop incrementing $_, call print passing in 0 (m/s, this starts the call to m in Perl, but is treated as standard division in JS) and our target string ($_+"\n"+$_) via the comma operator, which returns the last item in the list. I avoid the last piece of Perl code (&&reverse.$/) because $_+"\n"+$_ will be truthy and so I can use || to produce a RegExp object containing the end of the Perl code which is never evaluated.

Tested using Perl 5 and Node 6.

\$\endgroup\$
8
\$\begingroup\$

NodeJS / PHP, 131 106 bytes

-25 bytes thanks to @Titus

<!--
printf=(_,i)=>process.stdout.write(i+i),strrev=i=>i+" "//--><?
for($i=0;;)printf("%s ",strrev($i++));

Using NodeJS instead of browser JS for better output formatting and better infinite loop handling.

Try the JavaScript online
Try the PHP online

Note that the TIO output is cut off after 128KB.

\$\endgroup\$
  • 1
    \$\begingroup\$ 102 bytes starting at 0: <!--←printf=(_,i)=>process.stdout.write(i),strrev=i=i>>1//--><?←for($i=0;;)printf("%s ",strrev($i++));. 84 bytes (but not half as nice as your approach): <!--←for(i=1;;)process.stdout.write(i+" "+i+++" ")//--><?for(;;)echo strrev(++$i),_; or <!--←for(i=1;;)process.stdout.write((++i>>1)++" ")//--><?for(;;)echo strrev(++$i),_;. \$\endgroup\$ – Titus Jun 17 '17 at 9:53
  • \$\begingroup\$ @Titus Nice idea with the i>>1 to repeat the number, but I had to change the write(i) to include a space, and because write() doesn't accept a number. And you had a typo (strrev=i=i>>1 -> strrev=i=>i>>1) that added another byte. Ended up being shorter to do write(i+i) and strrev=i=>i+" ". \$\endgroup\$ – Justin Mariner Jun 17 '17 at 15:45
7
\$\begingroup\$

V/Brain-flak Classic, 27, 26 bytes

(()){[[({}())[]]]}é1òÙæ_æ

Hexdump:

00000000: 2828 2929 7b5b 5b28 7b7d 2829 295b 5d5d  (()){[[({}())[]]
00000010: 5d7d e931 f2d9 e65f 01e6                 ]}.1..._..

Try it online! in V (modified slightly so that it will terminate so you can see the output. On TIO, V only outputs if the program terminates)

Try it online! in Brain-flak Classic

This isn't the most interesting of polyglots, since the V code has no effect on brain-flak classic, and vice-versa, however it's really fun to use both of my own languages on a challenge, and the two solutions are pretty interesting on their own.

V Explanation:

é1              " Insert a '1'
  ò             "   Recursively:
   Ù            "   Duplicate this number
    æ_          "   Flip this line
      <C-a>     "   Increment the number on this line
           æ    "   Flip it back (the '_' is implicit because it's at the end of the program)

BFC explanation:

#Push a one onto the main stack
(())

#Forever:
{

  #Print twice:
  [[

    #Increment the top of the stack.
    #Evaluates to *i + 1*
    ({}())

    #Minus one
    []
  ]]

#Endwhile
}
\$\endgroup\$
  • 3
    \$\begingroup\$ As soon as I saw the languages I knew you posted this one. \$\endgroup\$ – Riley Jun 17 '17 at 0:52
  • \$\begingroup\$ Why is it "Brain-flak Classic"? Is there a different Brain-flak? \$\endgroup\$ – nmjcman101 Jun 19 '17 at 12:10
  • \$\begingroup\$ @nmjcman101 Brain-flak classic was the original version of Brain-flak. The difference is explained in more detail here, but the reason I picked it is because it has explicit output, which modern brain-flak does not. (allowing for infinite output) \$\endgroup\$ – DJMcMayhem Jun 19 '17 at 21:24
4
\$\begingroup\$

Retina / Python 2, 61 bytes

#{*M`
#*M`
"""

}`$
1
""";i=1
while 1:print str(i)[::-1];i+=1

Retina | Python 2

\$\endgroup\$
  • \$\begingroup\$ I tried replacing str() with ``, but apparently disturbed the Retina code. I don't know why? \$\endgroup\$ – officialaimm Jun 17 '17 at 1:42
  • \$\begingroup\$ You can't do that anyway. If it's going to make it to large numbers and work properly, it has to be str, otherwise you'll get L in the results. But it actually does work in Retina. You must've changed more than what you said you did, like moving something onto a different line. \$\endgroup\$ – mbomb007 Jun 17 '17 at 3:28
3
\$\begingroup\$

R/Octave, 83 80 78 71 bytes

-3 bytes thanks to Luis Mendo

i=0;
while(1)
#{
print(c(i<-i+1,i))
#}
disp(flip(num2str(i)))
i+=1;
end

#{ }# is an Octave block comment and # just so happens to be the comment for R. The R interpreter only sees the next line as the body of the while loop, and the Octave interpreter skips right ahead to the Octave code

The R part prints out pairs of numbers starting at 1, and the Octave portion prints out the backwards numbers starting at 0.

I fully expect to be outgolfed (even by the same combination of languages); I've just been writing so much Matlab and R code recently that I figured I'd give it a shot.

Try it online! - Octave link

\$\endgroup\$
  • \$\begingroup\$ Does the top one need to be i=i+1? \$\endgroup\$ – Zacharý Jun 16 '17 at 21:34
  • 1
    \$\begingroup\$ @ZacharyT unfortunately, += doesn't work in R, so yeah, it does have to be like that. \$\endgroup\$ – Giuseppe Jun 16 '17 at 21:37
  • \$\begingroup\$ Is the end necessary? \$\endgroup\$ – BLT Jun 17 '17 at 21:02
  • 1
    \$\begingroup\$ @BLT, yeah, that marks the end of the while loop for octave. \$\endgroup\$ – Giuseppe Jun 17 '17 at 21:05
  • \$\begingroup\$ Ok, thanks. I was thinking that since it was never going to end anyway (while(1)) you could save those bytes. \$\endgroup\$ – BLT Jun 17 '17 at 21:10
3
\$\begingroup\$

Ruby / Python2: 68 64 bytes

i=0
"#{loop{p i+=1,i}}"
exec('while 1:print str(i)[::-1];i+=1')

Ruby perspective

simple init of variable:

i = 0

"#{}" is syntax for string interpolation. I use it to exec expression instead.

"#{loop{p i+=1,i}}"

p is a shorthand for puts. loop creates an infinite loop.

Next there is the exec thing, but it never gets evaluated, as the infinite loop is by definition infinite. Needed exec not to yield syntax error with Python code.

Python perspective

From perspective of Python, there is a common i=0. Next, Python has different syntax for string interpolation, so this line is simply discarded. Next there is an infinite loop similar to what others posted.

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

Bash / Check, 50 28 bytes

Thanks to @Doorknob for saving a bunch of bytes by switching from Python to Bash

#>
#v
 #p<p<)#
seq 1 inf|rev

To Bash:

#>
#v
 #p<p<)#

These are just some comments, which are ignored.

seq 1 inf|rev

Start a sequence going from 1 to infinity, then pipe the result to rev.

To Check:

#>

This immediately switches into 2D mode, going right. > directs the IP right, which has no effect. It wraps around to the beginning of the line and hits # again, which switches out of 2D mode. It then hits > in 1D mode, which pushes 0 to the stack. Because it is in 1D mode, the IP wraps to the next line.

#v

# switches the IP into 2D mode again and v directs it downwards.

 #p<p<)#

The first # switches back to 1D mode again. p outputs the TOS as a number (but does not pop it), and then < prints a newline. This is done twice, and then the number is incremented with ). # switches to 2D mode again, so the IP wraps to the beginning of the line, hits # to switch to 1D mode, etc.

\$\endgroup\$
  • 1
    \$\begingroup\$ Bash uses # for comments and can perform the "reversed numbers" task very easily: seq 1 inf|rev. \$\endgroup\$ – Doorknob Jun 17 '17 at 7:00
  • \$\begingroup\$ Ruby code i=1;loop{puts i.to_s.reverse;i+=1} is one byte shorter \$\endgroup\$ – dkudriavtsev Jun 17 '17 at 9:02
3
\$\begingroup\$

CJam / ><>, 27 23 bytes

"la,:naonao
"1{_sW%n)}h

To CJam:

Try it online! - note that you have to wait until the 60 second limit to see the output, but it works offline.

"la,:naonao
"

This defines a multi-line string literal that is never used.

 1{_sW%n)}h

The second line goes like this:

1     e# Push 1:               | 1 
{     e# Forever:              | 1
  _   e#   Duplicate:          | 1 1
  s   e#   Convert to string:  | 1 "1"
  W%  e#   Reverse:            | 1 "1"
  n   e#   Print with newline: | 1
  )   e#   Increment:          | 2
}h    e# End loop

To ><>:

"

Begins a string literal.

 la,:naonao

Content of the string literal. Each of the character codes is individually pushed to the stack.

"

The IP wraps around to reach " again, which ends string mode.

 la,

l takes the length of the stack, a pushes 10, and , divides. This gives us the length of the stack / 10.

    :nao

: duplicates, n prints as a number, a pushes 10, and o prints as a character code (a newline).

        nao

Same thing. Print the number followed by a newline. The stack now has length 10 again (the original string literal's content is on the stack).

The IP then wraps around to the " again, leading to 10 more elements to be pushed. Next time, l returns 20, so 2 is printed, etc.

The second line is never touched by the IP.

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

Röda/C (gcc), 90 bytes

main(){f(0);}f(a){a=1//1{[` $a`[::-1]];a++}while[]/*
;for(;;a++)printf("%d %d ",a,a);/**/}

Röda: Try it online!

C: Try it online!

Explanation

This abuses the fact that // is int divison in Röda but a line comment in C.

In both languages, main(){} denotes the main program, and they both call function f with a dummy argument of 0.

In Röda, a=1//1 does int division and assigns the result 1 to a. C sees a=1 and does the same thing, but everything after that assignment is a comment for C. From there, the two languages branch off.

Röda

We have an infinite loop with while[] (an empty condition is truthy). Inside that, ` $a` converts the integer a into a string (with a leading space) after which [::-1] reverses it (and it outputs with a trailing space). Then the value of a is incremented by one.

Outside of the while loop, a multiline comment starts /* and ends just before the end of the function.

C

After having ignored the rest of the line, the program goes to the second line. We start with a semicolon because the a=1 statement needs to be terminated. After that, we encounter a simple for loop that prints the iterating variable, a, twice on each iteration.

Outside of the for loop, the /* is just there to ignore Röda's ending */ comment.

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

QBIC / QBasic 4.5, 58 bytes

do
p=p+1
if q then
'?`_f!p$|
else
?p,p,
end if
loop

This heavily abuses the fact that all lowercase letters are seen as literal QBasic code by the QBIC interpreter and are therefor just passed along to the QBasic layer of QBIC. How both languages see this code, side by side:

LOC         QBasic                    QBIC
-------------------------------------------------------
do                   Start an infinite loop
p=p+1                Increment p, starts off as 0
if q then    q = 0, goto ELSE         q = 1, execute IF
'?`_f!p$|    ' = comment, invalid     '?` is a 'code literal', passing PRINT to QBASIC
             syntax is ignored        followed by QBIC code to flip p cast as string.
else         q=0, execute             q=1, so ignored
?p,p,        PRINT p twice,
             separated by tab
end if               End of the branching logic
loop                 Wrap around for the next pass
\$\endgroup\$
2
\$\begingroup\$

laserLANG / ><>, 163 bytes

!\0 \
/:+1/!   ]oo\
\:a( ?\:a%$a ,!
/r[-1l//" ,"/
/!n-%1:\?(1l
 \ --\/ <<---\
/----/'
\----  v
/>>--\#>---->/
\     /
/----<
\  \
/ -<< \
 /<< \
 "
">=>= /
\>=>=/

First time golfing, so it's a bit larger than it probably could be. I wanted to use ><>, but since a few people already used it to create the second sequence, I decided I wanted to give creating the first sequence a go.

Try ><> online!
For laserLANG, an offline interpreter is needed to try it. It can be found here.

laserLANG

!\
 \ --\/ <<---\
/----/'
\----  v
/>>--\#>---->/
\     /
/----<
\  \
/ -<< \
 /<< \
 "
">=>= /
\>=>=/

execution starts at ! which is ignored completely. it then reaches the \ and starts traveling down past several characters that it completely ignores. Finally it reaches another \ and the fun begins. I basically took the idea behind the "Hello, World!" loop and condensed it as well as I could. It was a bit of a challenge dealing with the fact that laserLANG is only about to decrement/increment the memory counter when the program counter is going left/right respectively. I feel like the most bytes could be saved here by doing some tricks I haven't thought of.

><>

!\0 \
/:+1/!   ]oo\
\:a( ?\:a%$a ,!
/r[-1l//" ,"/
/!n-%1:\?(1l

Execution starts at ! which causes it to skip the \. It then continues on as if the laserLANG code wasn't there. I didn't realize ><> only had support for float division, so a short and simple truncation was a bit confusing at first.

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

Befunge-98/><>, 32 bytes

\r.#%a/# :_::p#+a#1,#
>l::naonao

Wrote this before I saw how many ><> answers there were. Some background: \ is a direction changing operator in ><>, in this case pushing it down, while in Befunge it swaps the top two items on the stack. The Befunge code looks like:

\r.#%a/# :_::p#+a#1,#

Try it online!

Prints out the backwards numbers separated by newlines. Befunge prints a space automatically after each number, so each digit is separated by spaces. Repeatedly gets the last digit, prints it and divides the number by 10 until it is 0. Then increment and repeat.

The ><> code immediately goes down to the second line.

>l::naonao

Try it online!

And is pretty simple. Get length of stack, print twice with newlines and leave a copy of the length on the stack for the next loop.

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

Ruby/Stacked, 37 bytes

0#/0[1+:tostr rev out]
loop{p p$.+=1}

Try it online!

This prints 1 1 2 2... in Ruby and 1 2 3 ... 01 11 21... in Stacked.

Explanation

In Ruby:

0#/0[1+:tostr rev out]
loop{p p$.+=1}

After removing the comment, this becomes:

0
loop{p p$.+=1}

The only relevant line here is the last. p returns its argument, so p p prints its argument twice. $. starts at 0, so $.+=1 increments $., returning the incremented value. Therefore, this prints each number from 1 twice.

In Stacked:

0#/0[1+:tostr rev out]
loop{p p$.+=1}

This is equivalent to the following tokens:

0 #/ 0 [ 1 + : tostr rev out ] loop { p p $ . + = 1 }

The first two are not relevant (basically, transforming 0 into a reduce f Unction). Then, 0 is pushed to the stack. After, the function [1+:tostr rev out] is pushed to the stack. loop pops this function and executes it infinitely.

The inside of the function increments the top of the stack (1+), duplicates it (:), converts it to a string (tostr), reverses it (rev) and outputs it (out). This process is repeated infinitely. Since the loop is infinite, anything that comes after that token is essentially ignored by the interpreter.

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

><> / Jelly, 37 bytes (25 in Jelly's codepage)

01+:nao:nao!
DU;⁷Ṙ€
®‘©Çß

Try ><> online!

Try Jelly online!

><> prints the sequence to infinity twice, Jelly counts backwards.

><> is only concerned with the top line:

And thanks to @Challenger5 for saving some bytes here on the linefeed

01+:nao:nao!                           Stack at: 1st run   2nd run ...
0                 Push a 0             0         -
 1                Push a 1             0,1       1,1   
  +               Pop 2, add them      1         2 
   :              Duplicate top item   1, 1      2, 2
    n             Pop top, show as num 1         2
     a            Push the number 10   1, 10     2, 10
      o           Pop and show 10 as an ACII char (ie '\lf')
                                       1         2
         :nao     And again, for repetition
             !    ><> wraps around; this skips pushing a 0 again.

Jelly executes its code bottom-to-top. Only the last 2 lines are relevant.

®‘©Çß       main link, keeps track of the current number

®           Get a number from the register (0 on first run)
 ‘          Increment that by 1
  ©         Store in register
   Ç        Call helper (printer) link
    ß       Call this link again

DU;⁷Ṙ€      Printer

            (Say we are at number 21)
D           Break into digits         [2, 1]
 U          Reverse array             [1, 2]
  ;⁷        Append a line break       [1, 2, \n]
    Ṙ€      Print each char in array
\$\endgroup\$
  • \$\begingroup\$ @LuisMendo The characters used in this ><> code have ASCII code-points that correspond with the Jelly Codepage. I don't know too much about this codepage business, but I think this would result in the same bytes used to represent the code. The characters on the lower lines are ignored by ><> so it doesn't matter if they are exactly the same between the codepages. The byte count was taken from the ><> TIO link. \$\endgroup\$ – steenbergh Jun 16 '17 at 22:22
  • \$\begingroup\$ Aren't these being printed without a separator in ><>? \$\endgroup\$ – Esolanging Fruit Jun 17 '17 at 6:25
  • \$\begingroup\$ @Challenger5 you'r right; fixed. \$\endgroup\$ – steenbergh Jun 17 '17 at 6:49
  • \$\begingroup\$ Fish doesn't have a character type; "," just pushes the ASCII value of , to the stack, so you can use a instead for a newline separator. \$\endgroup\$ – Esolanging Fruit Jun 17 '17 at 6:57
  • \$\begingroup\$ It looks like the commas are still there on first line of the ><> explanation. \$\endgroup\$ – Esolanging Fruit Jun 17 '17 at 22:03
1
\$\begingroup\$

C (gcc)/PHP, 102 86 80 bytes

#//\
for(;;)echo strrev(++$i).'
int main(i){for(;;i++)printf("%d %d ",i,i);}//';

Outputs the double sequence in C and the reverse sequence in PHP.

Try it in C!

Try it in PHP!

Explanations

C

In C, the # forms preprocessor stuff. I don't really know much about C but it doesn't complain when there's any empty line for this stuff. The // forms a line comment. A \ at the end of a line is essentially "escaping" the newline and making the two lines be treated as one. This also works for line comments, so the second line is seen as a comment in C. The third line does the work of outputting the numbers with a simple for loop. Afterwards, there is simply a comment.

PHP

In PHP, # forms a line comment, so the first line is ignored entirely. The second line prints the numbers reversed with a for loop, and separates them with \nint main(i){for(;;i++)printf("%d %d ",i,i);}// (the C code wrapped in a string).

\$\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.