What's the shortest contiguous subset of ASCII you need to output the rest?

42

3

The printable ASCII characters (hex codes 20 to 7E) in order are:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

(Note that space is in there.)

This string clearly contains all the printable ASCII characters at least once in increasing order when read from left to to right, but not in decreasing order.

The string

REVERSED:~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! NORMAL: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

contains all the printable ASCII characters at least once both in increasing and decreasing order. In other words, when the characters are valued with their numeric code, the longest increasing and longest decreasing subsequences have length 95 (the number of printable ASCII characters).

Challenge

Choose a contiguous subset of N printable ASCII characters, such as LMNOP (N = 5). Write a program using only those N characters whose output contains all 95 ASCII characters in increasing and decreasing order like the example above.

The winner is the submission with the lowest N. In case of ties the shortest code in bytes wins.

Notes

  • A contiguous subset means a set of the printable ASCIIs that all appear in an unbroken line, such as LMNOP or 89:;<=>.
  • Your contiguous subset may "loop around" from ~ to space, but this incurs a +3 penalty on N. So {|}~ has N = 4, but {|}~ ! has N = 6 + 3 = 9.
  • Your program may only contain the N printable ASCII characters from the contiguous subset you've selected. They do not all have to appear and may appear multiple times in any order. (All non-printable ASCII and all non-ASCII is not allowed. This means tabs and newlines are not allowed.)
  • Your output may only contain printable ASCII characters and must be less than 10000 characters long.
  • Your output's longest increasing and decreasing subsequences must both have length 95 (as explained above).
  • Output to stdout. There is no input.
  • N is a positive integer less than 96.

Calvin's Hobbies

Posted 2014-08-05T22:13:28.320

Reputation: 84 000

45At last, a challenge built for Brainfuck! – Level River St – 2014-08-05T22:26:51.043

{|}~ ! is 6 + 3 = 9. – Timtech – 2014-08-05T22:51:48.020

I think that the only thing that'll beat the current entries is something that will accept 0s and 1s as input; that'd give you N = 2 – Derek Tomes – 2014-08-06T01:47:42.030

1Given the kinds of answers this is attracting (which are clearly the optimal way), it might be interesting for the score to be some combination of program shortness and number of characters used. Perhaps minimizing n*m where n is the size of the subset of ascii, and m is the length of the program? – J.P. – 2014-08-06T10:52:38.970

1@J.P. "The winner is the submission with the lowest N. In case of ties the shortest code in bytes wins." General consensus is that it is bad form to change the rules at a late stage. The winning answer will be the shortest program in Unary (which is basically the shortest program in Brainfuck, just coded differently.) – Level River St – 2014-08-06T12:36:32.677

1I would suggest, though, that those posting in Unary might like to put an approximation of their code length in scientific notation, rather than making us squint to count the digits. – Level River St – 2014-08-06T12:40:11.960

@J.P. Yeah, it's too late to change the scoring method now. – Calvin's Hobbies – 2014-08-06T12:42:04.927

@steveverrill - Done. – Comintern – 2014-08-07T01:47:48.970

1Welcome to CodeGolf, where 90% of all questions are hijacked. ;) – TwoThe – 2014-08-07T10:29:54.800

If no non-printable ASCII is allowed, that means no newlines, which pretty much excludes any language that requires newlines, right? – Gabe – 2014-08-07T20:04:04.400

@Gabe That's right. – Calvin's Hobbies – 2014-08-07T20:08:01.633

Answers

33

Unary, N=1

14680262330376163203871465704220787333741951071 bytes

Uses only the '0' byte (ASCII 49).

Golfed about 4.13253e+60 bytes out of @Comintern's solution. Credit still to him :)

In the original Brainfuck:

++++++++[->++++<]>
[>+>+++<<-]>>-
[-<.+<+>>]<<
[>-.<-]

nneonneo

Posted 2014-08-05T22:13:28.320

Reputation: 11 445

5LOL! Love the byte reduction counts in Unary, they always make me laugh. Nice golf of the underlying Brainfuck, +1 – Comintern – 2014-08-06T04:21:48.907

It's a shame it's still 14,680,262,330,376,163,203,871,465,694,220 bytes longer than the maximum (10,000). Maybe you can golf a bit more? – Gabe – 2014-08-08T05:36:50.730

3@Gabe: The output is limited to 10,000 characters. The program length is not bounded. – nneonneo – 2014-08-08T08:12:11.770

@nneonneo: Oh, well carry on then! – Gabe – 2014-08-08T12:13:53.067

96

Unary, N=1

4132527913354820031118363262102424570092493175835499123283719 (4.1325279e+60) bytes

Source code in unary is obviously too large to post here. It can be easily reproduced by typing out (or generating) a file filled with "0"s of the same length as the number of bytes above.

Here is the binary representation:

1010010010010110011000010010010010010010010010001111000000010010010010010110011000010010010010010010010010010010010010010010010010010010010001111000110011001010001100010000000111001110011001011100000111

And the equivalent Brainf**k code (linebreaks for clarity):

++++[->++++++++<]>>
+++++[->+++++++++++++++++++<]>
[-<+<.+>>]<
[-<-.>]

Output:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! 

EDIT: Golfed out 9.097887e+87 unnecessary characters.

Comintern

Posted 2014-08-05T22:13:28.320

Reputation: 3 632

17Damn. Here I was feeling clever for getting N=2. +1, and also for golfing out more characters than there are atoms in the universe. – nneonneo – 2014-08-06T03:08:25.753

2@nneonneo - Right tool for the job, my friend. Usually it sucks as a golfing language... – Comintern – 2014-08-06T03:09:38.477

BTW I think you forgot to add a leading 1 (mandated by the Unary spec). – nneonneo – 2014-08-06T03:15:02.403

@nneonneo - Good catch, corrected. – Comintern – 2014-08-06T03:17:22.673

55Hahaha +1 just for "Golfed out 9.097887e+87 unnecessary characters." – Doorknob – 2014-08-06T09:15:56.197

8

I didn't know "Unary" existed, so I was going to invent it, except I was going to just use the letter "O". Then I was going to write a database in it. Now that this answer has introduced me to it, I guess I can just make a variant of Unary instead... Onary?

– HostileFork says dont trust SE – 2014-08-06T13:26:42.740

6Show us the code or it's not an answer. :-) More to the point: this answer is basically just a (well-supported) claim that such a program exists in an abstract space of possible programs, but I claim the physical instantiation of such a program is impossible and thus this is a non-solution. :-) – R.. GitHub STOP HELPING ICE – 2014-08-06T18:46:38.970

+1 for a solution that involves more than 10^39 times the amount of bytes that exist in the world! – Ryan – 2014-08-06T18:57:30.160

Considering the number of bytes, one of the best parts of the answer is "easily reproduced". – ultimA – 2014-08-06T19:57:50.880

3@R.. I think this counts. It's along the same lines as using the C preprocessor, albeit much more absurd. – pandubear – 2014-08-07T03:56:40.863

2

@R.. I think this is a valid answer. Unary is a real language, however esoteric, so this is not just a claim that such a program exists.

– Calvin's Hobbies – 2014-08-07T05:28:34.827

It's not a real language because you can't express a program in it. It's just a non-realizable expression of another language. Non-realizable because there are not that many bytes of storage, and even if there were, you could not count them reliably (the error rate counting would be sufficiently higher to make all program executions fail). – R.. GitHub STOP HELPING ICE – 2014-08-07T12:36:27.680

4@R.. If you're concerned with the file storage requirement, remember that it would be fairly trivial to compress the file and/or memory holding the source code because there is only one symbol. Obviously, if you decompress it all at once to ASCII you would hit hardware limitations. I could even toss together a Unary IDE that let you browse through all the bytes with a scroll-bar and still only use a small HDD footprint for the source file. – Comintern – 2014-08-07T13:12:31.507

2+1 for making me think about the fact that every program I write is just a really large number. And for possibly removing the most characters in a golfing ever! – Tim S. – 2014-08-07T13:37:30.727

@Comintern: You can't write such a compressor/decompressor which actually runs (before the heat death of the universe) unless it just cheats and assumes all characters of the program are the same and only the file size is significant, and thereby gets away without ever storing the contents of the program. And at that point I claim the size (in whatever form you encoded it, i.e. not unary) is the actual program and does not use only one character to represent it. – R.. GitHub STOP HELPING ICE – 2014-08-07T16:30:21.533

3@R.. I'm not sure why you think that's 'cheating'. If all the characters are the same, I'd call it 'efficient'. – Comintern – 2014-08-07T17:16:56.177

@Comintern: Because it's not actually a compressor/decompressor then. It's making assumptions about its data. Any "compressor" whose run time is less than O(n) in the size n of the data is not a compressor. But this is getting to be a stupid topic. People are free to agree with your view or mine as they wish. – R.. GitHub STOP HELPING ICE – 2014-08-07T18:38:04.500

1"And the equivalent Brainfk code (linebreaks for clarity**):" -- is that a joke? – rev – 2014-08-07T20:17:04.620

@AcidShout - Actually it wasn't. The first line sets cell 1 to 32, the second line sets cell 3 to 95, line three is the ascending ASCII sequence (and sets cell 2 to 95), the last line is the descending ASCII sequence. Much easier to read on 4 lines. The EDIT: and "easily reproduced by typing" were jokes though. – Comintern – 2014-08-07T23:36:13.557

Whitespace. N=1, there's no need to write the program to see this. It's also a lot shorter than those insane Unary programs. – Loren Pechtel – 2014-08-08T02:57:53.830

@LorenPechtel - You couldn't do a valid Whitespace program - by spec it has to end in 3 linefeeds (ASCII hex 0A) and the challenge defines printable ASCII as hex codes 20 to 7E. You also can't perform I/O without linefeeds.

– Comintern – 2014-08-08T03:07:21.450

@Comintern I misread the rules--I was thinking you didn't count the non-ASCII, not that you weren't allowed them. – Loren Pechtel – 2014-08-08T04:02:10.430

1Here is a shortened version of the BrainF_ck code for anyone who wants that (requires an interpreter that uses wrapping); from 67 to 56 characters (could be made shorter): >>-[-[-<]>>+<]>-<<<<->--<[+[+<]>>+]<+[>>.+<+<-]>+[>.-<-] – jocopa3 – 2014-08-08T07:44:11.303

6@R.. A decompressor that assumes all characters are the same is not cheating, if you create a special compressed file format that only allows a single character. In that case, the fact that all characters are the same is a hard fact, not an assumption, so the decompressor can rely on that fact. – hvd – 2014-08-08T08:27:24.093

1Here's some Haskell code for running the program, I haven't had time to test it yet, however: main = readProcess "unary" [] (genericReplicate 4132527913354820031118363262102424570092493175835499123283719 '0'). – TheSpanishInquisition – 2014-08-08T09:31:07.423

@hvd: You've fundamentally changed the definition of 'character' when you no longer have a character set but a single 'character' and the only relevant property is how many of them you have. Much like "base 1" fundamentally changes the definition of "base" (it's not a special case of "base N"). – R.. GitHub STOP HELPING ICE – 2014-08-08T17:23:24.123

@TimS. this is one of the fundamental assumptions behind the Gödel theorem. I would suggest reading the Goedel, Escher, Bach book for a very thorough explanation. – Thorbjørn Ravn Andersen – 2014-08-09T13:40:52.873

@R.. "base 1" is a special case of "base N". It is a degenerate case, but a degenerate case is still a special case. – Matthew Najmon – 2014-08-10T00:20:56.440

1Cannot reproduce – pqnet – 2014-08-17T19:13:46.207

51

Brainfuck, N=2

----------------------------------------------------------------------------------------------------------------------------------.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.

24,383 bytes. Uses only - and . (ASCII 45 and 46). Try it here: http://esoteric.sange.fi/brainfuck/impl/interp/i.html. Can probably be parsed as Morse code with the right spaces.

Requires an interpreter adhering to the traditional definition of Brainfuck, which uses an array of (at least) 30,000 byte cells, all initialized to zero.

nneonneo

Posted 2014-08-05T22:13:28.320

Reputation: 11 445

Very good. This occured to me after I went to bed :-D – Level River St – 2014-08-06T05:45:38.643

How does this work? There's only one output at the end, I don't understand how it can output the whole 95 character string. – Lou – 2014-08-06T08:59:13.343

4@LeoKing you need to be more observant. there are 256-126=130 -, then the descending part .-.-.etc then the ascending part (groups of 255 - followed by a .) As far as I can tell it's all there. Also see edit on my answer for explanation. – Level River St – 2014-08-06T09:25:37.160

1Oh sorry, when I scrolled along I thought it was just a string of - with just one . at the end :). My bad. – Lou – 2014-08-06T09:48:20.663

4+1 "Can probably be parsed as Morse code with the right spaces." – Amory – 2014-08-08T15:18:57.707

"Can probably be parsed as Morse code with the right spaces." Coincidentally I have a program that I wrote in C# that reads text and beeps it back as morse code. Internally it converts the characters into - and ., so with a bit of modification it could probably be done. – Pharap – 2014-08-09T03:20:07.217

23

CJam - N=3; 7659 bytes

''(((((((''((((((''(((((''((((''(((''((''('''(')'))')))'))))')))))'))))))')))))))'))))))))')))))))))'))))))))))')))))))))))'))))))))))))')))))))))))))'))))))))))))))')))))))))))))))'))))))))))))))))')))))))))))))))))'))))))))))))))))))')))))))))))))))))))'))))))))))))))))))))')))))))))))))))))))))'))))))))))))))))))))))')))))))))))))))))))))))'))))))))))))))))))))))))')))))))))))))))))))))))))'))))))))))))))))))))))))))')))))))))))))))))))))))))))'))))))))))))))))))))))))))))')))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))))'))))))))))))))))))))))))))))))')))))))))))))))))))))))))))))'))))))))))))))))))))))))))))')))))))))))))))))))))))))))'))))))))))))))))))))))))))')))))))))))))))))))))))))'))))))))))))))))))))))))')))))))))))))))))))))))'))))))))))))))))))))))')))))))))))))))))))))'))))))))))))))))))))')))))))))))))))))))'))))))))))))))))))')))))))))))))))))'))))))))))))))))')))))))))))))))'))))))))))))))')))))))))))))'))))))))))))')))))))))))'))))))))))')))))))))'))))))))')))))))'))))))')))))'))))')))'))')'(''''(''((''(((''((((''(((((''((((((''(((((((

Try it at http://cjam.aditsu.net/

aditsu quit because SE is EVIL

Posted 2014-08-05T22:13:28.320

Reputation: 22 326

13What..just what... – Calvin's Hobbies – 2014-08-05T22:39:05.803

1@Calvin'sHobbies just incrementing and decrementing characters :) – aditsu quit because SE is EVIL – 2014-08-05T22:39:48.080

52Are you sure this isn't LISP? – avalancha – 2014-08-06T09:27:48.903

18

Brainf**k, N=4

My first brainfuck program. Uses 3 characters out of the block +,-. (Ascii 43 to 46.)

410 bytes (one . can be deleted from the program if the double ~~ can be reduced to a single ~.)

Here's the list of commands in that area of the ASCII table (I don't need the input command):

+   increment (increase by one) the byte at the data pointer.
-   decrement (decrease by one) the byte at the data pointer.
.   output the byte at the data pointer.
,   accept one byte of input, storing its value in the byte at the data pointer.

Fortunately the remaining commands <>[] (moving data pointer and performing conditional jumps) are not required!

Split into 3 lines for clarity: 1: Increment until the data reaches 32. 2: Output and increment until data reaches 126. 3: Output and decrement until data reaches 32.

++++++++++++++++++++++++++++++++

.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.

.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.

Output

 !"#$%&'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! 

Edit N=2

Per @nneonneo's answer, it is possible to replace each + with 255 -signs for N=2. some rearrangement of the code and output (displaying down then up) means the first line can be reduced to 256-126=130 - signs. This occurred to me after I went to bed, and nneoneo beat me to it. https://codegolf.stackexchange.com/a/35801/15599

Level River St

Posted 2014-08-05T22:13:28.320

Reputation: 22 049

Yes, you can use ~ instead of ~~ since the increasing and decreasing subsequences would still be there. – Calvin's Hobbies – 2014-08-05T23:24:41.210

There had to be a Brainfuck program somewhere for this question ;) – WallyWest – 2014-08-06T03:51:07.317

beat me to it.... – Joshpbarron – 2014-08-06T06:07:41.753

7

C; N = 43 = 40 + 3

Here I avoid such common characters as + - * /, the digits 0-9, comma , and semicolon ;.

So I was forced to express various numbers using only the operations & % ~.

Further golfing may be possible (finding smallest representations for the numbers 63 and 95 is an exercise for the reader).

main(){
if (printf(" !"))
if (putchar('"'))
if (printf("#$%%&'"))
if (putchar('i'%(~' '&'a')))
if (putchar('j'%(~' '&'a')))
if (putchar('k'%(~' '&'a')))
if (putchar('l'%(~' '&'a')))
if (putchar('m'%(~' '&'a')))
if (putchar('n'%(~' '&'a')))
if (putchar('o'%(~' '&'a')))
if (putchar('p'%(~' '&'a')))
if (putchar('q'%(~' '&'a')))
if (putchar('r'%(~' '&'a')))
if (putchar('s'%(~' '&'a')))
if (putchar('t'%(~' '&'a')))
if (putchar('u'%(~' '&'a')))
if (putchar('v'%(~' '&'a')))
if (putchar('w'%(~' '&'a')))
if (putchar('x'%(~' '&'a')))
if (putchar('y'%(~' '&'a')))
if (putchar('z'%(~' '&'a')))
if (putchar('{'%(~' '&'a')))
if (putchar('|'%(~' '&'a')))
if (putchar('}'%(~' '&'a')))
if (putchar('~'%(~' '&'a')))
if (putchar('~'%(~'!'&'a')))
if (putchar(~(~('~'%(~'!'&'a'))&~(~' ' & '!'))))
if (putchar(~'!'&'a'))
if (putchar(~' '&'a'))
if (putchar(~' '&'b'))
if (putchar(~' '&'c'))
if (putchar(~' '&'d'))
if (putchar(~' '&'e'))
if (putchar(~' '&'f'))
if (putchar(~' '&'g'))
if (putchar(~' '&'h'))
if (putchar(~' '&'i'))
if (putchar(~' '&'j'))
if (putchar(~' '&'k'))
if (putchar(~' '&'l'))
if (putchar(~' '&'m'))
if (putchar(~' '&'n'))
if (putchar(~' '&'o'))
if (putchar(~' '&'p'))
if (putchar(~' '&'q'))
if (putchar(~' '&'r'))
if (putchar(~' '&'s'))
if (putchar(~' '&'t'))
if (putchar(~' '&'u'))
if (putchar(~' '&'v'))
if (putchar(~' '&'w'))
if (putchar(~' '&'x'))
if (putchar(~' '&'y'))
if (putchar(~' '&'z'))
if (putchar(~' '&'{'))
if (putchar(~' '&'|'))
if (putchar(~' '&'}'))
if (putchar(~' '&'~'))
if (putchar(~(~(~' '&'~')&~(~' ' & '!'))))
if (putchar(~('!'%' ')&'a'))
if (printf("abcdefghijklmnopqrstuvwxyz{|}~}|{zyxwvutsrqponmlkjihgfedcba"))
if (putchar(~('!'%' ')&'a'))
if (putchar(~(~(~' '&'~')&~(~' ' & '!'))))
if (putchar(~' '&'~'))
if (putchar(~' '&'}'))
if (putchar(~' '&'|'))
if (putchar(~' '&'{'))
if (putchar(~' '&'z'))
if (putchar(~' '&'y'))
if (putchar(~' '&'x'))
if (putchar(~' '&'w'))
if (putchar(~' '&'v'))
if (putchar(~' '&'u'))
if (putchar(~' '&'t'))
if (putchar(~' '&'s'))
if (putchar(~' '&'r'))
if (putchar(~' '&'q'))
if (putchar(~' '&'p'))
if (putchar(~' '&'o'))
if (putchar(~' '&'n'))
if (putchar(~' '&'m'))
if (putchar(~' '&'l'))
if (putchar(~' '&'k'))
if (putchar(~' '&'j'))
if (putchar(~' '&'i'))
if (putchar(~' '&'h'))
if (putchar(~' '&'g'))
if (putchar(~' '&'f'))
if (putchar(~' '&'e'))
if (putchar(~' '&'d'))
if (putchar(~' '&'c'))
if (putchar(~' '&'b'))
if (putchar(~' '&'a'))
if (putchar(~'!'&'a'))
if (putchar(~(~('~'%(~'!'&'a'))&~(~' ' & '!'))))
if (putchar('~'%(~'!'&'a')))
if (putchar('~'%(~' '&'a')))
if (putchar('}'%(~' '&'a')))
if (putchar('|'%(~' '&'a')))
if (putchar('{'%(~' '&'a')))
if (putchar('z'%(~' '&'a')))
if (putchar('y'%(~' '&'a')))
if (putchar('x'%(~' '&'a')))
if (putchar('w'%(~' '&'a')))
if (putchar('v'%(~' '&'a')))
if (putchar('u'%(~' '&'a')))
if (putchar('t'%(~' '&'a')))
if (putchar('s'%(~' '&'a')))
if (putchar('r'%(~' '&'a')))
if (putchar('q'%(~' '&'a')))
if (putchar('p'%(~' '&'a')))
if (putchar('o'%(~' '&'a')))
if (putchar('n'%(~' '&'a')))
if (putchar('m'%(~' '&'a')))
if (putchar('l'%(~' '&'a')))
if (putchar('k'%(~' '&'a')))
if (putchar('j'%(~' '&'a')))
if (putchar('i'%(~' '&'a')))
if (printf("'&%%$#"))
if (putchar('"'))
if (printf("! "))
{}
}

The ascii subset is 32...41 and 97...126.

I am not sure whether newline characters are allowed in code; if not, just remove them.

anatolyg

Posted 2014-08-05T22:13:28.320

Reputation: 10 719

Newlines are not allowed but as you can remove them in C it's not an issue here. – Calvin's Hobbies – 2014-08-07T20:46:36.853

Nice. Should be the minimum N for a C solution outside of abusing the linker - that whole main() thing... – Comintern – 2014-08-08T00:12:19.170

5

Whirl, N=2, 6486 bytes

Using only 2 characters, 01.

000110000011110000100000100000100000100000100000100000100000100000100000100110000011100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001111100000100010011110001000000011111000001000100111100010000000111110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001001111000100000001000011110000010001000001100

Output :

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"! 

I think I can golf down more using loops, but coding with 0s and 1s was horrible, so I won't do it.

Commented

00011000001111 // init math.val to O
0000100000100000100000100000100000100000100000100000100000100 // math.val to 32, mem to 32
110000 // set IO to print
0111001111000100000001111100000100 // print ascii(32), mem to 33
01001111000100000001111100000100 // print ascii(33), mem to 34
01001111000100000001111100000100 // print ascii(34), mem to 35
01001111000100000001111100000100 // print ascii(35), mem to 36
                                 // skipped
01001111000100000001111100000100 // print ascii(l23), mem to l24
01001111000100000001111100000100 // print ascii(l24), mem to l25
01001111000100000001111100000100 // print ascii(l25), mem to l26
0100 // print ascii(l26)
111100010000000100001111000001000100 // mem to l25, print ascii(l25)
111100010000000100001111000001000100 // mem to l24, print ascii(l24)
111100010000000100001111000001000100 // mem to l23, print ascii(l23)
                                     // skipped
111100010000000100001111000001000100 // mem to 34, print ascii(34)
111100010000000100001111000001000100 // mem to 33, print ascii(33)
111100010000000100001111000001000100 // mem to 32, print ascii(32)
0001100 // KTHXBAI

Note that there's O and l as 0 and 1.

Snack

Posted 2014-08-05T22:13:28.320

Reputation: 2 142

4

Python 2.7 N=45=42+3

This uses string.printable, sorts and spits it out over stdout. I save a few characters by inserting the . in stdout.write by using eval and string formating using the ord values of characters I could use.

from string import printable
from sys import stdout
eval("map(stdout%swrite,sorted(printable,None,ord))"%chr(ord('+') + ord('z')-ord('w') ))
print ""
eval("map(stdout%swrite,reversed(sorted(printable,None,ord)))"%chr(ord('+') + ord('z')-ord('w') ))

Out with the old - N=49=46+3

Unfortunately, while python includes the string.printable list, this isn't in ascii order, and there is no way to use it without a * or a ., so it takes less characters to do it manually.

Using the character range:

abcdefghijklmnopqrstuvwxyz{|}~ AND   !"#$%&'()*+,-.

print ''.join((chr(i)
  for i in range(
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
  )))
print ''.join((chr(i)
  for i in range(
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    len('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
    -len('x')
  )))

The obvious version: N=63=60+3

This is the obvious version using the character range:

[\]^_`abcdefghijklmnopqrstuvwxyz{|}~   AND   !"#$%&'()*+,-./01234567 `:

print ''.join([chr(i) for i in range(0x20,0x7E)])
print ''.join(reversed([chr(i) for i in range(0x20,0x7E)]))

user8777

Posted 2014-08-05T22:13:28.320

Reputation:

A bit nitpicky comment, but you didn't include 1 in your first character range. You got me wondering for a while why would you need a 0. – Dunno – 2014-08-06T20:32:34.627

@Dunno Thanks for pointing it out, but I dunno why I even used a 1 when len('x') saves me another 2 characters. – None – 2014-08-07T03:32:43.320

I've just realized that your code uses newlines. This is not allowed since they aren't printable ascii. – Calvin's Hobbies – 2014-08-07T06:04:31.653

@Calvin'sHobbies Sadly python isn't very golf friendly, I'll see what I can do. – None – 2014-08-07T06:06:47.430

1It looks like your import solution will only work if you have ;, which adds a substantial amount of characters. – Gabe – 2014-08-08T05:35:06.220

@Gabe I could pull the same ord/chr/eval trick and get it done, I just haven't had time to figure that out. – None – 2014-08-08T05:48:42.450

4

C; N = 61 = 58 + 3

To compensate for using such a large subset, I golfed my code.

a;main(d){for(;d&&++a,d||--a;putchar(a+31),a-95||--d);}

The ASCII subset is 32...59 and 97...126.

It was a fun challenge to avoid the = character!

anatolyg

Posted 2014-08-05T22:13:28.320

Reputation: 10 719

Oh, nice, though anatolyg's answer cleverly manages to avoid ;. You might be able to use that to expand your answer, without it becoming a copy of the other one. – hvd – 2014-08-08T08:35:55.277

1No......... ;-) – anatolyg – 2014-08-08T18:14:29.353

3

Python 2.7 N=28+12+3=43

Using characters cdefghijklmnopqrstuvwxyz{|}~ and then wrapping around to !"#$%&'()*+

exec "print ''"
   + chr(ord('+') + len('xxx'))        # .
   + "join(chr(i) for i in r"
   + chr(ord('c') + ~len('x'))         # a
   + "nge(ord(' ')"                    # 32
   + chr(ord('+') + len('x'))          # ,
   + " ord('~') + len('x'))) + ''"     # 127
   + chr(ord('+') + len('xxx'))        # .
   + "join(chr(i) for i in r"
   + chr(ord('c') + ~len('x'))         # a
   + "nge(ord('~')"                    # 126
   + chr(ord('+') + len('x'))          # ,
   + " ord(' ') + ~len('')"            # 31
   + chr(ord('+') + len('x'))          # ,
   + " + ~len('')))"                   # -1

In order to avoid using ,.- I had to use some tricks. I used exec so I can make the code into strings which allowed me to use chr(ord('+') + len('xxx')) for . and chr(ord('+') + len('x')) for ,. Any place I needed a -1, I used ~0 in the form of ~len(''). To avoid a, I used chr(ord('c') + ~len('x')) (99 - 2).

The string that gets composed has N=48, using characters abcdefghijklmnopqrstuvwxyz{|}~ and then wrapping around to !"#$%&'()*+,-.

print ''.join(chr(i) for i in range(ord(' '), ord('~') + len('x')))
    + ''.join(chr(i) for i in range(ord('~'), ord(' ') + ~len(''), + ~len('')))

Note that the newlines and comments are only for readability.

Gabe

Posted 2014-08-05T22:13:28.320

Reputation: 161

2

Ruby - N=48

Let Ruby be Ruby and embrace the wrap-around penalty.
N=48 <- 15 (' '-'.') + 30 ('a'-'~') + 3

eval "for c in ' '..'~' do putc c end #{('i'.ord-'.'.ord).chr} for c in ' '..'~' do putc ('~'.ord+' '.ord-c.ord).chr end"

or

eval "(' '..'~').each { |c| putc c } #{('i'.ord-'.'.ord).chr} (' '..'~').each { |c| putc ('~'.ord+' '.ord-c.ord).chr }"



Old:
N=72 {straight-line scoring} <- 72 ('.'-'u') + invalid newlines

format = 67.chr
format << 42.chr
a = []
for i in 33..126 do a << i end
t = a.dup
for i in 33..126 do a << t.pop end
puts a.pack format

There's some flailing in here to avoid the 'v' in "reverse". I left it in because I'm fond of the pack("C*") hack.

Scott Leadley

Posted 2014-08-05T22:13:28.320

Reputation: 459

1

x86_64 Machine Code, Mach-O format

N = 2, 32768 chars (too large to fit msg limit)

Edit: Pastebin is down, so you can find the full text at: http://www.ionoclast.com/random/golf.bin.txt

Ionoclast Brigham

Posted 2014-08-05T22:13:28.320

Reputation: 119

Is your entire code available somewhere? If not, you could post the full code externally; for example, on http://pastebin.com.

– Doorknob – 2014-08-09T23:01:40.177

The compiled executable is 33455 bits or bytes? You don't usually have an odd number of bits, and Clang and GCC won't produce such small executables without some tricks to strip the exception table. This program compiles to 8520 bytes, including the unwind table: `#include <unistd.h>

int main() { char const s[] = "~}|{zyxwvutsrqponmlkjihgfedcba`^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+)('&%$#"! !"#$%&'()+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^`abcdefghijklmnopqrstuvwxyz{|}~"; write( 1, s, sizeof s ); } ` Assembly should do a lot better. – Potatoswatter – 2014-08-10T01:20:52.370

Actually, it was exactly 4k == 32768 binary characters. I think I found a bug in SO's char counting code. – Ionoclast Brigham – 2014-08-10T16:19:42.110

1

Ruby, N = 27

Uses $ through >.

$><<(''<<32<<33<<34<<35<<36<<37<<38<<39<<40<<41<<42<<43<<44<<45<<46<<47<<48<<49<<50<<51<<52<<53<<54<<55<<56<<57<<58<<59<<60<<61<<62<<63<<64<<65<<66<<67<<68<<69<<70<<71<<72<<73<<74<<75<<76<<77<<78<<79<<80<<81<<82<<83<<84<<85<<86<<87<<88<<89<<90<<91<<92<<93<<94<<95<<96<<97<<98<<99<<100<<101<<102<<103<<104<<105<<106<<107<<108<<109<<110<<111<<112<<113<<114<<115<<116<<117<<118<<119<<120<<121<<122<<123<<124<<125<<126<<126<<125<<124<<123<<122<<121<<120<<119<<118<<117<<116<<115<<114<<113<<112<<111<<110<<109<<108<<107<<106<<105<<104<<103<<102<<101<<100<<99<<98<<97<<96<<95<<94<<93<<92<<91<<90<<89<<88<<87<<86<<85<<84<<83<<82<<81<<80<<79<<78<<77<<76<<75<<74<<73<<72<<71<<70<<69<<68<<67<<66<<65<<64<<63<<62<<61<<60<<59<<58<<57<<56<<55<<54<<53<<52<<51<<50<<49<<48<<47<<46<<45<<44<<43<<42<<41<<40<<39<<38<<37<<36<<35<<34<<33<<32)

Lynn

Posted 2014-08-05T22:13:28.320

Reputation: 55 648

0

Scala, N = 69

\u0028\u0027\u0020\u0027\u0074\u006f\u0027\u007e\u0027\u0029\u002b\u002b\u0028\u0027\u007e\u0027\u0074\u006f\u0027\u0020\u0027\u0029

Uses the characters 01246789\bdefu (unicode escapes) as a fancy way of writing (' 'to'~')++('~'to' ')map print.

corvus_192

Posted 2014-08-05T22:13:28.320

Reputation: 1 889