Count like Chuck Norris

58

2

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.

Luis Mendo

Posted 2017-06-16T21:05:03.203

Reputation: 87 464

8Downvoters, any suggestion for improvement? – Luis Mendo – 2017-06-16T21:10:06.240

29Chuck 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. – Magic Octopus Urn – 2017-06-16T21:55:34.303

11@carusocomputing, very wise given the world-wide shortage of push-ups since Chuck Norris did them all. – Wossname – 2017-06-16T22:17:18.290

1Chuck Norris' counting strategy: 0. 1/0. manages to kill counting. – Magic Octopus Urn – 2017-06-16T22:44:56.527

33Chuck Norris can complete this challenge in 0 bytes. He can just look at the computer and the computer does whatever he wants. – Kodos Johnson – 2017-06-17T00:47:35.070

1Chuck Norris/sirroN kcuhC, 5 bytes: count – Erik the Outgolfer – 2017-06-17T08:22:11.780

17Chuck Norris didn't try to win this challenge, he just allowed you to lose. – Nat – 2017-06-17T13:10:48.720

6@LuisMendo they don't like that people think computers can count as well as Chuck Norris – bleh – 2017-06-17T19:00:43.110

3“should continue to output terms of the sequence until stopped by the user” The user definitely cannot stop Chuck Norris. BTW counting Octave and Matlab as different is a bit risky I would say given that they are mostly compatible. – Andrea Lazzarotto – 2017-06-18T18:24:05.360

Why does the second sequence not start with 0, when the tenth/twentieth/etc terms all represent the respective zero? – 1Darco1 – 2017-06-18T20:12:58.810

@Andrea Yes, what languages to consider different and which the same is always tricky – Luis Mendo – 2017-06-18T21:06:56.323

@1Darco1 The second sequence is 1, 2, 3,..., 9,10, 11,... with the digits of each number in reverse order. As the rules indicate, you can start at 0 instead of 1 – Luis Mendo – 2017-06-18T21:08:54.463

4Chuck Norris already submitted a solution in BrainF*** and Malbolge, but due to it F***ing the Brains of the first person who read it then sending them to Malbolge hell, he roundhouse kicked the answer straight out of the Stack Exchange servers. – Ken Y-N – 2017-06-19T04:25:53.953

1

I can't wait for somebody to do this in ChuckScript https://github.com/angrykoala/chuckscript

– Daniel – 2017-06-19T12:49:02.870

Can I really use any separator? Is \nint main(i){for(;;i++)printf("%d %d ",i,i);}// a valid separator? – Business Cat – 2017-06-23T13:46:18.680

@BusinessCat I should have limited the acceptable separators more, but yes, that's valid. Some answers are using similar weird separators – Luis Mendo – 2017-06-23T13:59:53.393

Answers

18

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

Jonathan Allan

Posted 2017-06-16T21:05:03.203

Reputation: 67 804

I haven't checked if it works for Jelly, but if it does work, you can replace Ð,, by ==. – Adnan – 2017-06-18T21:13:55.987

That should parse in Jelly. I had looked in info.txt for a non-popping print, and did not see that. Thanks. – Jonathan Allan – 2017-06-18T21:18:22.537

26

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.

Comrade SparklePony

Posted 2017-06-16T21:05:03.203

Reputation: 5 784

Hmm, I think that you could use recursion in C code - a(i){printf("%i %i ",i,i);a(i+1)} – enedil – 2017-06-16T23:43:19.287

Why not to use while loop for C code? – enedil – 2017-06-17T17:36:40.930

@enedil It takes more bytes. – Comrade SparklePony – 2017-06-17T20:21:07.960

I think you can use \i`` instead of str(i) – Cyoce – 2017-06-18T08:02:52.553

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). – yoann – 2017-06-18T11:09:40.217

@yoann Thank you very much, edited. – Comrade SparklePony – 2017-06-18T22:31:07.160

@Cyoce I am afraid that won't work: large numbers in Python have an L after them, and using str gets rid of the L, whereas backticks do not. – Comrade SparklePony – 2017-06-18T22:32:05.723

Then here's a thought. How about changing i=1 to i=0, instead of incrementing after the print statement with ;i+=1, increment before and convert it to a long with i+=1L;. Then, change i++ to ++i in the C version. For the Python version, you can claim that L is part of the delimeter. – Cyoce – 2017-06-18T22:36:37.587

@Cyoce Clever idea, edited. – Comrade SparklePony – 2017-06-18T22:47:28.050

12

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.

Doorknob

Posted 2017-06-16T21:05:03.203

Reputation: 68 138

1@JonathanAllan You're right, that was the trailing newline added by my text editor. – Doorknob – 2017-06-18T21:10:16.517

11

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.

Dom Hastings

Posted 2017-06-16T21:05:03.203

Reputation: 16 415

8

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.

Justin Mariner

Posted 2017-06-16T21:05:03.203

Reputation: 4 746

1102 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),_;. – Titus – 2017-06-17T09:53:37.517

@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+" ". – Justin Mariner – 2017-06-17T15:45:24.683

7

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
}

James

Posted 2017-06-16T21:05:03.203

Reputation: 54 537

3As soon as I saw the languages I knew you posted this one. – Riley – 2017-06-17T00:52:06.477

Why is it "Brain-flak Classic"? Is there a different Brain-flak? – nmjcman101 – 2017-06-19T12:10:56.117

@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)

– James – 2017-06-19T21:24:11.450

4

Retina / Python 2, 61 bytes

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

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

Retina | Python 2

mbomb007

Posted 2017-06-16T21:05:03.203

Reputation: 21 944

I tried replacing str() with ``, but apparently disturbed the Retina code. I don't know why? – officialaimm – 2017-06-17T01:42:14.300

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. – mbomb007 – 2017-06-17T03:28:35.073

3

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

Giuseppe

Posted 2017-06-16T21:05:03.203

Reputation: 21 077

Does the top one need to be i=i+1? – Zacharý – 2017-06-16T21:34:30.647

1@ZacharyT unfortunately, += doesn't work in R, so yeah, it does have to be like that. – Giuseppe – 2017-06-16T21:37:21.353

Is the end necessary? – BLT – 2017-06-17T21:02:38.767

1@BLT, yeah, that marks the end of the while loop for octave. – Giuseppe – 2017-06-17T21:05:26.807

Ok, thanks. I was thinking that since it was never going to end anyway (while(1)) you could save those bytes. – BLT – 2017-06-17T21:10:55.507

3

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.

Esolanging Fruit

Posted 2017-06-16T21:05:03.203

Reputation: 13 542

3

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.

Esolanging Fruit

Posted 2017-06-16T21:05:03.203

Reputation: 13 542

1Bash uses # for comments and can perform the "reversed numbers" task very easily: seq 1 inf|rev. – Doorknob – 2017-06-17T07:00:39.387

Ruby code i=1;loop{puts i.to_s.reverse;i+=1} is one byte shorter – dkudriavtsev – 2017-06-17T09:02:19.793

3

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.

enedil

Posted 2017-06-16T21:05:03.203

Reputation: 223

2

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

steenbergh

Posted 2017-06-16T21:05:03.203

Reputation: 7 772

2

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.

user41805

Posted 2017-06-16T21:05:03.203

Reputation: 16 320

2

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.

Aroymart

Posted 2017-06-16T21:05:03.203

Reputation: 21

2

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.

Jo King

Posted 2017-06-16T21:05:03.203

Reputation: 38 234

1

><> / 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

steenbergh

Posted 2017-06-16T21:05:03.203

Reputation: 7 772

@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. – steenbergh – 2017-06-16T22:22:51.273

Aren't these being printed without a separator in ><>? – Esolanging Fruit – 2017-06-17T06:25:31.320

@Challenger5 you'r right; fixed. – steenbergh – 2017-06-17T06:49:22.790

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. – Esolanging Fruit – 2017-06-17T06:57:33.740

It looks like the commas are still there on first line of the ><> explanation. – Esolanging Fruit – 2017-06-17T22:03:43.577

1

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.

Conor O'Brien

Posted 2017-06-16T21:05:03.203

Reputation: 36 228

1

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).

Business Cat

Posted 2017-06-16T21:05:03.203

Reputation: 8 927