Rearrangeable Code Bowling

14

4

Code-Bowling Challenge

Write a program or function that produces the same output, no matter how you re-arrange the source code. (Output can't be an error)


Pangram Scoring

  • Your score is the amount of unique characters in your source code.

    A program with source code AJB would have a score of 3
    A program with source code AAJ would have a score of 2
    A program with source code 111 would have a score of 1

  • This is a variant. The program with the highest score wins!

(For your convenience an automated scoring tool has been created here)


Challenge Rules

  1. Input
    The program/function can take an input, that's entirely optional though.

  2. Output
    This output can be anything you want, but it should be non-nil, non-null, non-empty, and non-error. (Therefor output must be at least 1 byte)

  3. Rearrangement
    No matter how the source code is re-arranged, the output should be the same.

    Example:
       Program: ABJ outputs hello world, as does programs: [AJB, JAB, JBA, etc.]

This is a variant. The program with the highest number of characters wins!

Albert Renshaw

Posted 2017-03-18T00:01:48.810

Reputation: 2 955

Must output be in stdout, or could it be a place in memory? – brianush1 – 2017-03-18T00:26:41.610

1Without any specific task to achieve, this challenge is too broad in my opinion. – Dennis – 2017-03-18T00:31:03.773

Is "non-nil" the same as non-zero, or is the literal zero output allowed? – Jonathan Allan – 2017-03-18T00:33:36.957

@JonathanAllan Edited in, output must be at least 1 byte. – Albert Renshaw – 2017-03-18T00:34:49.683

@Dennis I feared requiring a specific output might make it too narrow (If that's a thing haha). The specific task is in the re-arranging of the code in my opinion. – Albert Renshaw – 2017-03-18T00:35:26.460

2What does non-nil mean? – Dennis – 2017-03-18T00:51:34.030

@dennis by non-nil I meant it can't be empty or unassigned. An output of "0" is fine – Albert Renshaw – 2017-03-18T04:35:41.357

2While your pangram scoring is an attempt to make code bowling work, I'm not sure these challenges should really be tagged [tag:code-bowling]. The scoring mechanism is quite different from what code bowling is supposed to be, so I'd say either use [tag:code-challenge] or create a new tag. – Martin Ender – 2017-03-18T11:31:39.193

1

I have to agree with Martin. For example, this challenge isn't a code-golf. As soon as you score by anything besides total number of characters (or bytes), it isn't a code-bowling challenge anymore

– Nathan Merrill – 2017-03-18T12:33:32.737

Non-empty output is clear. What is "unassigned output"? – Nathan Merrill – 2017-03-18T12:35:47.297

3Does the program/function have to end? (e.g. can I print 0 forever?) – MildlyMilquetoast – 2017-03-18T18:16:48.277

1@MistahFiggins The program/function does not have to end. Printing forever is fine – Albert Renshaw – 2017-03-19T20:48:52.883

1@NathanMerrill Unassigned is for programs without an stdout and therefor their output is done in memory, <s>variable assignment</s>, or other. – Albert Renshaw – 2017-03-19T23:28:30.073

@AlbertRenshaw Outputting to a variable is not an allowed output method

– Nathan Merrill – 2017-03-19T23:31:41.467

@NathanMerrill didn't know that, thanks! – Albert Renshaw – 2017-03-19T23:32:14.420

1

The near-infinite scoring answers on this challenge are valid. I am really loving seeing the creative and well-bowled solutions for languages scoring under 100. If anyone has ideas for how to systematically limit near-infinite scoring answers in future code-bowling challenges, feel free to share on this meta post: https://codegolf.meta.stackexchange.com/a/11817/16513

– Albert Renshaw – 2017-03-20T04:49:35.797

Answers

18

Lenguage, 1,112,064 points if UTF-8

My program consists of every possible UTF-8 character. It prints out "Hello world", and uses 1.75 * 1076 yottabytes of space.

(To generate the program, you simply need to make a file with 17498005810995570277424757300680353162371620393379153004301136096632219477184361459647073663110750484 characters, ensuring that each possible UTF-8 character is in the file)

Nathan Merrill

Posted 2017-03-18T00:01:48.810

Reputation: 13 591

2You, sir, are a genius. And wait, why is my computer breaking down? :'P – HyperNeutrino – 2017-03-18T00:43:15.060

I thought that Unicode had 1114112 character? – MilkyWay90 – 2018-11-07T01:01:30.877

14

Many languages, 2 points

0.

Produces 0.0 as 0. or .0. Requires liberal number parsing that's OK with a decimal point at the start or end, assuming 0 for the missing integral or decimal part. 0000000. would give the same score.

This also works in the following languages (in some cases with a different output, as indicated):

  • Python REPL
  • Javascript REPL
  • MATLAB (produces ans = 0)
  • Octave (produces ans = 0)
  • MATL (produces 0)
  • CJam
  • Retina (produces 0)
  • Stacked (produces 0)

For Python, I think this is the only way to get a score above 1, as the possibilities can be exhausted.

  • Any binary or unary operator will fail as the last character
  • Any of [](){} require a match and will fail if the closing one comes first
  • A tabs or space can't start a line. Newlines can't be used in REPL.
  • A , can't be the first character
  • A # placed first would comment everything and produce not output
  • A starting \ is an invalid line continuation
  • Backticks (Python 2) must be paired, and them surrounding nothing is an error
  • $, !, ?, and @ can't be used without other unusable characters

This leaves letters, digits, _, ., and quotes.

  • With quotes, any non-string outside them gives an error.
  • Letters with possible digits and _ makes variable names, of which some permutation always doesn't exists.

The leaves digits and .. Permuting different digits gives a different number unless all the digits are 0. So, I think zeroes and . is the only way to get a score above 1. But, I don't know the Python lexer well, so I could be missing something.

xnor

Posted 2017-03-18T00:01:48.810

Reputation: 115 687

11

CJam, score 15

T U
V	LMOQR[]0q

Try it online!

Always prints 0000:

  • 0 just pushes a zero.
  • T, U, V are variables which are pre-initialised to zero.
  • L, M, O, Q, R are variables which are pre-initialised to an empty list, so they don't show up in the output.
  • [ and ] may or may not wrap things in a list, but they don't have to be matched correctly and the output is flattened for printing anyway.
  • q reads the input which is empty and hence doesn't show up in the output either.
  • linefeed, space and tab are ignored by the parser.

Martin Ender

Posted 2017-03-18T00:01:48.810

Reputation: 184 808

This is a great answer for a language like CJam! Nice – Albert Renshaw – 2017-03-19T20:47:44.293

Could a lowercase r be added accomplishing something similar to the lowercase q? – Albert Renshaw – 2017-03-20T05:09:55.297

1@AlbertRenshaw you can't have both of them, because one will error out on EOF. – Martin Ender – 2017-03-20T06:43:44.960

9

MATL, 3 5 6 points

The idea to add whitespace was taken from Bijan's answer.

lv
 T1

The code, or any permutation thereof, outputs three ones separated by newlines.

Try it online!

Explanation

  • Function l by default pushes number one to the stack.
  • Literal 1 does the same.
  • Literal T pushes true, which is displayed as number one.
  • Space and newline are separators, and here do nothing.
  • v concatenates the whole stack so far into a column vector. So for example v after T would concatenate the first two numbers into a column (and then the next number would be pushed). An initial v would produce an empty array.

At the end of the code, the stack is implicitly displayed, with the following rules:

  • Each element or array in the stack is displayed on a different line.
  • Column vectors are displayed with each element on a different line.
  • The empty array causes no output.

So any permutation of the input characters produces 1 three times in different lines.

Luis Mendo

Posted 2017-03-18T00:01:48.810

Reputation: 87 464

Explanation? I am curious about how this works. – Comrade SparklePony – 2017-03-18T00:18:51.307

@Sparkle Added an explanation – Luis Mendo – 2017-03-18T00:20:06.253

Nice! Also just wanted to note that I had this text in the challenge Removing any part of the source code however should cause that specific output to not be produced. at the time you posted, I did not mean to have it added and it has been removed. Maybe that will help you increase score a tad possibly – Albert Renshaw – 2017-03-18T00:20:17.457

1@AlbertRenshaw Thanks for the heads-up! Two more points – Luis Mendo – 2017-03-18T00:23:13.483

I'm accusing you of stealing my idea. It's not a problem though. – Bijan – 2017-03-18T00:24:36.467

@Bijan Indeed. I'm already mentioning that in my answer – Luis Mendo – 2017-03-18T00:26:23.840

6

Jelly, score 53 101

¶ ¤$¥&+ABDFHNPQSUVX^_aborv|®²×ȧȯḄḅḌḞḢḤḷṀṂṚṛṠṢṪẠạị«»()kquƁƇƊƑƘⱮƝƤƬƲȤɓɗƒɦƙɱɲƥʠɼʂƭʋȥẸẈẒẎŻẹḥḳṇọụṿẉỵẓḋėġṅẏ

Using only characters that are part of Jelly's code-page.

Jelly has implicit input of 0, and the first half (up to and including ạị«») of the string of code above consists mostly of monadic (uppercase) and dyadic (lowercase and symbols) atoms that when given a zero or a list containing only one zero (or two such inputs in the case of dyads) return a zero or a list containing only one zero.

The exceptions are:

  • The space: it is ignored (even though it is in the code-page).

  • The pilcrow, separates links (as does a line feed - but that is really the same byte), but no other bytes will reference the code before it anyway.

  • the scarab, ¤, instructs the parser to treat everything to it's left starting at a nilad (or constant) as a constant (and works as a first atom).

  • the Dollar, $, instruct the parser to treat the two links to it's left as a monad (and, somewhat surprisingly, works as a first atom)

  • the Yen, ¥, similarly instructs the parser to treat the two links to it's left as a dyad.

  • The recommended, ®, recalls the value of the registry, initially 0 (it's counterpart copyright, ©, breaks when used as the very first atom as it is arity is found from the arity of the link to it's left, which is not yet set).

The code from the parentheses, ( and ) and on, are currently unused code points, these all get parsed and each causes a new chain (much like a newline would, although they don't have the effect of creating callable links like a newline, but that's no problem here as nothing tries to do so).

Jonathan Allan

Posted 2017-03-18T00:01:48.810

Reputation: 67 804

1

You can add all characters outside the code page for free, as the interpreter drops them before processing the code. I still don't know what non-nil means though.

– Dennis – 2017-03-18T01:15:09.473

1I think the spirit of the challenge is probably that characters should be on-page. I asked about non-nil and the response was to specify a minimum output of 1-byte. – Jonathan Allan – 2017-03-18T01:24:50.137

@Dennis any idea about the correct terminology for what hapens with the parsing at parentheses? – Jonathan Allan – 2017-03-18T01:33:17.740

All unused characters begin a new link, just as a newline. – Dennis – 2017-03-18T01:59:04.740

@Dennis, yet one cannot seem to "call" the chain to the left of a ( like one can with a newline (they actually seem to break things a little)

– Jonathan Allan – 2017-03-18T02:03:29.510

1Let's call them undefined behavior. :P – Dennis – 2017-03-18T04:11:19.207

4

TI-Basic (83 series), 93 points (99 on a TI-84 Plus)

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZθnπeiAnsrandgetKeyZXsclZYsclXsclYsclXminXmaxYminYmaxTminTmaxθminθmaxZXminZXmaxZYminZYmaxZθminZθmaxZTminZTmaxTblStartPlotStartZPlotStartnMaxZnMaxnMinZnMinΔTblTstepθstepZTstepZθstepΔXΔYXFactYFactTblInputNI%PVPMTFVP/YC/YPlotStepZPlotStepXresZXresTraceStep

All the digits, all the one-byte variables (including θ and n, the independent variables for polar and sequential graphing), the constants π, e, and i, some not-quite-variables (Ans, rand, and getKey), and 59 different window variables (all the ones that are guaranteed to be defined).

Implied multiplication guarantees that the result will be 0 when we take this in any order. If this is running on a fresh calculator, all the variables will be 0; even if not, getKey will be 0 because there's no time to press a key before the program returns a value.

On a TI-84 Plus or higher, we can get 6 more points by adding the tokens getDate, getTime, startTmr, getDtFmt, getTmFmt, isClockOn. The result will now always be {0 0 0} because getDate and getTime return lists of length 3 and the implied multiplication distributes over the elements.

I think these are all the possible tokens to use: any actual commands are prefix, infix, or postfix (meaning they won't work at the beginning or end of the program) and any other variables might be undefined (and cause an error when used).

Misha Lavrov

Posted 2017-03-18T00:01:48.810

Reputation: 4 846

This is clever. Not particularly impressive haha, but clever indeed! +1 – Albert Renshaw – 2018-11-05T23:21:18.080

3

(non-competing) Brainf-ck, 63 bytes

Well, I don't know if this is considered cheating, but...

.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

The dot prints the current character (0x00) and the rest of the characters do nothing. This could technically be expanded infinitely, so please let me know if this is considered cheating.

brianush1

Posted 2017-03-18T00:01:48.810

Reputation: 300

I'd consider that a nil output – Albert Renshaw – 2017-03-18T00:31:48.723

Oh, should I delete my answer then or mark it as non-competing? – brianush1 – 2017-03-18T00:32:11.433

1There are 97 typeable characters, 7 of which you can't use (8-1), so I'd say 90. – Bijan – 2017-03-18T00:32:13.333

@brianush1 you can leave it as non-competing so others can see. I'll edit question a little further to explain output must be at least 1 byte – Albert Renshaw – 2017-03-18T00:34:17.023

15@AlbertRenshaw (sorry for all these comments) If output must be 1 byte, then the NULL character should count, as it is a byte, although one with a value of 0. – brianush1 – 2017-03-18T00:36:23.197

@Bijan At least > can be used, and possibly < as well if we allow the tape to be unbounded in both directions, so the score should be 92. – kennytm – 2017-03-19T21:43:18.703

The PPCG consensus is that answers can only be marked as non-competing if the language is newer than the challenge. Marking an answer as non-competing is not an excuse to keep your answer when it does not meet the question's specs. – Okx – 2017-03-27T10:32:40.173

3

Haskell, 3 points

+ 1

No matter how rearranged this code always returns function which increments input. Examples of usage in repl:

>(+ 1) 1
2
>(1+ ) 1  
2
>( +1) 1
2

Antisthenes

Posted 2017-03-18T00:01:48.810

Reputation: 181

2

√ å ı ¥ ® Ï Ø ¿ , 128,234 (?) points

I arrived at 128,234 with help from @DestructibleLemon. This program uses all Unicode characters (128,237) except o,O and ł. Oddly enough, two of these are output commands.

Surely, though, no language could use all those characters, right? Well this language just ignores the commands it doesn't recognise. Problem solved.

This language will, by default, output the following:

===== OUTPUT =====



==================

which is non-nil, non-null, non-empty and non-error.

Note: if this violates some unwritten rule, notify me in the comments and I'll change this. If you know my score (assuming this is allowed), also post in the comments.

caird coinheringaahing

Posted 2017-03-18T00:01:48.810

Reputation: 13 702

What character set does it use? utf 8? utf-16? Does it use all of unicode? – Destructible Lemon – 2017-03-20T01:57:55.117

@DestructibleLemon Looking on the github page, it seems to use "CP-1252" for the encoding. – brianush1 – 2017-03-20T02:21:57.017

@DestructibleLemon The commands are all in CP-1252 (Windows-1252) but it will accept any Unicode character as valid syntax – caird coinheringaahing – 2017-03-20T07:26:30.947

Apparently, there are 128,237 unicode chars, so, you would have 128,234? https://en.wikipedia.org/wiki/Unicode#cite_note-24

– Destructible Lemon – 2017-03-20T09:15:13.107

According to other answers apparently there are 1,112,064 unicode, so I'm not really sure anymore – Destructible Lemon – 2017-03-20T21:18:56.390

1

///, 1 2 points

\_

Try it online!

I have no clue how to do it in any other Turing-complete language. Of course, there is HQ9, but that just feels cheaty.

1 byte thanks to @Martin Ender.

Comrade SparklePony

Posted 2017-03-18T00:01:48.810

Reputation: 5 784

this should be two points not bytes – Destructible Lemon – 2017-03-20T01:54:47.783

@DestructibleLemon Sorry, TIO formatting. – Comrade SparklePony – 2017-03-20T13:41:05.320

1

J, 3 bytes

 1

The chars 1, space and newline will always print 1.

Bijan

Posted 2017-03-18T00:01:48.810

Reputation: 781

1

Dots, 1,114,111 characters (if using unicode).

<87 dots here> Every Unicode character except NUL and . here

Explanation:

1                                           leading binary number
1010                                        010 increments the value under the pointer
1010111                                     111 prints out chr(1)

So the resulting binary string is 1010111, which converted to decimal is 87, so we need 87 dots.

Every other character is a comment, so we use every character except a NUL, because Python3 stops reading the file then, and a dot, because dots aren't comments.

MilkyWay90

Posted 2017-03-18T00:01:48.810

Reputation: 2 264

0

Prelude, score 1,112,051

(When only considering the printable ASCII [\t\n -~], the score is 84. If we consider all Unicode code-points, the score is 1,112,051.)

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

(then append all characters [\u{7f}-\u{10ffff}] after it.)

Always print 0.


Prelude is a parallel stack-based language, where the stack is pre-filled with infinite numbers of 0s.

  • +: Pop two values (always 0), add them (0), and push to stack.
  • -: Pop two values (always 0), subtract them (0), and push to stack.
  • #: Pop a value and discard it.
  • !: Pop a value and output it as a number (always 0) (spec says "character" but interpreter says "number"; either case, a byte is printed)
  • 0: Pushes 0.
  • ^, v, V: Pushes the top value of the previous/next parallel programs ("voices"), but the stacks of all "voices" are filled with 0, so they always push 0.
  • other characters: no-op.

So there are only 13 characters we need to avoid:

  • (, ): Unpaired parenthesis will cause error
  • 19: We only want to output 0.
  • ?: We don't want to input anything.
  • *: Causes very complicated consistency check for the code before and after a line consisting of a lone *. So we need to either remove the new line or remove the *. The reference implementation uses Python 2's .readline() which a "new line" could mean \r or \n. So it is better to just remove the *.

kennytm

Posted 2017-03-18T00:01:48.810

Reputation: 6 847

0

Deadfish, score 86

o.ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghjklmnpqrtuvwxyz?!|[]_-();'"*&^$#@!1234567890+=<>,/\:

If that's illegal, then there's also

o

(score 1)

snorepion

Posted 2017-03-18T00:01:48.810

Reputation: 43