37
\$\begingroup\$

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

\$\endgroup\$
5
  • \$\begingroup\$ Related \$\endgroup\$ Nov 13, 2017 at 22:55
  • \$\begingroup\$ Great challenge, complex yet simple. \$\endgroup\$
    – ATaco
    Nov 13, 2017 at 23:40
  • \$\begingroup\$ @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). \$\endgroup\$ Nov 13, 2017 at 23:45
  • 2
    \$\begingroup\$ Thank you so much for making them forward slashes instead of backward slashes. \$\endgroup\$ Nov 14, 2017 at 0:40
  • 1
    \$\begingroup\$ @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?! \$\endgroup\$ Nov 14, 2017 at 0:53

23 Answers 23

11
\$\begingroup\$

Charcoal, 30 25 bytes

FN«J﹪ι⁵⁰×⁵÷ι⁵⁰¿﹪⊕ι⁵↓⁴«←↙⁴

Try it online! Link is to verbose version of code. Explanation:

 N                          Input number
F «                         Loop over implicit range
     ι     ι                Loop index
      ⁵⁰    ⁵⁰              Literal 50
    ﹪                       Modulo
          ÷                 Integer divide
         ⁵                  Literal 5
        ×                   Multiply
   J                        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
\$\endgroup\$
6
\$\begingroup\$

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!

\$\endgroup\$
5
6
\$\begingroup\$

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!

\$\endgroup\$
5
\$\begingroup\$

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

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

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

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

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>
<pre id=O style="border-bottom:1px solid black"></pre>

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.

\$\endgroup\$
3
  • \$\begingroup\$ Took me a solid 10 minutes to work through the ungolfed version and understand it. =^P You've got some nice tricks in there. \$\endgroup\$
    – DLosc
    Nov 15, 2017 at 5:36
  • \$\begingroup\$ pretty sure you can do for(i=0; ++i < n/50; s+=N) which saves one char \$\endgroup\$ Nov 20, 2017 at 18:47
  • \$\begingroup\$ @DanielIndie That fails because the outer loop runs one too few times: Try it online! \$\endgroup\$ Nov 20, 2017 at 19:38
4
\$\begingroup\$

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.
\$\endgroup\$
2
  • \$\begingroup\$ I love the idea of using infixes for this part 4,&' '\7$'|||/' \$\endgroup\$
    – Jonah
    Nov 15, 2017 at 5:10
  • \$\begingroup\$ @Jonah it had to go :( \$\endgroup\$
    – FrownyFrog
    Nov 16, 2017 at 19:54
3
\$\begingroup\$

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.

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

Python, 129 113 112 bytes

f=lambda n:n>50and f(50)+"\n\n"+f(n-50)or"\n".join(("|||/|||"[k:k+4]+" ")*(n//5)+" "+"|"*(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

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ 142 bytes in 18 minutes? Not bad :). \$\endgroup\$ Nov 13, 2017 at 23:16
  • 3
    \$\begingroup\$ Got to work quick when you should really have gone to bed an hour ago \$\endgroup\$ Nov 13, 2017 at 23:18
  • \$\begingroup\$ Quick ~= Quality ;). Nice job. \$\endgroup\$ Nov 13, 2017 at 23:29
  • 3
    \$\begingroup\$ Errr... that may be misconstrued. Saying you did quality work fast... Not the opposite. \$\endgroup\$ Nov 13, 2017 at 23:36
  • 2
    \$\begingroup\$ 138 bytes \$\endgroup\$
    – ovs
    Nov 14, 2017 at 13:39
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ Neat! But from the second tally-line on the tallies are not crossed completely. \$\endgroup\$ Nov 15, 2017 at 10:22
  • \$\begingroup\$ When running your "try it online" example from 5.5 on, locally 5.6.31 and 7.1.9. \$\endgroup\$ Nov 15, 2017 at 14:49
  • 1
    \$\begingroup\$ $x is only undefined in first loop, this messes up output for tally greater than 54. Fixed, but not golfed: sandbox.onlinephpfunctions.com/code/… \$\endgroup\$ Nov 15, 2017 at 15:40
  • \$\begingroup\$ @SpazzMarticus fixed \$\endgroup\$
    – Titus
    Nov 16, 2017 at 11:47
  • \$\begingroup\$ Cool! It was my first time debugging golfed code, you gave me a hard time! :) I think I'm hooked! \$\endgroup\$ Nov 16, 2017 at 12:35
1
\$\begingroup\$

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!

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

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!

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

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.

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

Canvas, 30 bytes

H╷‾#%╵¹‾#÷U╷5×¹5%?4|*];4-;4/}╋

Try it here!

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

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

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

Stax, 24 bytes

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

Run and debug it

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

C (gcc), 107 106 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

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

Vyxal L, 169 bitsv2, 21.125 bytes

4ẋ5ẇƛ\|*₅5=[ḢėṘƛ÷$\/Ȧ;ðwj

Try it Online!

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

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!

\$\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.