text:
Basic ASCII Tallies
Alternate Title: Tally Your Prison Sentence on the Wall
Given a number n, output tallies grouped into the traditional 5-per-group and 50 per row.

Examples
1
|
|
|
|

4
||||
||||
||||
||||

5
|||/
||/|
|/||
/|||

6
|||/ |
||/| |
|/|| |
/||| |

50
|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /|||

51
|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /|||

|
|
|
|

256
|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /|||

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /|||

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /|||

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /|||

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /|||

|||/ |
||/| |
|/|| |
/||| |

Rules

5 tallies per group, 50 total tallies per row.
The first 4 tallies are vertical, the 5th tally crosses all other tallies.

Each of the first four consist of 4 vertical | characters.
The final 5th tally spans all 4 of the first, with a / character, diagonally.

Each group should be separated by a space, each row a blank newline.
The constraints on n are: 0 <= n <= 1000 (for simplicity).
Trailing spaces and newlines are fine, preceding are not.
This is code-golfascii-art, lowest byte-count wins.

Reviewed by ~4 people in the sandbox.

P.S. fun little tid-bit, the average number of tallies per row in prison was 50, hence the alt. title.

Related

Great challenge, complex yet simple.

@ATaco I really want to find the solution that aggregates the slashes in the "big picture", and takes into account that the slash pattern can be inferred by row (that's the easy win).

Thank you so much for making them forward slashes instead of backward slashes.

@totallyhuman  Oh god, the guy in the image I posted does... WHAT UNIVERSE IS THIS? It's the Bernstein bears all over again... Did the coin land on heads or tails to decide the most recent US election?!

Charcoal, 30 25 bytes
ＦＮ«Ｊ﹪ι⁵⁰×⁵÷ι⁵⁰¿﹪⊕ι⁵↓⁴«←↙⁴

Try it online! Link is to verbose version of code. Explanation:
 Ｎ                          Input number
Ｆ «                         Loop over implicit range
     ι     ι                Loop index
      ⁵⁰    ⁵⁰              Literal 50
    ﹪                       Modulo
          ÷                 Integer divide
         ⁵                  Literal 5
        ×                   Multiply
   Ｊ                        Jump to column, row
                 ι          Loop index
                ⊕           Incremented
                  ⁵         Literal 5
               ﹪            Modulo
              ¿             If
                   ↓⁴       Print 4 `|`s downwards
                     «      Implicit else
                      ←     Move left
                       ↙⁴   Print 4 `/`s down and left

Funky, 156 132 133 bytes
n=>{k=n=>((l="|"::rep)(3-i)+"/"+l(i)+" ")::rep(n)p=print L=f=>fori=0i<4i++p(f())forc=0c<n//50c++{L@k(10);p()}L@k((m=n%50)//5)+l(m%5)}

Try it online!

Funky is a... What now? Interesting. Never seen this language on any of my challenges before.

@MagicOctopusUrn Probably because I wrote it :P

A JavaScript based language? Dangerous. But that's okay, I love danger.

fori=0i<4i++p(f())forc=0c<n//50c++ what is this unholy beast taking the name of syntax

@totallyhuman "It's like you took the overeager type deduction schemes from JS and PHP and applied them to the whole language's syntax "

Haskell, 117 bytes
f m|m<1=""|n<-min 50 m=unlines[[last$"| "!!(0^c%5):['/'|r+c%5==4,n-n%5>c]|c<-[1..n]]|r<-[0..3]]++'\n':f(m-50)
(%)=mod

Try it online!

Jelly, 37 bytes
:5[“|||/”]ẋ;”|ẋ⁸%5¤¤W¤ṙ€4Ḷ¤s⁵Z€G€j⁾¶¶

Try it online!
Explanation
:5[“|||/”]ẋ;”|ẋ⁸%5¤¤W¤ṙ€4Ḷ¤s⁵Z€G€j⁾¶¶  Main Link
:5                                     Floordiv by 5
  [“|||/”]ẋ                            Repeat ["|||/"] by this number
           ;                           Append
            ”|ẋ    ¤                   "|" repeated by
               ⁸%5¤                    The argument modulo 5
                    W¤                 Then wrapped to prevent weirdness
                      ṙ€               Rotate each tally segment by
                        4Ḷ¤            (each) [0, 1, 2, 3]
                           s⁵          Slice into pieces of length 10 (to get 50 per row)
                             Z€        Transpose each
                               G€      Convert each into a grid
                                 j⁾¶¶  Join these grids by a double newline

wheee this is too long

Husk, 29 bytes
J;øṀṪṙŀ4C10§:oR"|||/"÷5oR'|%5

Try it online!
I feel like the first 5 is redundant, but removing it gives a type error...
Explanation
J;øṀṪṙŀ4C10§:oR"|||/"÷5oR'|%5  Implicit input, an integer n.
                       oR'|    Repeat the character '|'
                           %5  n mod 5 times.
             oR"|||/"          Repeat the string "|||/"
                     ÷5        n/5 times.
           §:                  Tack the '|'-string to the end of that list.
        C10                    Cut the list of strings into pieces of length 10.
   Ṁ                           For each piece,
    Ṫ ŀ4                       for each k in [0,1,2,3],
     ṙ                         rotate each string k steps to the left
                               and collect the results into a list.
                               Now we have a list of lists of lists of strings.
J;ø                            Join them with the list [[]].
                               Implicitly join each list of strings by spaces,
                               then join the resulting list of strings by newlines,
                               and print the result.

J, 50 48 45 35 33 bytes
_50|:\'|/ '{~[{.(|.2,=i.4)$~]-5|]

Try it online!
                (    =i.4)          Identity matrix of size 4.
                (  2,    )          Prepend a row of 2s.
                (|.      )          Upside down.
                          $~        Take __ rows.
                            ]-5|]   Input rounded down to a multiple of 5.
             [{.                    Pad with rows of zeroes to [input] rows.
      '|/ '{~                       Get the characters.
_50|:\                              Transpose and fit to width.

I love the idea of using infixes for this part 4,&' '\7$'|||/'

@Jonah it had to go :(

JavaScript (ES6), 139 137 bytes
n=>eval('s="";for(i=0;i++<=n/50;s+=N)for(j=5;--j;s+=N=`\n`)for(k=0;k<(x=(y=n-i*50)<0?50+y:50);)s+=++k%5?k%5-j|k>5*(x/5|0)?"|":"/":" ";s')

Returns a string with one trailing newline when n is not a multiple of 50 and one with several trailing newlines when n is a multiple of 50.
Ungolfed
n=>{
    s=""
    for(i=0; i++ <= n/50; s+=N)
        for(j=5; --j; s+=N=`\n`)
            for(k=0; k < (x = (y = n-i*50) < 0 ? 50+y : 50);)
                s += ++k%5 ?
                    k%5-j|k>5*(x/5|0) ?
                        "|"
                    : "/"
                : " "
    return s
}

Test Snippet

f=
n=>eval('s="";for(i=0;i++<=n/50;s+=N)for(j=5;--j;s+=N=`\n`)for(k=0;k<(x=(y=n-i*50)<0?50+y:50);)s+=++k%5?k%5-j|k>5*(x/5|0)?"|":"/":" ";s')

;(I.oninput=_=>O.innerText=f(+I.value))(I.value=76)
<input id=I type=number>

Non-eval solution, 150 bytes
n=>(A=(v,m)=>j=>[...Array(v).keys()].map(m).join(j))(n/50+1|0,i=>A(4,j=>A(x=(y=n+~i*50)<0?50+y:50,k=>++k%5?k%5-4+j|k>5*(x/5|0)?"|":"/":" ")``)`
`)`

`

Possibly able to golf this one further but the eval method has been shorter so far.

Took me a solid 10 minutes to work through the ungolfed version and understand it. =^P You've got some nice tricks in there.

pretty sure you can do for(i=0; ++i < n/50; s+=N) which saves one char

@DanielIndie That fails because the outer loop runs one too few times: Try it online!

SOGL V0.12, 33 bytes
ā.{┐4∙F5\?X1w⁄3-14╚╬5@}┼FM»\?O¶oā

Try it Here!
Golfing on a phone is hard..
Explanation:
ā                                  push an empty array
 .{                                repeat input times
   ┐4∙                               push a 4 tall line
      F5\?            }              if the counter (1-indexed) divides by 5
          X                            pop that vertical line
           1w⁄                         get the width of the main array
              3-                       subtract 3 from that width - X position
                1                      push 1 - Y position
                 4╚                    push a 4 long diagonal
                   ╬5                  place that in the main array at [width-3; 1]
                     @                 push a space - for the below to add spacing
                       ┼             append horizontally
                        FM»\?        if the counter divides by 50
                             O         output the main array
                              ¶o       output a newline
                                ā      push a new array
                                       (note that the outputting here doesn't disable
                                       implicit outputting)

Python, 129 113 112 108 bytes
f=lambda n:n>50and f(50)+"\n\n"+f(n-50)or"\n".join(n//5*("|||/|||"[k:k+4]+" ")+" "+n%5*"|"for k in range(4))

Explanation
def p(n):
  if n > 50:
    return p(50) + "\n\n" + p(n-50) # Handle 50-groups recursively
  else:
    # For each of the 4 lines:
    rows = []
    for row in range(4):
      #  - Build the "|||/"-blocks by slicing the correct part of "|||/|||".
      #  - Do that n/5 times
      #  - Then add "|" n%5 times
      rows += [("|||/|||"[row:row+4]+" ")*(n//5) + " " + "|"*(n%5)]

    # Join the four rows together
    return "\n".join(rows)

Works in Python 2 and 3.
Try it online

Rearranging multiplications to get rid of parenthesis brings you down to 108 bytes total

@movatica nice, thanks!

C (gcc), 170 bytes
char*s="|||/ \0||/| \0|/|| \0/||| \0";h;k;g(x){for(h=0;h<5;h++){for(k=x;k>4;k-=5)printf(s+6*h);for(;k&&h-4;k--)printf("|");putchar(10);}}f(x){for(;x>49;x-=50)g(50);g(x);}

Try it online!
f is a function taking a nonnegative integer (x) and printing that many tallies, grouped as specified, to stdout
g is a helper function that prints x tallies, grouped by 5, without splitting lines.
f calls g(50) and decrements x by 50 until it is less than 50, then calls g(x) to print the remaining tallies on one line.
s is a char* such that, as strings, s is the first row of a bundle, s+6 is the second, s+12 is the third, and s+18 is the fourth, and s+24 is an empty string.
g(x) prints bundles and decrements x by 5 until x is less than 5, then prints x single tallies.

135 bytes

Python 2, 142 bytes
n=input()
while n>0:print"\n".join("".join("|/ "[2*(j%5>3)+(n/(5*(j/5+1))and 3-i==j%5)]for j in range(min(50,n)))for i in range(4)),"\n";n-=50

Try it online!

142 bytes in 18 minutes? Not bad :).

Got to work quick when you should really have gone to bed an hour ago

Quick ~= Quality ;). Nice job.

Errr... that may be misconstrued. Saying you did quality work fast... Not the opposite.

138 bytes

Perl 5, 103 bytes
$a=<>;do{$_=$a<50?"|||/ "x($a/5).'|'x($a%5):"|||/ "x10;for$i(1..4){say;s%\|/%/|%g}say""}while($a-=50)>0

Try it online!

Haskell, 134 bytes
f#n=unlines$(concat.f.(<$[1..n`div`5]))<$>["|||/ ","||/| ","|/|| ","/||| "]
f n|n>50=id#50++'\n':f(n-50)|1>0=(++['|'<$[1..n`mod`5]])#n

Try it online!
asdfghjkl-- Yeah, I'm working on it.

PHP, 138 141+1 bytes
probably not the shortest possible solution
for(;0<$z=50+min($n=$x=$y=0,$argn-=50);print"
")while($n++<$z||!$x=+(3<$y+=$n=print"
"))echo"/| "[$n%5?($y+$x++)%4<3|$n%5+$y<4|$z-$z%5<$n:2];

Run as pipe with -nR or try it online.

Neat! But from the second tally-line on the tallies are not crossed completely.

When running your "try it online" example from 5.5 on, locally 5.6.31 and 7.1.9.

$x is only undefined in first loop, this messes up output for tally greater than 54. Fixed, but not golfed: http://sandbox.onlinephpfunctions.com/code/aad4fad0617cdb677556ed9c1f5cb9d26fd72726

@SpazzMarticus fixed

Cool! It was my first time debugging golfed code, you gave me a hard time! :) I think I'm hooked!

05AB1E, 28 bytes
5‰"|||/"¬‚×J4ôTôεε3Ý._}ø»¶«,

Try it online.
Explanation:
5‰              # Divmod the (implicit) input-integer by 5
                #  i.e. 111 → [22,1]
  "|||/"        # Push string "|||/"
        ¬       # Push its first character (without popping the string itself): "|"
         ‚      # Pair them together: ["|||/","|"]
          ×     # Repeat it based on the divmod
                #  i.e. [22,1] → ["|||/|||/|||/...|||/|||/|||/","|"]
           J    # Join everything together to a single string
                #  → "|||/|||/|||/...|||/|||/|||/|"
            4ô  # Which is then split into block of size 4
                #  → ["|||/","|||/","|||/",...,"|||/","|||/","|||/","|"]
Tô              # Then split this list into sublists of size 10
                #  → ["|||/","|||/","|||/",...],[...,"|||/"],["|||/","|||/","|"]]
  ε             # For-each over the sublists:
   ε            #  Map over the strings in the sublist:
    3Ý          #   Push list [0,1,2,3]
      ._        #   For each: rotate the string that many times
                #    ("|||/" → ["|||/","||/|","|/||","/|||"])
   }ø           #  After the map: zip/transpose; swapping rows/columns
     »          #  Join each inner list by spaces, and then the strings by newlines
      ¶«        #  Append a newline to each string
        ,       #  And print with trailing newline

¶«, of course has a few possible equal-bytes alternatives, like ,¶? or ,õ,.

Uiua, 61 60 59  bytes
≡(&p""≡&p⊏:"/| "/≡(⊂⊂:2))⬚2↯∞_10_4_4⊂↯:⇌⊞≠.⇡4:↯4+1≤⇡4:⌊⊃÷◿5

Try it
I think there is likely a somewhat shorter method. I did try porting Kevin Cruijssen's 05AB1E solution, but it came out a little longer and didn't work in a few cases.
The basic idea is to do division with remainder by 5, use the remainder make the final tally group, and repeat a full tally group by the division result, and combine them to make one array of 4x4 arrays.
In order to format this to lines of 50, first reshape it to an array of 10 columns of 4x4s. Then join each line of each row by spaces. Finally print each line of the row with a newline, and then print just a newline after the line.

Pip, 47 46 bytes
Wa-:yP('|X4.sRA3-_'/M,4)X(YMN[a50])/5.'|Xy%5.n

Try it online!
Explanation
        Implicit: a is 1st cmdline arg, y is "", s is space, n is newline
W       While loop:
 a-:y   Each iteration, subtract y from a and check if a is still nonzero
        (Since "" is 0 in numeric contexts, this does nothing the first time through)
     P  Print the following:

('|X4.sRA3-_'/M,4)X(YMN[a50])/5.'|Xy%5.n
              M                           Map this function to each number in
               ,4                         range(4):
 '|X4                                      String of four pipe characters
     .s                                    Concatenate a space
       RA                                  Replace the character at index
         3-_                                (3 minus function argument)
            '/                              with forward slash

                                          We now have a list of four strings representing
                                           the rows of a group of 5 tally marks; the
                                           following operations apply to the list
                                           element-wise:

                       [a50]              List of a (number of remaining tallies) and 50
                     MN                   Get the min (number of tallies on this row)
                    Y                     Yank it into y
                   (        )/5           Divide by 5 (number of groups on this row)
(                )X                       String-multiply by that amount
                                   y%5    Number of leftover tallies on this row
                                '|X       String-multiply that many pipes
                               .          Concatenate
                                      .n  Concatenate a newline

The resulting list will be something like this:
["|||/ ||\n" "||/| ||\n" "|/|| ||\n" "/||| ||\n"]

By default, P concatenates the contents of the list together and outputs them with a trailing newline. Thus, we get
|||/ ||
||/| ||
|/|| ||
/||| ||

with two trailing newlines (one from the list contents and one added by P). If there is another row to be printed, this gives the requisite blank line in between.

Java (OpenJDK 8), 188 bytes
i->{int j=0,l,k;String r="";for(;j<~-i/50+1;j++,r+="\n")for(l=0;l<4;l++,r+="\n")for(k=0;k<(j*50+50>i?i-j*50:50);k++)r+=k%5>3?" ":k%5==3-l?"/":"|";return r.replaceAll("/(?=(\\|*\n))","|");}

Try it online!

179 bytes

Ruby, 100 bytes
->n{(n/-50*-4).times{|i|j=[n-i/4*50,50].min
$><<("|||/|||"[i%4,4]+" ")*(j/5)+?|*(j%5)+$/*(1+i%4/3)}}

Commented
->n{(n/-50*-4).times{|i|              #Calculate rows of tallies (Ruby rounds division towards negative infinity. Multiply by 4 lines per tally and iterate through them.)
  j=[n-i/4*50,50].min                 #Number of strokes printed in current row is either the number remaining, or 50, whichever is less
    $><<("|||/|||"[i%4,4]+" ")*(j/5)+ #Send to stdout the correct 4 chars selected from "|||/|||" plus a space, j/5 times (rounded down, which eliminates odd strokes.)
    ?|*(j%5)+                         #If there are any odd strokes, add them to the output
    $/*(1+i%4/3)                      #followed by a newline (2 for the final line of each row of tallies.)
  }
}

Try it online!

Canvas, 30 bytes
Ｈ╷‾#％╵¹‾#÷Ｕ╷５×¹５％？４|＊］；４－；４／｝╋

Try it here!

C (gcc), 107 106 105 bytes
i,j;f(n){for(;n>50;f(50))n-=50;for(i=5;--i;)for(j=0;putchar(j++-n?j%5?(j-i)%5|n-j<n%5?'|':47:32:10)%5;);}

Try it online!
-1 thanks to ceilingcat
-1 again from ceilingcat

Stax, 24 bytes
⌐å9☼,▄█┌`╕G╛ï╞▬Gpƒ\╜ª_N╬

Run and debug it

Vyxal L, 169 bitsv2, 21.125 bytes
4ẋ5ẇƛ\|*₅5=[ḢėṘƛ÷$\/Ȧ;ðwj

Try it Online!

It doesn’t seem to work

@noodleman interesting. Something must have been changed in the code base since it was posted, as it worked at the time of posting

Evidently, since I upvoted it when you posted it and I doubt I would upvote a clearly non-working solution.

Befunge, 125 105 bytes
$&:!#@_:::"2"v>*\5%4\`+1g1-,1+:14g\`#v_55+,$:#v_55+,
!}0:+*`"2"\-\<^!-g01%5\!`g41+5*5/5:::<0p01:-1<<<4-p4

Try it online!

JavaScript (Node.js), 99 bytes
f=n=>n>50?f(50)+f(n-50):(g=j=>j-204?[(x=++j%51)?x%5&&x<=n?j%5-4|j%50>n?'|':'/':' ':`
`]+g(j):`
`)``

Try it online!

Scala 3, 138 bytes
A port of @Lukas Boersma's Python answer in Scala.

Golfed version. Attempt This Online!
def p(n:Int):String=if(n>50)p(50)+"\n\n"+p(n-50)else(0 to 3).map{r=>(("|||/|||".substring(r,r+4)+" ")*(n/5)+" "+"|"*(n%5))}.mkString("\n")

Ungolfed version. Attempt This Online!
object Main {
  def p(n: Int): String = {
    if (n > 50) {
      p(50) + "\n\n" + p(n - 50) // Handle 50-groups recursively
    } else {
      // For each of the 4 lines:
      val rows = (0 until 4).map { row =>
        //  - Build the "|||/"-blocks by slicing the correct part of "|||/|||".
        //  - Do that n/5 times
        //  - Then add "|" n%5 times
        (("|||/|||".substring(row, row + 4) + " ") * (n / 5)) + " " + "|" * (n % 5)
      }

      // Join the four rows together
      rows.mkString("\n")
    }
  }

  def main(args: Array[String]): Unit = {
    println(p(256))
  }
}


text:
The thousand character classic
Background
The Thousand Character Classic is a chinese poem written around the 4th Century CE in China, and memorized by large populations since then. The name comes from not only its length, but its number of characters: each character occurs only once in the text. It is commonly used to teach children chinese characters, and also, because of its commonness, as a means of enumerating the 1000 characters in the text.
The challenge
Here is a copy of the Thousand Character Classic, gotten from Wikipedia.
The Thousand Character Classic
Reproduce the entirety of the Thousand Character Classic in either UTF-8 or UTF-16, including punctuation, newlines, and heading numbers. Punctuation can be halfwidth or fullwidth, and the trailing newline is optional.
For those that want to analyze the unicode text for patterns, I've provided hexdumps of both encodings.
utf-8
utf-16
Rules
Because of the size of the text to reproduce, you may optionally supply a file for your submission to use as input. If this is done, add the byte length of the input file to the byte length of your code.
Otherwise, this is a standard issue code golf challenge, so standard loopholes apply, and shortest submission wins.

Your link is probably encoded in something other than Unicode.

@EriktheOutgolfer It's in UTF-8.

Chrome isn't able to correctly infer a character encoding.  I had to use a plugin to force UTF-8, as the option as apparently been removed(!?)

Can you post an english translation.

Also... you may optionally supply a file...? Groovy: {it.text} where it is a file containing the 1,000 line classic.

File length is added to code length in that case.

Bubblegum, 2526 bytes
00000000: 2dd4 47c2 82cc 9680 e1f9 b78a de42 e7ed  -.G..........B..
00000010: 898a 808a 3921 28e6 0ca8 1830 e162 9a13  ....9!(....0.b..
00000020: 6ad4 5bb8 50fe e3e7 bc86 4aff fe07 8b2d  j.[.P.....J....-
00000030: 3847 aa15 c5ab f0ff ef2a f81a f816 5e76  8G.......*....^v
00000040: 6cb6 fe2f 97ff b73f ec2f d1d1 c9d6 7190  l../...?./....q.
00000050: 39c7 47f0 bfa0 f7e1 7d95 0e41 2b89 4b38  9.G.....}..A+.K8
00000060: 6c42 9c4b 9dd6 15ec dca0 74e0 7e5d bae8  lB.K......t.~]..
00000070: d5c5 6280 7a03 bd73 ea10 57a0 99e7 dd57  ..b.z..s..W....W
00000080: 589f 9fdb 67b1 39b2 7611 f626 75e1 9ce9  X...g.9.v..&u...
00000090: daa0 fc53 38ce cfb5 2675 5cf1 ece3 f192  ...S8...&u\.....
000000a0: 3ad5 0cd0 9e70 69c2 792a 1dca 265b 2edc  :....pi.y*..&[..
000000b0: 37a2 dfcd bc3e a1cd 0916 0ea8 8674 1c3b  7....>.......t.;
000000c0: 5437 7154 43f7 983a d71d a199 5c5e c2da  T7qTC..:....\^..
000000d0: f9f9 f50e ad08 cf21 dea7 a98b 531f 3f36  .......!....S.?6
000000e0: c51f fa76 a4ff c79f 884d 88f6 a4ec 211a  ...v.....M....!.
000000f0: 6513 e112 fc41 f27c d250 9313 b0ae 807e  e....A.|.P.....~
00000100: c39e 065e 3ff5 e451 40c7 e4e9 9ce7 a174  ...^?..Q@......t
00000110: ac6d 928f c97e 1b9c 4aea e818 6c8d 8575  .m...~..J...l..u
00000120: 834e 433a bc3b 786c 26ef 067d 76a9 4373  .NC:.;xl&..}v.Cs
00000130: 43d6 1bfd 3b3e 829f 8f1a e88c a05b 174a  C...;>.......[.J
00000140: 3bf3 711e 2b27 7884 b49f 48c7 a2cd f9b3  ;.q.+'x...H.....
00000150: 78d5 c4aa 973a 6bf3 e45d 47bd 4671 55ba  x....:k..]G.FqU.
00000160: 501a 22af 2551 4eec 3b72 0535 0edb e845  P.".%QN.;r.5...E
00000170: 54ab fc3c bc88 3004 6743 fb47 e6d6 47ac  T..<..0.gC.G..G.
00000180: 5b62 eec2 e422 1daa 3d9e edd9 34d0 d9a4  [b..."..=...4...
00000190: cee1 05ea 656e 1cb0 f790 fe9f 7fdc aea0  ....en..........
000001a0: b7e0 e75e ecfd 7402 6c1b 16eb e4d9 8128  ...^..t.l......(
000001b0: 9213 a878 5870 c578 2216 e5d4 f9a4 6377  ...xXp.x".....cw
000001c0: 8641 0ef2 77e9 b00c 51ed f279 4c57 2775  .A..w...Q..yLW'u
000001d0: eadc b1ab a361 b211 4827 7729 941a 7c55  .....a..H'w)..|U
000001e0: ec3c e419 ea73 e1c3 b53d 7c07 3fff 7478  .<...s...=|.?.tx
000001f0: afc1 e74d ae97 ba18 4d51 29c0 fd24 ba77  ...M....MQ)..$.w
00000200: e9c9 779a 7cbe 500f 7855 ca7a 6b83 87b3  ..w.|.P.xU.zk...
00000210: b0e7 42ab 4b87 d906 f367 ba9e d16d a7ce  ..B.K....g...m..
00000220: db2d fb43 8a3b 1497 a5a3 15f0 b44a 378f  .-.C.;.......J7.
00000230: c359 d6ab 15f8 5e93 8fc3 4a4f 3ac4 7778  .Y....^...JO:.wx
00000240: 3da1 61d2 be92 f967 46fb b4d8 a037 974e  =.a....gF....7.N
00000250: db27 1fef 900f 5939 a7ce 960d 933c 7d5b  .'....Y9.....<}[
00000260: ac7c 7ebe 32c1 9e60 614a 5b33 755a d5e9  .|~.2..`aJ[3uZ..
00000270: 3e87 5e11 d59b 7438 3ea9 b516 a331 04b7  >.^...t8>....1..
00000280: d421 8884 75c4 4140 fb9f 73a8 917e 4b9e  .!..u.A@..s..~K.
00000290: 1568 d8a9 a37d 84e1 8575 0dbb 07e9 e08d  .h...}...u......
000002a0: a87b a3bd 07e5 cce1 3b01 4323 7b0a cd8f  .{......;.C#{...
000002b0: 74d6 3678 3fc1 69c9 bd62 e60b 8b75 1d9f  t.6x?.i..b...u..
000002c0: 7bd0 cad2 93f7 9b07 1ef6 02b1 da64 beca  {............d..
000002d0: e328 4e1e 15b2 6de9 701f e155 4922 1395  .(N...m.p..UI"..
000002e0: 2075 bc5f 312e 42bd 8783 c9cf fd07 7a33   u._1.B.......z3
000002f0: ae2c 3137 4a9d 3739 8e3d f00d f087 d229  .,17J.79.=.....)
00000300: 5880 3ee2 dd84 e25a d6ab 35ba e6c1 7792  X.>....Z..5...w.
00000310: d742 3aae 7c5c 7a68 e4c0 7d66 7ddf a0ce  .B:.|\zh..}f}...
00000320: 908a 53da bbd2 c18b a0b8 23eb 95bc ba59  ..S.......#....Y
00000330: df19 b172 8778 8c9d ef3f 3e48 5e4b ea0c  ...r.x...?>H^K..
00000340: 703e 491d 6a2f ce55 c92e f376 221d 3779  p>I.j/.U...v".7y
00000350: f4cb 7cbe 70b8 90eb ef83 be84 6319 cca6  ..|.p.......c...
00000360: f424 2a43 ab9a 4415 1aad e4fa eca1 7382  .$*C..D.......s.
00000370: ed4a 0c37 d261 d183 7a1f f22a 6fda 99ab  .J.7.a..z..*o...
00000380: 4b58 1a18 9850 cc49 e77d 04eb 66f2 0ea0  KX...P.I.}..f...
00000390: 2e6f 60f5 065e 0383 0ea8 2de9 e075 50bb  .o`..^....-..uP.
000003a0: 835a 84b7 9bf5 8d2a 1ee7 2237 c7c9 437a  .Z.....*.."7..Cz
000003b0: f25c 40bd 82e5 2ee8 a5cc 758d e61b f22f  .\@.......u..../
000003c0: bcaa fffc a5a0 aa8b e109 0baf d445 6e82  .............En.
000003d0: 8729 bcfb c29e 49a7 2047 f116 5e86 c8e5  .)....I. G..^...
000003e0: 329f da78 b6a1 ba63 6b2d 1d73 6b31 72b0  2..x...ck-.sk1r.
000003f0: a08a 5c24 cf47 012a 5d5a 8ea9 7796 0ebe  ..\$.G.*]Z..w...
00000400: 4e8e 0bdf 3ebe bef2 f31b 646c b158 a7f5  N...>.....dl.X..
00000410: ebe7 1315 ab8a b055 6c9b 59bf fc90 7e65  .......Ul.Y...~e
00000420: 6d47 d1cf ffeb 4f14 3e22 dfe4 7a00 8b7a  mG....O.>"..z..z
00000430: b643 a313 2fbf c9b3 9a3c 7f27 940b 5591  .C../....<.'..U.
00000440: b7c4 6886 173b f3ab 8f91 87ed 21de 34e9  ..h..;......!.4.
00000450: e0fb e87f c95e 8882 92f9 a6cd eb9c 98db  .....^..........
00000460: 623b fcb9 d383 604f ab0f 9951 ead4 ddc3  b;....`O...Q....
00000470: 679b bcd2 4fd4 a527 91c5 ba09 7913 ba6e  g...O..'....y..n
00000480: e69d 3344 211c 4d5c 3ea4 73be 44de 9537  ..3D!.M\>.s.D..7
00000490: 1e44 f205 79b7 a9e9 42e3 4107 4b3a 989a  .D..y...B.A.K:..
000004a0: 18d6 e862 0a4b dea0 b7c2 1f83 7a4d 1cb8  ...b.K......zM..
000004b0: 3faf 8722 3784 d71c d475 e6f7 9550 3a68  ?.."7....u...P:h
000004c0: 7c71 5093 8efd 99b0 4b30 0b41 8d52 4f9e  |qP.....K0.A.RO.
000004d0: 2b56 8614 2fb8 72fa f9c8 a1cd 5798 b118  +V../.r.....W...
000004e0: 668e ef12 da11 cc15 bab5 a5c3 d3a1 5885  f.............X.
000004f0: a346 76e6 7c0f 92ef 04d7 0d30 bfd2 51bf  .Fv.|......0..Q.
00000500: c151 0175 4fd1 3c75 f06f 745d 8159 00f5  .Q.uO.<u.ot].Y..
00000510: 2a5d ec07 509a 086b c7ef 55ea 62ab f227  *]..P..k..U.b..'
00000520: 8fd5 809e 6de9 49d4 a374 4362 1d82 6aea  ....m.I..tCb..j.
00000530: fc2a 8b75 97f3 4b7e 77a5 93d7 83b2 cbd5  .*.u..K~w.......
00000540: 3c04 590f 9516 cd9a a0bf 4479 f0f3 f90b  <.Y.......Dy....
00000550: 9fbb e45d 86e3 23f5 e4d3 402b 2f06 5f9e  ...]..#...@+/._.
00000560: 4ea5 c3b2 08be 8af6 590c 9cac 8f7d ecaf  N.......Y....}..
00000570: c03b 92e6 4ac7 691b d403 54a7 d0d0 53c7  .;..J.i...T...S.
00000580: af0b ef13 1a37 c8c7 d2e9 f604 7b8c ef19  .....7......{...
00000590: 1626 a9f3 6e87 4517 bd55 1229 d293 6f39  .&..n.E..U.)..o9
000005a0: 79e4 2128 41e5 2b6f e810 e67b 083a 10ac  y.!(A.+o...{.:..
000005b0: a5a3 65e0 7288 f645 3872 fd6e 96f0 ea60  ..e.r..E8r.n...`
000005c0: 1f71 bb97 0e8a 2672 1d7c a96c cd32 8f1a  .q....&r.|.l.2..
000005d0: e0b8 e814 c876 a527 9fae 50ae 7429 62d8  .....v.'..P.t)b.
000005e0: 4d5d b86d 7897 49dd 82de 94ce d73b 7d57  M].mx.I......;}W
000005f0: 62d2 2763 2dcf d786 5f26 3a39 3ac7 d2c1  b.'c-..._&:9:...
00000600: 9fc3 46c1 b385 ef49 d6af 42f6 3e49 f410  ..F....I..B.>I..
00000610: a396 f4e4 3182 fb98 560f be4f b3de 8a45  ....1...V..O...E
00000620: 614a eb15 3c6e d2e1 1c82 dfc7 f008 e753  aJ..<n.........S
00000630: e6ab 5d12 bd92 6733 797a d285 ad88 5e8e  ..]...g3yz....^.
00000640: 2e7b 988e 5317 f698 3a47 be2e c0ad 49c7  .{..S...:G....I.
00000650: 4109 4f13 9acd c90d 3337 54a1 d5f0 3286  A.O.....37T...2.
00000660: 7f7a b427 4299 d0ed 2bf2 7aea 70de c279  .z.'B...+.z.p..y
00000670: 8fa3 104a 4be9 fffd 87e7 173a 07ec bd39  ...JK......:...9
00000680: 3ecb 1360 71f5 4c9b 376d a7ff ecc0 8ddf  >..`q.L.7m......
00000690: 0698 7dea 8e52 47bd c9fd 9178 99b4 b94b  ..}..RG....x...K
000006a0: a78d 4a25 97cf 33ec 1d65 1f71 3816 2f47  ..J%..3..e.q8./G
000006b0: 58ae 74f0 5c7e bdb0 bba2 cb24 f3fa 5978  X.t.\~.....$..Yx
000006c0: 435a 1b64 5f7e febc c123 4e22 0f9e 91ec  CZ.d_~...#N"....
000006d0: c77c b0f8 f0c0 6e57 3a2b 25e1 8610 b8d4  .|....nW:+%.....
000006e0: 28a5 2e9a 2d3e 5739 deb0 71fe f9f9 03b5  (...->W9..q.....
000006f0: 250c 0caa de65 6f80 7aa3 651f 17a6 7472  %....eo.z.e...tr
00000700: 147e 1ed8 abf3 6e9a 7970 85d9 18cb 7d5c  .~....n.yp....}\
00000710: 5ea5 a35f e2f8 c4df 262a cbd4 71dc a761  ^.._....&*..q..a
00000720: 051e 1198 a174 50b7 d4ab f3aa 825b 3775  .....tP......[7u
00000730: 5ecf e95a e4dd 51e4 ded2 e932 8393 2a7a  ^..Z..Q....2..*z
00000740: 2db6 ba59 7f36 c46b 0041 1e82 a574 3ce5  -..Y.6.k.A...t<.
00000750: a1be 8063 85f7 bdcc bb73 547d 9133 8562  ...c.....sT}.3.b
00000760: fdfc 3087 659d 2e81 50e6 99ab 6f3e 8cd0  ..0.e...P...o>..
00000770: 9b62 c5fe 7934 61f3 4ec3 227a f2ff 392d  .b..y4a.N."z..9-
00000780: ae7d b0fc c1d9 e8e7 630d 4777 b486 f49d  .}......c.Gw....
00000790: 64fd 6c8d d306 0f17 a055 a40b 2bc4 c903  d.l......U..+...
000007a0: d61d fa86 a973 e3c3 4d43 cc8b d8e8 49c7  .....s..MC....I.
000007b0: 2812 d798 cc8d 502a a983 56c5 e696 aea1  (.....P*..V.....
000007c0: 708a d2ff e78f 731f f673 54db 4294 972b  p.....s..sT.B..+
000007d0: d826 db07 bb4c fee9 9f33 d8e6 f70d 3b11  .&...L...3....;.
000007e0: 75eb 999f 0e9c 0b61 3c27 a324 1dd4 3b97  u......a<'.$..;.
000007f0: 42b1 6888 7990 ba50 b650 9f83 aab2 1a49  B.h.y..P.P.....I
00000800: 17f3 8f98 efa9 f000 ff98 f97c 0635 8f42  ...........|.5.B
00000810: 97c2 8974 5eed 501f 6257 65bd 9c3a e714  ...t^.P.bWe..:..
00000820: 3836 a97b a470 2d1d 5631 c453 8a62 bac8  86.{.p-.V1.S.b..
00000830: 1d8e 55b8 c710 dd51 ff4a a78b 8e86 064e  ..U....Q.J.....N
00000840: 1b3f 9dd4 4539 479a 476a 8bd4 aa74 b446  .?..E9G.Gj...t.F
00000850: e44c 60d1 85a0 913a f74d f24c 3e4d e159  .L`....:.M.L>M.Y
00000860: 960e ef15 7a55 a1b6 c0bf a48e b525 8e02  ....zU.......%..
00000870: d60d 5e5f a493 1ba0 5111 9336 dfc2 ccf3  ..^_....Q..6....
00000880: 2a9f f649 d481 e75d 3aec a710 57a1 3fa7  *..I...]:...W.?.
00000890: 6735 755a 7ab4 cc51 6104 83be 74da 7cc4  g5uZz..Qa...t.|.
000008a0: d482 9289 1547 f643 d4de a834 b070 fbb9  .....G.C...4.p..
000008b0: 5f21 a345 c729 af94 d4c5 744d 5e07 822d  _!.E.)....tM^..-
000008c0: 6f43 e962 17c1 7886 8510 af97 d4c1 bd53  oC.b..x........S
000008d0: e924 a603 bcbd 7fbe 9d89 4d4c e519 198f  .$........ML....
000008e0: ac5f 7bfc 34f9 a68a ed42 3aef 54ec 1d38  ._{.4....B:.T..8
000008f0: 2c93 2dbf dfec 9279 86ba 9d3c a7d2 fff7  ,.-....y...<....
00000900: 0fa2 021c 8b50 1826 91bc a357 8d1a 1731  .....P.&...W...1
00000910: f061 10a4 137f a81c c82b 416e 4f17 2b65  .a.......+AnO.+e
00000920: a18f e1be 4e5e 2fa1 cd33 165a 852e 36e8  ....N^/..3.Z..6.
00000930: dbe4 db4f 99f6 231a 9692 4f08 2b4b d681  ...O..#...O.+K..
00000940: 8dbd 0fde 9bb0 964f fc7d 29a6 4758 9974  .......O.}).GX.t
00000950: 6866 0c8f 0bb9 330c ea90 3fa4 8cf6 0a87  hf....3...?.....
00000960: 063a 7db4 9d8c a9f5 a5d6 1cb5 087b d38c  .:}..........{..
00000970: ad95 f08a d43a 92ba ce18 ab1a f776 c9d7  .....:.......v..
00000980: a7a5 93f1 31a2 5b1d 1a06 943d 59bb 5bf4  ....1.[....=Y.[.
00000990: 96f0 ee8a c920 e5e4 1b24 af23 bcca f072  ..... ...$.#...r
000009a0: 653d 7221 ba91 ebc0 b328 4fd6 00e2 328d  e=r!.....(O...2.
000009b0: 5fe4 3c33 066f 21ac 0a04 5356 c629 6371  _.<3.o!...SV.)cq
000009c0: c82d 8b3c 8377 c38c f990 e7dd 18ca 5bce  .-.<.w........[.
000009d0: a929 53d1 80b6 913c 6ac9 c34d f95f       .)S....<j..M._

Try it online!

You know what, I'll admit that this code golf challenge wasn't as clever as I thought it was. Bubblegum stomps this challenge, so I'll give it to you. (There's probably more score to be had in compressing with LZMA rather than DEFLATE, but that's beside the point.)

C, 50 + 3008 = 3058 bytes
I've tried out several simple compression methods, and found that outputting the UTF-16 input (trailing newline removed) directly is the best way. Input from stdin.
int b[999];main(){read(0,b,3008);write(1,b,3008);}

Python 3, 62 + 2145 = 2207 bytes
Evil built-in. Input filename is A, which is an xz-compressed file of UTF-16 version.
import lzma
print(lzma.open('A','rt',encoding='utf16').read())

Compressor code:
import lzma
open('A','wb').write(lzma.compress(open('utf16_file.txt','rb').read(),lzma.FORMAT_ALONE))

Java 8, 3640 (127 + 3513) bytes
import java.nio.file.*;v->{Files.lines(Paths.get("a")).map(x->x.length()>1?x+"。":x).forEach(System.out::println);}

The total byte-length of the original file is 4003 bytes. When we remove all trailing spaces and the trailing new-line, this becomes 3888 bytes. All the lines in the file except for the single digits end with 。, so removing all those and using .map(x->x.length()>1?x+"。":x) will save an additional 390 bytes.
Can definitely be golfed by just using an encoding/decoding compressed strategy, but whatever..
Explanation:
import java.nio.file.*;        // Required import for Files and Paths

v->{                           // Method with empty unused parameter and no return-type
  Files.lines(Paths.get("a"))  //  Read the file as a String-Stream
       .map(x->                //  Map over the lines:
         x.length()>1?         //   If the length of a line is larger than 1:
          x+"。"               //    Use the line + literal "。"
         :                     //   Else:
          x)                   //    Use the line as is
       .forEach(System.out::println);
                               //  And print each of those mapped lines
}                              // End of method

You can try to download the file directly (maybe Ctrl+S on browsers) instead of copy-and-paste.

05AB1E, 2605 bytes
•!…мOÂ6м’ZÖ₁-Pr@½õθ₃žв∊}`?(Ć·Ò[Íš2мö$qjõaF“;<!S¤mC†&ζΓ{ãˆFiUM’^Nm…M¾g¹Ć"ú¥/ÐòvÂqŒ4©Ù
1£v4ÒÀÌçтΛ˜þ∍ãÛ[£FàΔт÷¾ÜʒÕā“q¾^|°7δ«à÷³þ§I₁˜ýΣŽê¾мΘà¹œb₅γ*Üã“öÚŸEà/‚µá¢—₃;œýLº₅fK“ÎIF‹{Æ~3âтü!ï^:¢Σιв¾¢ißŠk¥´∍Õ'ÀºζE×*ÆAÄj`î¦ûKλL&н"ĀÛĀ™ú¥ÖµвrÁD²āh—ζŒ%ÇxÃ²©¼Á¹Ù½Θ¾~‹¡¨FÞFg≠¨É÷ƒá_:§£Ãìć˜ùÍ´zεΘoиXhδ'úEÐÂÖ&Ô!¨ú¹Òó²˜OOäê₃\å`q[í ₆ΣuÍ¯¬ª₆-éßkEšxX¸ï.c‰ó€‡Kð"P[áìαλ€!f¨в≠ΣYí-ʒ{€0à51QÃè…Wöù·t8ÁÏ=U—–TòΩá¨y2˜z)@¥¹#lLP¬ÔO2ýÀòŒÍä∞Δk¿cÅŒã’[ºнe¬7¢UÙÈδ´'§ÀbMÞи@Q)Vα#*yÚì°®Š₂ªl@ƶÅ∞è‡¾V@ÁçĀoµ¯ˆåÀÓ£öWg1^Kåα³¿ζ™¯í¥‰®6ê¥AïƶTCR´"zêÛ^Äª;¥n₁*ŠäδÓ₂¡Ž²Áü,|tWR¨cd¢ú×λ>B¯ÃÈÒĆâŸÎŠ˜`ΛαPиĆ₂è9×)≠ç÷ºÀ‰ÆÒ—\|<RõéÅΛ₆¢µV¿ǝâÀë7q{Σ₄Ib éZrγ)αI¸Ñ-,E½Ó´¢å7Ö8-»CʒEā%eo
³tX1s–O∞d‚÷θT3†&ïÕ)Z¯н¾½røδ¦ÎÉη~ΩSëÞÓ¿w ∍Ð¿´6тв₂M~šÜKž×Ä¦ãÅšÓ3Ýàlá|å₃м_mCs©¥¾²Á[6À3{MÍO<‡
∍9¹eΩ(ǝPΔнÅZp“=1GÂbÏΛηñzÒ²ûζœÉ‹ön®œ¦ΛÞ0®ζï₄Þ>c¬ˆ~Θ*¤_é¨ÉBÔÕð₅€xÁIz‚æ(»'JRúÓd±^pÜ±λLα½‹FΔò(ΔÆrð6±/^н₅yì}ž6îEy…´θ2s25þÔô[>Å£и¬?Òd Ñ?`Ÿ∊Xlêx`:ŠòΘBŠ':´KM^нΓæ±s»∍vǝλà"‘ív32É»‚}@ÎÈé₃I¨zA³ÚÅb≠†ËØΘÙ¹Ý²ćÛ^fǝäÚ_™§Ô©₆Θeñ¼-иx(„àR—ÑWú/”.”OKéŽÎ‘™þÊð
N/8sØ§«ÀMÂηjIĆ2*bηǝ±m¨¬¾ΔtÃ_∍ÿþΩ¼∊÷γ½.,ÙC¯¤àÊhŠ[ˆñтúΓiƒ¯[~ηΛ₆¿–©µΩJ‹»\≠:°ù…нYĀì—!Ûl1™Ö¤°´A3-мćÞôîΣFÊ)Oƶ€lª®mĀ!%½ŽZdUºĆåùÛCp±?99äƒ\ñ£ÕH´¹0f±Q2Íö’Ćв₂ǝÔ§üñ&ÔÎèçÆw¦â«×ý'Ë₃ʒвƵ
nAä„ÐĆs<F×¿4dxç©ù‹ʒóTË)¡≠{ùO5₅ʒ@
Ö…U²&¨®lŽuu“≠¹ÍÒWZâÃ¶_Ûyt‰ΛuItÃλfŒ3Ž¨Ƶ}+â©¨ƶ—*Ê1и≠ž]ˆÛ$?ʒu¾2z>ôÿÚ¤ÄŸE₁Uò!Ƶf1A1ζ‹Öj:¸Zc2Ã^d_¾₂Í%l"jÊ˜ð„.tþì∊Γ*WÛÓ™§ÜÁŒÁòz‘Σ·kçŽ>Ï~ÕÃn\β8δ₄XMe¹Ú‰.$ƒ=ÏÕ…¡˜bH5¼pñвÆÉ×¬~ßιÀP$WÆñ;Uðè‰#uú‡Ï²т?¢þ»ÂÈÑÛ@Úć‰f0Èö₅Í°¼0₆õòÿ∍ª¢ÈUTà’æÊöü₆ÉIмΛú:Σ£…Ç×ÜBÂµãÓq₃¡н¸‰4œÞª(∊ΓÍ[εS_?ì…KнâOùFr½³ê∍*θ§€‘PÄ¾õÔ ªÃΔ”Duï¿Ćub¨Λé3ìCð6µK=Çθ>wjñ‰yP¦
gr¸N(Ô½G>“aóÀo»³{Î§_øā(¢*´ΓyĀí´R§æÀ0$MÔˆζÜÊàx¸Û₁¨и"+ƶÑǝtJ”É‹Mçò‘tývÓ^:¡Ü‘≠OË!θÃw₂î(∍‘Pœ²ižraïΓ]E∞zo5θè@[žĀS4€jU≠ÃZD*Ðùв†ù·Λ{’₃≠„αûΣT3Ì×¯OS¤T–Œþ&ÞVKV.∍2§Gú₃₁~ª¼)(ø><q₂¤S»þìAMв+ U’Íy†p×E0‚QÛ£Ü–½7=nyÚ˜qú6;Δ“Ì¹YĀ—p₅!Ω"a–|á&†ª“ëkBQöã}3
s××ĀΓ¶ü¸†¹è¹zÒć†@+2ΓRαÃðû∊$º–„Ÿã>\>|d£Ýõõdʒhû#“IƒvJýi{Ùʒ₃-±¥)—ÝÅн{Š\e∞‡Δ-8¹ûÌâ₃±
«ãÜ‹›tdÂ«W"Ô£&₄;åL à¿мÂλÌм£«н₆¹NóüQH„w¦ºÔòcΔ¡HáÕ¢δĆShΔÈÔBX`Â´0₃iè«®°—fS$×ǝ&Ë3nH]wÂß0µ∍±ò+ÚΓqQ]õºćuH~°ÄÜÉ’=øƶË₄¹\ï≠7ðDg›½ÑšƵ÷é3µÿη–|Øìä₄CĀ²‹₅So–saÆ₃¦õÌÉr—=0ć₆?ŸÛÏƶ‡[õ¸β%H<-çмlÞ„‹59°C>#ÓΛh₂µJôü…ι¥mΩ«ÎP`§т·¥Òž©Ó¤½θVC!’вxjí<:∍{ÇS&PsÆÅË†:₄Ì¡ˆΛð∍ó«:ièîðÕ{ôт%F¨2uÞ∍ù)/θÙ-αŒj)7·BÿJ€Ãδñ«[éÒm‡ìõиà₁AVw₆ÇÇÂk“Ÿkˆ£}TžŽ¹©¤âò+gZεê}ñÖàΔ÷ǝ³U;°:ûhmÑòÏÜ₄[ÛÁçû$µ“"Xz€‚zλ1
¯0ï3ƶTн=íõ99ƒñβÌõöæ¶E˜ƵÝÑŒà·ƒFÊVùûèÏWŒþā4αº+ŒÔFàŽrÆ#'€î²d¸xLmAĀ÷«vV°©!¯āÌØ≠в'ÕxêÃÄmWβªŸíê¢6}2ú…åô%gÿEXÙr6íËÛ€¶Ý₄·®₄¬ºó«'(Ë—ûá—ÔË½*e‚*Õ›Ø/"‘¡oαΛñ†4~¸qCyî>òšqu"₆Æ¡áë“¤š_¦¦!т<gÙ×¼'oθp²n¶'^±‚X!½ƶΔ>{is¢λ"oAÁjв₄z‹ø₆)5HˆCÍ‘˜Þðêβƶÿùc¼λoM₄ªÞΛ≠H&ÚþýoÒÝ¥@a³Y[áæ°$¢}ćĆ¹±»₂¥˜³²™Lm9GΘΣΛ«2‚O»‘ηhĀÛˆ\¥ηÕÞ ‘6Rm‹ð≠~r–[+“Å7Àx/т÷âIι”Õ¾õ'3K[]=€Q}Ô,XÖè₁3µ /ÖZ₄X
≠è₁÷
≠Rèxž×hÉÑ’₁óqÊÒ:<eÀÙØãÚžNg‹Ā~Gη«ø¶`rΣÖ)Ä«Ω.Ç<Æ;´(…;±+§AP™wQÉι×¶т+_Ωj-Ê°ƒ§¡çóùÿ‡αØAh—“ζì(Adß¾y‚2ÿÄyFìεíøíagúÐ₂¥¼MsÀïê;EAŠ+³ìΘEwC–Hç•5ôçTô»

Try it online!

Shrugs in 05AB1E: I'm astonished how direct base conversion almost ties BG...

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Output an Anagram! No Not That One!
Given a list of unique strings that are anagrams of each other, output an anagram of those words that is different from each word in the list.
The strings will be alphanumeric, and there is guaranteed to be a valid anagram.
The program or function can, but doesn't have to be non-deterministic, meaning given the same input, multiple running a of the code can yield different outputs, as long as every possible output is a valid one.
Test Cases
[Input] -> Possible output
-----------------
[ab] -> ba
[aba, aab] -> baa
[123, 132, 231, 312, 321] -> 213
[hq999, 9h9q9, 9qh99] -> 999hq
[abcde123, ab3e1cd2, 321edbac, bcda1e23] -> ba213ecd

Python 3, 64 bytes
lambda a:[*{*permutations(a[0])}-{*a}][0]
from itertools import*

Try it online!

But is itertools ever the answer?

@MistahFiggins Nominated

@Mr.Xcoder before 22 July 2015

@StanStrum I just mentioned it, I am aware of that restriction. As Stewie said...

@Mr.Xcoder didn’t see that, cool!

If there a reason the import is after the lambda?

@jpmc26 Yes, this way you can put f=\ in the Try it Online header and leave the function anonymous, while not affecting the automatic TiO byte counter

Nifty. Thanks for answering.

Great submission. I'd be interested to know if there's a shorter non-itertools solution. random string generation or sort with a random key would all be longer than your code.

05AB1E, 5 bytes
нœ¹мà

Try it online!
Explanation
нœ¹мà

н     // Get the first element of the input list
 œ    // Generate all permutations
  ¹   // Push the input again
   м  // In the permutations list, replace all strings that
      //   are in the input list with empty strings
    à // Pick the string with the greatest lexicographic
      //   index (in this case a non-empty string)

Pyth, 5 bytes
h-.ph

Try it online!
Explanation
h-.ph
    h    First string in [the input]
  .p     All permutations
 -       Remove those in [the input]
h        First element.

Jelly, 6 bytes
XŒ!ḟµḢ

Try it online!
1 byte more than the 05AB1E and the Pyth answer.
Explanation:
XŒ!ḟµḢ   Main program.
 Œ!      All permutation of...
X        any element from the word list.
   ḟ     Filter out (remove) all the elements in the original word list.
    µ    With the filtered-out list,
     Ḣ   pick the first element.

I chosen X because it is the shortest way I know to pick any element from the list without altering the list (Ḣ and Ṫ doesn't work, ḷ/ and ṛ/ is longer), and it happens to cause some randomness.
The µ here is pretty redundant, but without it, the Ḣ would be paired with the ḟ, and it is interpreted as "filter out the head of the input", which is not what I need here (what I need is "filter out the input, and get the head").

Haskell, 58 bytes
-1 byte and a fix thanks to Laikoni.
import Data.List
f l=[i|i<-permutations$l!!0,all(/=i)l]!!0

Try it online!
It's probably not worth importing Data.List for permutations but eh.

You can save a byte with notElem. i would be surprised if someone finds a permutation function which beats the import, my shortest approach is 60 bytes vs. the 29 bytes of the import.

Here is a 43 bytes permutation function, but only for duplicate free lists.

Also your solution is currently not working because $ is missing before l!!0.

Javascript, 118 Bytes
function f(a){s=a[0];while(a.indexOf(s)!=-1)s=s.split("").sort(function(){return .5-Math.random()).join("")};return s}

uses a bad randomizer to iterate over each "random" permutation.
Probably provably wrong but afaik the bad randomizer just means we wont get true randomness, but will still get every permutation.
Seems to work on all cases in chrome for me but apparently due to undefined behaviour in this sort abuse, it can not work in some browsers.
(Probably very ungolfed feel free to improve it in your own solutions)
80 bytes
Thanks to pirateBay's comment -a lot of bytes
-4 bytes thanks to Rick
f=a=>eval('s=[...a[0]].sort(()=>.5-Math.random()).join``;a.indexOf(s)<0?s:f(a)')

FYI arrow functions are allowed (for example a=>b instead of function(a){return b}). It saves a lot of bytes.

Wow... that'll save quite a few bytes.

s.split("") can be [...s].  Also join("") can be `join```

@ThePirateBay i was afraid that would be the case, but why is that? (im aware that sort is not fully random,but all sequences SHOULD be possible)

@Imme. Here is 87 bytes working version. Notice that your sort function never returns 0 (or at least extremely rare), that's why it didn't work.

@ThePirateBay Im going with extremely rare. You should post that as your own, quite different from mine already. I'll recheck and mark it wrong in a few hours.

Ruby, 46 bytes
->l{(l[0].chars.permutation.map(&:join)-l)[0]}

Try it online!

Brachylog, 7 bytes
hp.¬∈?∧

Try it online!
Explanation
hp.        The Output is a permutation of the first element of the Input
  .¬∈?     The Output is not a member of the Input
      ∧    (Disable implicit Input = Output)

Japt, 7 6 bytes
-1 byte thanks to @Shaggy
á kN ö

Try it online!
Takes input strings as several inputs instead of as an array. Outputs a random permutation; switch ö to g to get the first one instead.
Explanation
á kN ö  Implicit input: N = array of input strings
á       Get all permutations of the first input string
  kN    Remove all input strings from those
     ö  Get a random element from the array. Implicit output

Nuts, you beat me to it. You could take input as individual strings and save a byte with á kN ö.

@Shaggy That's a great way to get the first input item, I'll have to remember that. Thanks!

Mathematica, 57 bytes
non-deterministic
(While[!FreeQ[#,s=""<>RandomSample@Characters@#&@@#]];s)&

Try it online!
Mathematica, 56 bytes
deterministic
#&@@Complement[""<>#&/@Permutations@Characters@#&@@#,#]&

Try it online!

Python 3, 78 bytes
lambda a:[x for x in permutations(a[0])if~-(x in a)][0]
from itertools import*

Try it online!
-1 byte thanks to Mr. Xcoder

if x not in a is if~-(x in a) for 178

@Mr.Xcoder. You mean 78, right?

@ThePirateBay Yes, I do... Whoops!

How about 66 bytes?

@NieDzejkob That's impressively shorter. You should post your own if you want

@HyperNeutrino that's a simple golf based on your answer, but now I noticed that Mr. Xcoder's answer uses the same trick, but with [*s][0] instead of (s).pop()for 64 bytes.

@NieDzejkob oh yeah, I see it there now. Yeah, I'll keep mine in its current state because I don't really need to golf it down any further (and it would pretty much just be his version :P)

MATL, 15, 13, 12 bytes
1X)Y@Z{GX-1)

Try it online!
Saved 2 bytes thanks to Sanchises. setdiff(...,'rows') is shorter than negating ismember(...,'rows') and it avoids one duplication. Saved another byte thanks to Luis Mendo, by switching to cells instead of arrays.
Explanation:
The MATLAB / Octave equivalents are also included.
                 % Implicitly grab input x containing cells of strings
1X)              % Get first cell. Equivalent to x{1}
   Y@            % All permutations of first row input. Equivalent to p=perms(y)
      Z{         % Convert the list of permutations to a cell array
        G        % Grab input again
         X-      % setdiff, comparing the input cells with the permutations
           1)    % The first of the results

Input must be one the format {'abc', 'acb'}.

Pip, 11 bytes
@:_NIgFIPMa

Takes the inputs as command-line arguments. Try it online!
Explanation
          a  1st cmdline arg
        PM   List of all permutations
      FI     Filter on this function:
  _NIg         Permutation not in cmdline args
@:           First element of resulting list (with : meta-operator to lower precedence)
             Autoprint

Python 3, 87 bytes
I believe this is the only submission so far that uses neither a permutation builtin nor random shuffle/sort. Even though it's longer, I think the algorithm is pretty neat.
lambda L:[p for s in L for i,c in enumerate(s)for p in[c+s[:i]+s[i+1:]]if~-(p in L)][0]

Try it online!
Explanation
What we're doing is basically this:
def unique_anagram(string_list):
    for string in string_list:
        for i, char in enumerate(string):
            # Move the character to the beginning of the string
            permutation = char + string[:i] + string[i+1:]
            if permutation not in string_list:
                return permutation

Here's a proof that it works:

For a string S, define front(S) as the set of strings obtained by choosing one character from S and moving it to the front of S. For example, front(ABCDE) is {ABCDE, BACDE, CABDE, DABCE, EABCD}.
Now consider a list of anagrams L, such that L does not contain every possible anagram (as per the problem description). We wish to show that there exists a string S in L such that front(S) contains at least one anagram S' that is not in L.
Suppose, by way of contradiction, that for every string S in L, every string in front(S) is also in L. Observe that we can generate an arbitrary permutation of any string via a series of "fronting" moves. For example, to get
ABCDE -> BAEDC

we can do
ABCDE -> CABDE -> DCABE -> EDCAB -> AEDCB -> BAEDC

We have assumed that for each S in L, every S' in front(S) is also in L. This also means that every S'' in front(S') is in L, and so forth. Therefore, if S is in L, every permutation of S is also in L. Then L must be a complete set of anagrams, a contradiction.
So, since we are guaranteed that there is at least one permutation not in L, there must exist a string S in L for which some S' in front(S) is not in L. QED.

The code iterates over front(S) for each S in L and selects an S' which is not in L. By the above result, there will be at least one S' that qualifies.

C# (Visual C# Interactive Compiler), 116 96 bytes
s=>{for(var g="";;)if(s.All(z=>z!=(g=string.Concat(s[0].OrderBy(t=>Guid.NewGuid())))))return g;}

My golfing skills have certainly gotten better since when I first posted this!
Try it online!

Husk, 6 bytes
←-⁰P←⁰

Try it online!

It doesn't look like this works for inputs greater than length 2?

@MistahFiggins You can't have spaces in the array literal: https://tio.run/##yygtzv7//1HbBN1HjRsCgDSQ@v//f7RSYlKyko5SYnISkExKTlSKBQA

JavaScript (ES7), 172 bytes
f=(a,s=a[0],b=[...s],k=b.findIndex((e,i)=>s[i-1]>e))=>a.includes(s)?f(a,(~k?(t=b[k],b[k]=b[l=a.findIndex(e=>e>t)],b[l]=t,b.map((e,i)=>i<k?b[k+~i]:e)):b.reverse()).join``):s

Find the first lexicographic permutation of the first element of the array that's not contained in the array.

Kotlin, 104 bytes
{var r=""
do{r=it[0].map{it to Math.random()}.sortedBy{(_,b)->b}.fold("",{a,(f)->a+f})}while(r in it)
r}

Beautified
{
    var r = ""
    do {
        r = it[0].map { it to Math.random() }
            .sortedBy { (_, b) -> b }
            .fold("", { a, (f) -> a + f })
    } while (r in it)
    r
}

Test
var ana: (List<String>) -> String =
{var r=""
do{r=it[0].map{it to Math.random()}.sortedBy{(_,b)->b}.fold("",{a,(f)->a+f})}while(r in it)
r}

fun main(args: Array<String>) {
    println(ana(listOf("ab")))
}

C++, 169 bytes
#import<set>
#import<string>
#import<algorithm>
using S=std::string;S f(std::set<S>l){S s=*l.begin();for(;l.count(s);)std::next_permutation(s.begin(),s.end());return s;}

Try it online!

PHP, 70 bytes
$j=1;while($j){$g=str_shuffle($_GET[0]);$j=in_array($g,$_GET);}echo$g;

Run on a webserver, inputting 0 indexed get values or Try it online!
Ungolfed
$j=1; //set truty value
while($j){
    $g=str_shuffle($_GET[0]); //shuffle the first anagram of the set
    $j=in_array($g,$_GET); //see if in the set, if false, the loop ends
}
echo $g;

Save two bytes with do{...}while($j); instead of $j=1;while($j){...}. Use in-place definition for $g to get rid of the braces (and save four bytes).

PHP, 58 55 bytes
while(in_array($s=str_shuffle($argv[1]),$argv));echo$s;

non-deterministic;
takes input from command line arguments
Run with php -r <code>  follwed by space separated words or try it online.

Scala, 50 bytes
(l:Seq[String])=>(l(0).permutations.toSet--l).head

Try it online!
Explanation
l(0)         // Take the first anagram
permutations // Built-in to get all permutations
toSet        // Convert to set, required for -- function
-- l         // Remove the original anagrams
head         // Take a random element from the set

R, 89 bytes
x=scan(,'');repeat{a=paste(sample(el(strsplit(x[1],''))),collapse='');if(!a%in%x)break};a

Repeatedly sample the letters from the first entry (as they should be anagrams of each other) and stop when one of those samples is not in the original list.

82 bytes

Attache, 16 bytes
&\S@{!S@_[0]Ø_}

Try it online!
Explanation
&\S@{!S@_[0]Ø_}
    {         }    lambda (input: `_`)
        _[0]       first element of the given array
       @           pass to:
     !                 on each permutation:
      S                cast to string
            Ø      without any member of
             _     the input
                   this gives all anagrams not in the input
   @               then
&\S                "first string element"
&                  spread input array over each individual arguments
 \                 tale first argument
  S                as a string

Alternatives
17 bytes: {&\S! !S@_[0]Ø_}
18 bytes: {&\S! !Id@_[0]Ø_}
19 bytes: {&\S!(!Id)@_[0]Ø_}
26 bytes: {&\S!Permutations@_[0]Ø_}
26 bytes: {&\S!Permutations[_@0]Ø_}
26 bytes: {(Permutations[_@0]Ø_)@0}
26 bytes: &\S##~`Ø#Permutations@&\S
27 bytes: Last@{Permutations[_@0]Ø_}
27 bytes: `@&0@{Permutations[_@0]Ø_}
28 bytes: Last##~`Ø#Permutations@&{_}
28 bytes: Last##~`Ø#Permutations@Last
28 bytes: First@{Permutations[_@0]Ø_}
30 bytes: {NestWhile[Shuffle,`in&_,_@0]}
33 bytes: {If[(q.=Shuffle[_@0])in _,$@_,q]}
33 bytes: {q.=Shuffle[_@0]If[q in _,$@_,q]}
34 bytes: {If[Has[_,q.=Shuffle[_@0]],$@_,q]}

J, 25 bytes
((A.~i.@!@#)@{.@:>){.@-.>

The input is a list of boxed strings - I felt it was fair like this and not to declare the lists of strings explicitly as 4 8$'abcde123', 'ab3e1cd2', '321edbac', 'bcda1e23'.
I don't like the @ mess in my code, but there are a lot of serialized verbs this time.
How it works:
                         >  - unboxes the strings
 (                 )        - left verb of the fork as follows:
             @{.@:>         - unbox and take the first string
  (         )               - finds all permutations of the first string
      i.@!@#                - a list 0 .. the factorial of the length of the 1st string
   A.~                      - anagram index, all permutations
                    {.@-.   - remove the inital strings and take the first of the remaining

Try it online!

Taking input as a table, for 21 bytes: {.@(-.~i.@!@#@{.A.{.).  Try it online!

05AB1E, 5 bytes
нœIмà

Try it online!
Explanation
нœIмà full program with implicit input i
н     push first element of i
 œ    push all permutations
  I   push input i
   м  remove all elements of i from the permutations
    à extract greatest element and print implicitly

Pretty much the same answer that @ThePirateBay found.

JavaScript, 87 bytes
a=>eval('for(s=[...a[0]];(a+[]).includes(k=s.sort(a=>~-(Math.random``*3)).join``););k')

Try it online!
This answer is based (although heavily modified) on Imme's answer. He suggested in a comment that this should be a different answer.
The problem with the old approach is because sort is completely implementation-dependent. The standard doesn't guarantee the order of calling the sort function, therefore theoretically it may never end for the first or the second test case.
This approach is few bytes longer, but it guarantee that it will finish in constrained time, even if Math.random never returns .5.

CJam, 11 bytes
q~_0=m!\m0=

Try it online!
Explanation
q~  e# Read input and evaluate: ["123" "132" "231" "312" "321"]
_   e# Duplicate:               ["123" "132" "231" "312" "321"] ["123" "132" "231" "312" "321"]
0=  e# First:                   ["123" "132" "231" "312" "321"] "123"
m!  e# Permutations:            ["123" "132" "231" "312" "321"] ["123" "132" "213" "231" "312" "321"]
\   e# Swap:                    ["123" "132" "213" "231" "312" "321"] ["123" "132" "231" "312" "321"]
m0  e# Subtract, push 0:        ["213"] 0
    e# (m is used instead of - when in front of a digit)
=   e# Get item:                "213"

I think there might be a typo in your explanation - The answer that your code gives is different from what your explanation says

Perl 6, 42 bytes
{(.[0],*.comb.pick(*).join...*∉$_)[*-1]}

Try it online!
Randomly shuffles the first string of the input until it is not an element of the input.
Explanation:
{(.[0],*.comb.pick(*).join...*∉$_)[*-1]}
{                                      }   # Anonymous code block
 (                        ...    )   # Create a sequence
  .[0],   # The first element is the first element of the input
       *.comb.pick(*).join   # Each element is the previous one shuffled
                             *∉$_   # Until it is not in the input
                                  [*-1]   # Return the last element

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Bitwise XOR of rational numbers
Introduction
Every rational number between 0 and 1 can be represented as an eventually periodic sequence of bits.
For example, the binary representation of 11/40 is
0.010 0011 0011 0011 ...

where the 0011 part repeats indefinitely.
One way of finding this representation is the following.
Start with r = 11/40, then repeatedly double it and take the fractional part, recording when it goes above 1.
When the value of r repeats, you know you have entered a loop.
1. r = 11/40
2. 2*r = 11/20 < 1   ->  next bit is 0, r = 11/20
3. 2*r = 11/10 >= 1  ->  next bit is 1, r = 2*r - 1 = 1/10
4. 2*r = 1/5 < 1     ->  next bit is 0, r = 1/5
5. 2*r = 2/5 < 1     ->  next bit is 0, r = 2/5
6. 2*r = 4/5 < 1     ->  next bit is 0, r = 4/5
7. 2*r = 8/5 >= 1    ->  next bit is 1, r = 2*r - 1 = 3/5
8. 2*r = 6/5 >= 1    ->  next bit is 1, r = 2*r - 1 = 1/5, same as in 4.
   The loop 5. -> 6. -> 7. -> 8. now repeats.

To get from the binary string back to 11/40, you can use the formula
(int(prefix) + int(suffix)/(2^len(suffix) - 1)) / 2^len(prefix)

where prefix is the initial part 010, suffix is the repeating part 0011, and int converts a binary string to integer.
Given two such representations, we can perform the bitwise XOR operation on them.
The resulting sequence will also be periodic, so it represents a rational number.
For some rational numbers, there are two binary representations.
1/4 = 0.010000000...
    = 0.001111111...

The choice between them can affect the result of the bitwise XOR.
In these cases, we use the former representation, which has infinitely many 0s.
The task
Your inputs are two rational numbers in the half-open interval [0,1).
Your output shall be the result of the bitwise XOR operation applied to the inputs, expressed as a rational number.
Note that the output can be 1, even though neither of the inputs are.
The exact formats of input and output are flexible, but each rational number should be represented by two integers, the numerator and denominator (with the exception of 0 and 1, which can be represented as 0 and 1 if desired).
You can assume that the inputs are expressed in lowest terms.
The output must be expressed in lowest terms.
A built-in rational number type is an acceptable format, as long as it satisfies these restrictions.
You can ignore any bounds on integers imposed by your language, but your algorithm should theoretically work for all rational numbers.
The lowest byte count wins.
Standard code-golf rules apply.
Example
Consider the inputs 11/40 and 3/7.
We write their representations one above the other, delimiting the repeating parts by pipes |.
Then we extract repeating parts of equal lengths, and apply bitwise XOR to them and the parts before them.
11/40 = 0. 0 1 0|0 0 1 1|0 0 1 1|0 0 1 1|0 0 1 1|0 0 1 1|0 0 1 1|0 0 1 ...
3/7   = 0.|0 1 1|0 1 1|0 1 1|0 1 1|0 1 1|0 1 1|0 1 1|0 1 1|0 1 1|0 1 1|...
     -> 0. 0 0 1|0 1 0 1 1 1 1 0 1 0 0 0|0 1 0 1 1 1 1 0 1 0 0 0|0 1 0 ...

The resulting rational number is 89/520.
Test cases
0 0 -> 0
1/2 1/2 -> 0
1/2 1/4 -> 3/4
1/3 2/3 -> 1
1/2 3/4 -> 1/4
5/8 1/3 -> 23/24
1/3 1/5 -> 2/5
15/16 3/19 -> 257/304
15/16 257/304 -> 3/19
3/7 11/40 -> 89/520
5/32 17/24 -> 59/96
16/29 16/39 -> 621001733121535520/696556744961512799

What's the maximum period we need to support?

@Neil What makes you think that such a maximum exists?

I get 23/24 as a result for 5/8, 1/3 instead of the 11/12 in the testcases.

@Neil There is no hard limit. You algorithm should be able to handle any period, ignoring the limits of your language.

@orlp Thanks for noticing. There was a bug in my reference implementation. The values should be correct now.

@Zgarb  Can we remove the testcase 0, 1 and make the input range half-open? Handling numbers >= 1 is annoying and inconsistent. Assuming each number is in [0, 1) seems more reasonable to me. At the moment every input has form 0.xyz... except 1.

@orlp You're right, 1 is a potentially annoying special case. I included it mainly for completeness since the output can be 1. The input range is now [0,1).

@Zgarb So, if my language fails on 16/29 16/39 because of 32-bit integer overflow then my answer is still valid?

@Neil Yes, it's valid if the overflow is the only thing that prevents it from working correctly.

Note: Some numbers have two binary expansions, namely those numbers where the eventual period has length one. It is implicit in the problem definition above that we must choose the representation that ends in 000... in this cases (which is also what we get if we use the algorithm with r). For example, in the case 5/8, 1/3 we get 23/24 because we choose the expansion 0.101000... for 5/8. If we choose instead 0.10011111... as 5/8, the result after XOR becomes 19/24, so this is wrong. Related to Wikipedia: 0.999...

@JeppeStigNielsen Damn... This means that unlike regular XOR (a ^ b) ^ b == a does not hold. E.g. (19/24 ^ 1/3) ^ 1/3 != 19/24. That made me lose quite a bit of excitement about this :(

See also What do bitwise operators look like in 3d? on [math.se].

@JeppeStigNielsen Thanks, I forgot to mention that. Added now.

Python 3, 193 164 bytes
def x(a,b,z=0):
 l=[]
 while(a,b)not in l:l+=[(a,b)];z=2*z|(a<.5)^(b<.5);a=a*2%1;b=b*2%1
 p=l.index((a,b));P=len(l)-p
 return((z>>P)+z%2**P*a**0/~-2**(P or 1))/2**p

Takes input as Python 3's fractions.Fraction type, and outputs it as well.
Fun fact (you can easily show this using generating functions), if you change (a<.5)^(b<.5) to ((a>=.5)and(b>=.5)) above you get the binary AND between two rational numbers. Call this nd(a, b). Then we have a + b - 2*nd(a, b) = x(a, b)!

Indeed, my mistake. Apologies! (note that a link to tio included in the answer would be great)

JavaScript, 141 bytes
(p,q,r,s)=>(h=(v,u)=>v%u?h(u,v%u):[a/u,b/u])(b=(g=x=>x%q||x%s?g((x|x/2)+x%2):x)(1),a=(o=b/(b-(b&~-b)),x=p*b/q,y=r*b/s,(x%o^y%o)+(x/o^y/o)*o))

Wont work for last test case (integer overflow). Input 4 numbers for p/q xor r/s, output an array with two numbers. For testcase 0, 0, you should input 0, 1, 0, 1.
How:
(All numbers described here is in binary form.)

find the smallest number b, which b = 10 ^ p - 10 ^ q (p, q are integers, p > q); and b = 0 (mod q); and b = 0 (mod s);
Let x = p * b / q, y = r * b / q; Convert p / q, r / s to x / b and y / b;
Let o = 10 ^ (p - q) - 1; split x, y to [x % o, x / o], [y % o, y / o]; get xor for each part [x % o xor y % o, x / o xor y / o], and join back to (x % o xor y % o) + (x / o xor y / o) * o; Donate it as a;
If a = 0, the answer is 0 (or 0 / 1); Otherwise let u = gcd(a, b); the answer is (a/u) and (b/u).

f=

(p,q,r,s)=>(h=(v,u)=>u%v?h(u%v,v):[a/v,b/v])(b=(g=x=>x%q||x%s?g((x|x/2)+x%2):x)(1),a=(o=b/(b-(b&~-b)),x=p*b/q,y=r*b/s,(x%o^y%o)+(x/o^y/o)*o))
<div oninput="[v5.value,v6.value]=['?','?'];[v5.value,v6.value]=f(+v1.value,+v2.value,+v3.value,+v4.value)">
<input id=v1 />/<input id=v2 /> xor <input id=v3 />/<input id=v4 /> = <output id=v5></output> / <output id=v6></output>
<style>input{width:40px}</style>
</div>


text:
Is it a substring of itself?
Given a string, return whether the string is a substring of the program's source code.
Standard quine rules apply, meaning you cannot read your own source code. The length of the input is guaranteed to be less than or equal to the length of the program. You may return any two distinct values, not necessarily truthy and falsey values. You may also submit a function, rather than a full program.
This is a code-golf so shortest code wins!
An example
If your source code is print(input() = False), it should return True for nt(i but False for tupn.

Related

Is a function allowed?

@totallyhuman as with most challenges, yes.

Also related.

guys mentioning all related questions that don’t make it a duplicate is unnecessary.

@StanStrum It is not to point out duplicates, it is to show related challenges that people might be interested in and to show them on the sidebar to the right.

Can the input be empty? (Actually, can the code be empty?)

@Lynn No, the code cannot be empty

-1 because this is a generalized narcissist

Python 2, 41 bytes
s="print input()in's=%r;exec s'%s";exec s

Try it online!

As a reference, the Python 3 port is 44 bytes.

JavaScript, 25 bytes
f=s=>('f='+f).includes(s)

Try it online!
I'm personally not a fan of this, but it's allowed.
Alternate (invalid?) solution, 19 bytes
This takes input as a regex.
f=s=>s.test('f='+f)

Try it online!

Doesn't it read itself?

@Adám https://codegolf.meta.stackexchange.com/a/13638/68615

What is the purpose of explicitly mentioning (Node.js)? Doesn't it work in browsers too?

@ThePirateBay Works as expected in Chrome.

@steenbergh. I know, of course, but I'm wondering what is the purpose of mentioning Node.js while it works on any JavaScript engine.

@ThePirateBay There are some differences between the Javascript implementations of Node, Spidermonkey and ... the other one. I guess it's mentioned to avoid hitting one of those differences, though in this case I think it's a bit superfluous.

@steenbergh. Well, I think the only reason for it is because he just copied "Code Golf submission" field from TIO without modifying anything, which includes Node.js next to JavaScript. I agree, it is superfluous in this case and may be confusing to people which see this answer.

You guys are thinking way ahead, it's just from the TIO template. :P

Java 8, 124 112 bytes (function)
p->{String s="p->{String s=%c%s%1$c;return s.format(s,34,s).contains(p);}";return s.format(s,34,s).contains(p);}

Try it here.

Here is it as full program instead (to see one of the reasons why functions are allowed on PPCG, because some languages -like Java- require very verbose mandatory boilerplate code for full programs).
Java 8, 226 214 bytes (full program)
interface M{static void main(String[]a){String s="interface M{static void main(String[]a){String s=%c%s%1$c;System.out.print(s.format(s,34,s).contains(a[0]));}}";System.out.print(s.format(s,34,s).contains(a[0]));}}

Try it here.

Explanation:

The String s contains the unformatted source code.
%s is used to input this String into itself with the s.format(...).
%c, %1$c and the 34 are used to format the double-quotes.
s.format(s,34,s) puts it all together.

And then .contains(...) is used to check if this source code contains the given input.

This gives me true for all strings when I "Try it online".

@MichaelKarnerfors not for me... Are you sure you don't add arguments each time? Only one argument is used. You have to run the program changing the argument each time you make a new test.

@OlivierGrégoire You are correct, I used the TIO page wrong. Thank you. :)

QBIC, 28 bytes
?instr(B+B,;)#?instr(B+B,;)#

This prints 0 if the input is not a substring of the source, and X otherwise where X is the (first) index of the substring.
Explanation
Latter part:
#?instr(B+B,;)#   Define a string literal B$ with a copy of the source

First part:
?                 PRINT
 instr(   , )     the index of
           ;          the cmd line parameter A$
       B+B            in B$ concatenated with itself

# defines a string literal in QBIC, and assigns it to the first available string variable. That is B$ in this program, because A$ is already taken by ; (read a string from cmd line). Then, everything up to the delimiter is fed into the literal; the delimiter is a backtick - which also makes it the only ASCII char not includable in string lits. In this case, QBIC doesn't need a backtick, because the literal is terminated at the end of the code by QBIC's auto-close feature. For more information on QBIC's literals, see the Showcase thread.

What is A in this context?

@cairdcoinheringaahing a little error on my side, should've beenB and an explanation is added.

Bash, 43, 28 bytes
[[ $BASH_COMMAND = *"$1"* ]]

try it online

I don't know Bash, but can this be golfed further by removing a lot of the whitespace?

@cairdcoinheringaahing I don't think so, typeset formats it like this AFAICT. Try it online!

but may be improved maybe using another technique

just found another solution

What does $1 do?

@cairdcoinheringaahing it 's the first argument in a script, for example script.sh '[[' or a function f '=', the result is the exit status 0 means success, 1 failed

the double quotes arround $1 prevent wildcard characters * or ? inside argument to have a special meaning and are taken literally

This reads the source file, no?

not really, it's a special variable, see also https://codegolf.meta.stackexchange.com/a/13638/68615, it's part of language, it's not the same as accessing to the source

Your first solution is more instructive to me, but a nice find with that environment variable. +1

Haskell, 92 bytes
import Data.List;f s=isInfixOf s$(++)<*>show$"import Data.List;f s=isInfixOf s$(++)<*>show$"

Try it online! Obvious extension of the standard quine. Getting rid of the import would be nice, but I doubt isInfixOf can be computed in a shorter amount of bytes.

Wolfram Language (Mathematica), 33 bytes
!StringFreeQ[ToString[#0], #1] &

Try it online!

nice! +1. I see comments for "ungolfed syntax" coming ;-)

Jelly, 10 bytes
“;⁾vṾƓẇ”vṾ

Try it online!
How it works
“;⁾vṾƓẇ”vṾ  Main link. No arguments.

“;⁾vṾƓẇ”    Set the left argument and the return value to ';⁾vṾƓẇ'.
         Ṿ  Uneval; yield '“;⁾vṾƓẇ”'.
        v   Dyadic eval; eval ';⁾vṾƓẇ' with argument '“;⁾vṾƓẇ”'.

  ⁾vṾ       Yield 'vṾ'.
 ;          Append it to '“;⁾vṾƓẇ”', yielding the source code.
     Ɠ      Read a string from STDIN.
      ẇ     Check if it's a substring of the source code.

Julia, 72 bytes
I now understand what people mean when they say that quine problems are just variations on the classic quine.
x="~y=contains\"x=\$(repr(x));\$x\",y)";~y=contains("x=$(repr(x));$x",y)

Explanation
#Defines x to be the next line of the source, with the help of escaping characters
x="~y=contains\"x=\$(repr(x));\$x\",y)";
#Interpolates together a comparison string, including repr(x), the re-escaped from of x, and x itself, for comparison.
~y=contains("x=$(repr(x));$x",y)

Vyxal D, 56 bitsv2, 7 bytes
`Iǎc`Iǎc

Try it Online!
Explained
`Iǎc`Iǎc
      ǎ   # Does all substrings of
`Iǎc`     #   The string "Iǎc"
     I    #   With a version surrounded in backticks prepended to itself
       c  # Contain the input?

Created with the help of Luminespire.

Perl 5, 60 + 2 (-pl) bytes
$_=(sprintf$a=q($_=(sprintf$a=q(%s),$a)=~/\Q$_/),$a)=~/\Q$_/

try it online

05AB1E, 17 bytes
0"D34çýIå"D34çýIå

Modification of the default quine 0"D34çý"D34çý by adding Iå.
Try it online.
Explanation:
0                    # Push 0 to the stack
                     #  STACK: [0]
 "D34çýIå"           # Push the string 'D34çýIå' to the stack
                     #  STACK: [0, 'D34çýIå']
          D          # Duplicate this string
                     #  STACK: [0, 'D34çýIå', 'D34çýIå']
           34ç       # Push '"' to the stack
                     #  STACK: [0, 'D34çýIå', 'D34çýIå', '"']
              ý      # Join the stack by this '"' delimiter
                     #  STACK: ['0"D34çýIå"D34çýIå']
               I     # Take the input
                     #  STACK: ['0"D34çýIå"D34çýIå', 'Iå"D']
                å    # Check if it's a substring of the source code
                     #  STACK [1]
                     # (Output the top of the stack implicitly)


text:
Bobby's Booby-Trapped Safe
Bobby's booby-trapped safe requires an n-digit code to unlock it. Alex has a probe which can test combinations without typing them onto the safe. The probe responds Fail if no individual digit is the same as that in its corresponding position in Bobby's code. Otherwise it responds Close, including when all digits are correct. For example, when n=3, if the correct code is 014, then the responses to 099 and 014 are both Close, but the response to 140 is Fail.
Your task is to create a program/function that takes n (a positive integer) as input and returns the answer to the following question:
If Alex is following an optimal strategy, in the worst-case scenario, what is the smallest number of attempts needed to guarantee that he knows the correct code, whatever it is?
This is a codegolf challenge, so make your code short.
Test Cases
> 1
9

> 2
11

> 3
13

> 4
16

> 5
19

> 6
21

This is a modified version of a problem from BMO2 2017.
Explanation of the Test Cases
Where n=1, in the worst case, Alex will try eight numbers that all fail. The ninth number he tries will determine what the code is. Therefore, the answer is nine.
Where n=2, there are a hundred possible codes. In the worst case, he will fail the first test and narrow it down to eighty-one possible codes. Failing will be the worst case (and so he'll keep failing) until Alex has narrowed it down to nine possible codes (after seven tries). If he fails the next one (on his eighth try), he'll have narrowed it down to four possible codes, so if he gets 'Close', then he'll have five possible codes. We can then deduce that Alex will need at least three more tries to guess the code because five distinct numbers cannot be represented with distinct two-digit binary codes. Thus, Alex needs at least eleven guesses. Now, observe that Alex can find the code in eleven guesses. He can try 00, 11, ..., 99. If he failed nine of those tests, the one he didn't fail is the answer. If he failed eight of them (suppose he didn't fail xx and yy), he can try xy. If xy fails, the code is yx. Otherwise, the code is xy. Therefore, the answer is eleven.
Where n=3, Alex will fail every try (like in the n=2 case). He will start with a thousand possible codes, then after his seventh guess he will have narrowed it down to sixty-four possibilities (in the worst case, when Alex has failed all the tests). Then, if Alex doesn't fail the next test, he will have narrowed it down to thirty-seven possibilities. Alex will then need at least six more guesses to find the code. Therefore, Alex needs at least thirteen guesses. In fact, finding the code within thirteen guesses is possible. A possible strategy is to try 000, 111, ..., 999. If nine of these fail, then the code that didn't fail is right. If eight of them failed, then (if xxx and yyy worked and zzz failed) Alex can do xzz, zxz and zzx to check if each digit is x or y. If seven codes failed, then (if xxx, yyy and zzz worked and www failed) Alex can do xww and yww (to find the first digit) and then there is just one more code (could be xyz, xzy, yxz, yzx, zxy or zyx) Alex can try to see what order the last two digits are in (since the code has to be made of three different digits).
A similar argument is used for n=4, n=5 and n=6. Note that a different strategy would have to be found for n>10.

I suggest adding a worked example. For instance, you could explain how you got 11 for the third test case. Also adding more test cases might be helpful

Related Math post and related proposed solution to the maths part of it.

When you say "a digit is correct", do you mean "the digit in that specific position is correct"?

@EriktheOutgolfer Yes. Added. Is that the only reason you voted to close or is there more stuff you recommend clarifying?

Everyone who voted to close, why?! Tell me what I need to correct and I'll fix it!

Could you perhaps add some more test cases for n=5 through n=10? I have a formula with the correct results for the four test cases, but I'm fairly certain it's incorrect for n=5 and higher right now..

@J843136028 I'm not really sure what you're asking here. What is the "optimal strategy"? And I'm pretty sure that a "Fail" is far from worst-case scenario.

I guess that the OP may not have test case. | An optimal strategy is an strategy that guarantee worst case result. @J843136028 you can add < if you think it's what you meant.

@EriktheOutgolfer There isn't necessarily "the optimal strategy". For different values of n, there are probably different optimal strategies. An optimal strategy is a strategy for a particular value of n is one that means the fewest guesses possible. Failing the first few tests is the worst case for values of n from 1 to 4 because you start with 10^n possible codes and then if you fail the first test, you narrow it down to 9^n possible codes which is more than half of 10^n. Then, after 9^n codes, another fail makes you narrow it down to 8^n codes. This carries on until (k+1)^n>2k^n.

@KevinCruijssen I added n=5 and n=6.

Mathematica, 125 bytes (121 chars)
(f@{_}=0;f@l_:=1+Min[Max[{g=GatherBy[l,vFreeQ[#-v,0]]}~With~If[Length@g<2,∞,f/@g]]&/@R~T~#];f@(T=Tuples)[R=Range@10,#])&

Try it online!
(it actually does not run the code, just the function pasted into TIO. So because the function is not invoked, it does nothing)
This cannot be run even with input n=1 because it has no memoization or whatever optimization. The ungolfed code below, however, does return 9 for n=1.
Ungolfed code:
n = Input[];

base = 10;

Clear@f;
f@{_} = 0;
f@l_ := f@l =
  1 + Min[
    Max[
       With[{groups = GatherBy[l, v \[Function] FreeQ[# - v, 0]]},
        If[Length@groups == 1, Infinity, f /@ groups]
        ]
       ] & /@ Tuples[Range@base, n]
    ]

f@Tuples[Range@base, n]

This code run in upper bound time O(2^(10^n poly(n))), which is impractical for all n ≥ 2.
Explanation:
Let a number be represented as a list of n numbers from 1 to 10. There are 10^n numbers.
Then, the function f receive a list of "numbers" l (so a 2D list of digits), and return the information "assuming all the possible candidate numbers are in the list l, at least how many question are necessary to reduce it to 1 candidate in the worst case?"
So the function f is defined as:
f@{_} = 0;

When there is only 1 candidate, we only need to ask 0 more questions.
f@l_ := f@l =

Memoization (in ungolfed code) to slightly improve performance.
1 +

Ask one question.
/@ Tuples[Range@base, n]

For each possible number (numbers are represent as n-tuple of digits, each digit is in the range from 1 to base (10)) to be asked,
Min[]

find the minimum (best strategy)
groups = GatherBy[l, v \[Function] FreeQ[# - v, 0]]

partition the candidates to 2 groups: one gives the value "Close" when ask this number, and the other gives the value "Fail" when ask this number.
If[Length@groups == 1,

If all the numbers in the list l get to the same answer when test,
Infinity

return Infinity (avoid asking this question, avoid loop forever)
, f /@ groups

otherwise recursively apply the function f to the resulting group
Max[]

and get the maximum (worst case).