Count like Chuck Norris
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.
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
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.