33
\$\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\$
  • \$\begingroup\$ Related \$\endgroup\$ – Magic Octopus Urn Nov 13 '17 at 22:55
  • \$\begingroup\$ Great challenge, complex yet simple. \$\endgroup\$ – ATaco Nov 13 '17 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\$ – Magic Octopus Urn Nov 13 '17 at 23:45
  • 1
    \$\begingroup\$ Thank you so much for making them forward slashes instead of backward slashes. \$\endgroup\$ – totallyhuman Nov 14 '17 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\$ – Magic Octopus Urn Nov 14 '17 at 0:53

17 Answers 17

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

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

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
\$\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\$
  • \$\begingroup\$ @FrownyFrog fixed, thanks! \$\endgroup\$ – HyperNeutrino Nov 14 '17 at 17:36
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\$
  • \$\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 '17 at 5:36
  • \$\begingroup\$ pretty sure you can do for(i=0; ++i < n/50; s+=N) which saves one char \$\endgroup\$ – DanielIndie Nov 20 '17 at 18:47
  • \$\begingroup\$ @DanielIndie That fails because the outer loop runs one too few times: Try it online! \$\endgroup\$ – Justin Mariner Nov 20 '17 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\$
  • \$\begingroup\$ I love the idea of using infixes for this part 4,&' '\7$'|||/' \$\endgroup\$ – Jonah Nov 15 '17 at 5:10
  • \$\begingroup\$ @Jonah it had to go :( \$\endgroup\$ – FrownyFrog Nov 16 '17 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\$
3
\$\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\$
3
\$\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\$
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\$
  • 1
    \$\begingroup\$ 142 bytes in 18 minutes? Not bad :). \$\endgroup\$ – Magic Octopus Urn Nov 13 '17 at 23:16
  • 3
    \$\begingroup\$ Got to work quick when you should really have gone to bed an hour ago \$\endgroup\$ – Halvard Hummel Nov 13 '17 at 23:18
  • \$\begingroup\$ Quick ~= Quality ;). Nice job. \$\endgroup\$ – Magic Octopus Urn Nov 13 '17 at 23:29
  • 3
    \$\begingroup\$ Errr... that may be misconstrued. Saying you did quality work fast... Not the opposite. \$\endgroup\$ – Magic Octopus Urn Nov 13 '17 at 23:36
  • 1
    \$\begingroup\$ 138 bytes \$\endgroup\$ – ovs Nov 14 '17 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\$
  • \$\begingroup\$ Neat! But from the second tally-line on the tallies are not crossed completely. \$\endgroup\$ – SpazzMarticus Nov 15 '17 at 10:22
  • \$\begingroup\$ When running your "try it online" example from 5.5 on, locally 5.6.31 and 7.1.9. \$\endgroup\$ – SpazzMarticus Nov 15 '17 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\$ – SpazzMarticus Nov 15 '17 at 15:40
  • \$\begingroup\$ @SpazzMarticus fixed \$\endgroup\$ – Titus Nov 16 '17 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\$ – SpazzMarticus Nov 16 '17 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
\$\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\$
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, privacy policy and cookie policy

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