14
\$\begingroup\$

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!

\$\endgroup\$
17
  • 3
    \$\begingroup\$ Without any specific task to achieve, this challenge is too broad in my opinion. \$\endgroup\$
    – Dennis
    Mar 18, 2017 at 0:31
  • 2
    \$\begingroup\$ What does non-nil mean? \$\endgroup\$
    – Dennis
    Mar 18, 2017 at 0:51
  • 2
    \$\begingroup\$ While your pangram scoring is an attempt to make code bowling work, I'm not sure these challenges should really be tagged code-bowling. The scoring mechanism is quite different from what code bowling is supposed to be, so I'd say either use code-challenge or create a new tag. \$\endgroup\$ Mar 18, 2017 at 11:31
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ Mar 18, 2017 at 12:33
  • 3
    \$\begingroup\$ Does the program/function have to end? (e.g. can I print 0 forever?) \$\endgroup\$ Mar 18, 2017 at 18:16

14 Answers 14

18
\$\begingroup\$

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)

\$\endgroup\$
2
  • 2
    \$\begingroup\$ You, sir, are a genius. And wait, why is my computer breaking down? :'P \$\endgroup\$
    – hyper-neutrino
    Mar 18, 2017 at 0:43
  • \$\begingroup\$ I thought that Unicode had 1114112 character? \$\endgroup\$
    – MilkyWay90
    Nov 7, 2018 at 1:01
14
\$\begingroup\$

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.

\$\endgroup\$
0
11
\$\begingroup\$

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.
\$\endgroup\$
3
  • \$\begingroup\$ This is a great answer for a language like CJam! Nice \$\endgroup\$ Mar 19, 2017 at 20:47
  • \$\begingroup\$ Could a lowercase r be added accomplishing something similar to the lowercase q? \$\endgroup\$ Mar 20, 2017 at 5:09
  • 1
    \$\begingroup\$ @AlbertRenshaw you can't have both of them, because one will error out on EOF. \$\endgroup\$ Mar 20, 2017 at 6:43
9
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ Explanation? I am curious about how this works. \$\endgroup\$
    – sporkl
    Mar 18, 2017 at 0:18
  • \$\begingroup\$ @Sparkle Added an explanation \$\endgroup\$
    – Luis Mendo
    Mar 18, 2017 at 0:20
  • \$\begingroup\$ 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 \$\endgroup\$ Mar 18, 2017 at 0:20
  • 1
    \$\begingroup\$ @AlbertRenshaw Thanks for the heads-up! Two more points \$\endgroup\$
    – Luis Mendo
    Mar 18, 2017 at 0:23
  • \$\begingroup\$ I'm accusing you of stealing my idea. It's not a problem though. \$\endgroup\$
    – Bijan
    Mar 18, 2017 at 0:24
6
\$\begingroup\$

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

\$\endgroup\$
6
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Dennis
    Mar 18, 2017 at 1:15
  • 1
    \$\begingroup\$ I 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. \$\endgroup\$ Mar 18, 2017 at 1:24
  • \$\begingroup\$ @Dennis any idea about the correct terminology for what hapens with the parsing at parentheses? \$\endgroup\$ Mar 18, 2017 at 1:33
  • \$\begingroup\$ All unused characters begin a new link, just as a newline. \$\endgroup\$
    – Dennis
    Mar 18, 2017 at 1:59
  • 1
    \$\begingroup\$ Let's call them undefined behavior. :P \$\endgroup\$
    – Dennis
    Mar 18, 2017 at 4:11
4
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ This is clever. Not particularly impressive haha, but clever indeed! +1 \$\endgroup\$ Nov 5, 2018 at 23:21
3
\$\begingroup\$

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

\$\endgroup\$
7
  • \$\begingroup\$ I'd consider that a nil output \$\endgroup\$ Mar 18, 2017 at 0:31
  • \$\begingroup\$ Oh, should I delete my answer then or mark it as non-competing? \$\endgroup\$
    – brianush1
    Mar 18, 2017 at 0:32
  • 1
    \$\begingroup\$ There are 97 typeable characters, 7 of which you can't use (8-1), so I'd say 90. \$\endgroup\$
    – Bijan
    Mar 18, 2017 at 0:32
  • \$\begingroup\$ @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 \$\endgroup\$ Mar 18, 2017 at 0:34
  • 15
    \$\begingroup\$ @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. \$\endgroup\$
    – brianush1
    Mar 18, 2017 at 0:36
3
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

√ å ı ¥ ® Ï Ø ¿ , 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.

\$\endgroup\$
5
  • \$\begingroup\$ What character set does it use? utf 8? utf-16? Does it use all of unicode? \$\endgroup\$ Mar 20, 2017 at 1:57
  • \$\begingroup\$ @DestructibleLemon Looking on the github page, it seems to use "CP-1252" for the encoding. \$\endgroup\$
    – brianush1
    Mar 20, 2017 at 2:21
  • \$\begingroup\$ @DestructibleLemon The commands are all in CP-1252 (Windows-1252) but it will accept any Unicode character as valid syntax \$\endgroup\$ Mar 20, 2017 at 7:26
  • \$\begingroup\$ Apparently, there are 128,237 unicode chars, so, you would have 128,234? en.wikipedia.org/wiki/Unicode#cite_note-24 \$\endgroup\$ Mar 20, 2017 at 9:15
  • \$\begingroup\$ According to other answers apparently there are 1,112,064 unicode, so I'm not really sure anymore \$\endgroup\$ Mar 20, 2017 at 21:18
1
\$\begingroup\$

J, 3 bytes

 1
 

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

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ this should be two points not bytes \$\endgroup\$ Mar 20, 2017 at 1:54
  • \$\begingroup\$ @DestructibleLemon Sorry, TIO formatting. \$\endgroup\$
    – sporkl
    Mar 20, 2017 at 13:41
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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 *.
\$\endgroup\$
0
\$\begingroup\$

Deadfish, score 86

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

If that's illegal, then there's also

o

(score 1)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.