Skip to main content
6 of 10
Add link to tokeniser
Muzer
  • 423
  • 3
  • 5

#38. C, 801 bytes # 1"16" 2//v(@#/;n4"14" #/3 auaaZ<>16/"<"6/b.q@")(22)S# ␉␉␉␉ #yy␉;36!@ # ␉ #=␉> #[#yy#yy0l0mx01k1k0l0ix0jx0h0h1d111P0eU0bx0b0o1d0b0e0e00x1d0i0fx0g0n0n11x0o0n0cx0c0o0f0c0gx0g0f0h0j0j0i0001k10mx0m0l11111100(^_) #<␉| print((eval("1\x2f2")and( 9 )or(13 ))-(0and 4)^1<<(65)>>(62))or'(\{(\{})(\{}[()])}\{}\{}\{})'#46(8+9+9+9+9+=!)#1|=/=1/24=x=9[<$+@+-@@@@=>+<@@@=>+<?#>+.--.]/ __DATA__=1#// #.\."12"*␉ """"#// =begin␉// # #*/␉ #define␉z sizeof 'c'-1?"38":"37" #include␉<stdio.h> int main() /*/ #()#\'*/{puts(z);}/*'`` $'main'␉// #-3o4o#$$$ <>3N.<>␉// #xx #x%~~~+␉+~*ttt*.x #xx =end #// """#"#// #0]#echo 21#/(\[FAC,1<-#2FAC,1SUB#1<-#52FAC,1SUB#2<-#32FACLEGEREEX,1PLEASEGIVEUPPLEASE) ap #_~nJ|#o51\ #0␛dggi2␛␉|1|6$//''25 >>>#>27.say# =#print(17)#^_^_7LEintndu;({})!<>+]////Z222999/3!@"26

is a literal tab, a literal ESC character; Stack Exchange would mangle the program otherwise. I recommend copying the program from the "input" box of the TIO link below, if you want to work on it.

Try them online!

Rundown

This program prints 38 in C, 37 in C++, 36 in Labyrinth, 35 in INTERCAL, 34 in Rail, No idea in Incident, 32 in Whirl, 31 in Modular SNUSP, 30 in Whitespace, 29 in Trigger, 28 in Brain-Flak, 27 in Perl 6, 26 in 05AB1E, 25 in Pip, 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng, 18 in Cardinal, 17 in Julia, 16 in Pyth, 15 in Haystack, 14 in Turtlèd, 13 in Ruby, 12 in Fission, 11 in Befunge-98, 10 in Befunge-93, 9 in Perl 5, 8 in Retina, 7 in Japt, 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in V/Vim, and 1 in Python 3.

Verification

Most of the languages are tested by the test driver shown above. You can test Reng here and Modular SNUSP here; they output 19 and 31 respectively, as required.

Here is my slightly tweaked version of the Incident tokeniser, designed to be a bit less golfed but a bit more useful.

Explanation

I've always loved making little polyglots but never one as big as this; I thought I should probably give it a go!

After @Chance's wonderful C++ answer, C seemed the next logical choice, and given (compared to some previous answers) the relative ease of adding it, I decided to go for it when I had the chance!

I used a very well-known trick to tell the difference between C and C++; the sizeof a character constant is 1 byte in C++ but the sizeof an int (guaranteed to be at least 16 bits) in C. This code should be very portable (except maybe for systems that use bytes with enough bits to fit an int) unless I've made a stupid mistake.

I've not tested Incident at all; I've no way of running it where I'm sat now. I'll have a better look at it this evening to see if I can make head or tail of it, but I thought I'd post what I had in the meantime, since everybody else seems to have similar troubles with Incident! However, I have now removed the ; token that was appearing before the #yy token. I did this by replacing s (which now appears much more in the C program than it did in the previous one) in the "detokenising" string with a ;. I have also tweaked the whitespace a little to change some other tokens to make some attempt at centring, to re-tokenise Tab Linefeed (by moving the tab at the end of the #include line to in the middle, thus making three tokens), and to de-tokenise the triple-space token by moving one space in the define line.

I firstly tried to do a printf with everything inline, but the multiple brackets seemed to be causing issues for Japt, so I made the line simpler, which appeared to fix it.

Next, Cardinal didn't like it, I guessed because of the % in the printf, so I had to solve that one by switching to manipulating strings.

My next attempt, trying to assign a string then change the second byte contingent on the C behaviour, ended up far too long and would have pushed Hexagony onto the next size; I wanted to avoid redoing that by keeping it within the extra characters I had to play with! I needed every byte I could get for this, so I implemented the byte-saving changes suggested by @Chance.

So I golfed that C code down a bit and came up with puts(sizeof'c'-1?"38":"37"); which almost worked, except that Underload was segfaulting, presumably because of the complex expression in the brackets.

Even after removing the extra >> that used to be required to match the << in Perl6, I couldn't get a concise enough way to split out the more complex part of it into a char array assignment. So I ended up looking at using the preprocessor instead.

After a lot of trial and error I found a solution that Retina seemed to like. Prelude which was causing me problems on-and-off all the way through, ended up fixing itself before I got round to looking at why it was breaking (I guess either the brackets or the ! I had in the ternary at one stage, looking at previous answers).

All the while I was patching up the whitespace to get something that Whitespace would like; I found that to be rather easy. Specifically, tab space space space was a very useful combination (the instruction to add the top two items on the stack), since it meant I could add whitespace to lines with no other whitespace without having everything go out of sync (I'm guessing its position in the program means it never actually gets executed so I'm not worried about stack underflows here).

Bear in mind I've never used most of these languages, I hope my success encourages more newcomers to give this a try! I just hope it's not a lost cause to make Incident work...

Muzer
  • 423
  • 3
  • 5