title: Arbitrary Interval Ruler

text:
# Question
Title: Arbitrary Interval Ruler
Make a program that takes a length and list of intervals and outputs a ruler of that length with longer ticks for each interval using the line drawing characters `┌ ┬ ┐ │ ╵`

* The first row of the output should begin with the tick for 0 with  and end with a tick for the length with , with a  being used for every character in between. There will be a total of `length` \+ 1 line drawing characters in this first row.
* A tick should be lengthened vertically by half-character increments using  and  based on the input intervals.
* Intervals are listed from smallest to largest, relative to the interval before it. To elaborate:
    + The first interval tells how many base ticks (the first row - one character per tick) are in the second-smallest interval (the smallest interval being 1). For example, \[3\] will lengthen every third tick by a half-character.
    + The second and subsequent intervals are in terms of the next smallest interval. For example \[3, 5\] will lengthen every 15th base tick by a full character and \[3, 5, 2\] will lengthen every 30th base tick by a character and a half.
    + A sub-interval of 1 is valid and effectively means that the last interval lines are lengthened by a full character instead of a half-character.
* The example test cases should help to clarify how this works.

## Examples/Test Cases

3, \[\]:

```
┌┬┬┐

```

9, \[3\]:

```
┌┬┬┬┬┬┬┬┬┐
╵  ╵  ╵  ╵

```

30, \[5, 2\]:

```
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│    ╵    │    ╵    │    ╵    │

```

32, \[4, 2, 2, 2\]:

```
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│   ╵   │   ╵   │   ╵   │   ╵   │
│               ╵               │

```

48, \[5, 3, 2\]

```
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│    ╵    ╵    │    ╵    ╵    │    ╵    ╵    │
╵                             ╵

```

24, \[7, 3\]

```
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│      ╵      ╵      │

```

17, \[3, 2, 1\]

```
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│  ╵  │  ╵  │  ╵
╵     ╵     ╵

```

1, \[23, 19, 13, 11, 7, 5, 3, 2, 1\]

```
┌┐
│
│
│
│
╵

```

## Other Rules/Notes

* Input and output can use any convenient format
* The ruler doesn't have to end on a major tick
* The interval list may be empty
* The zeroth tick is *always* within all intervals.
* You may assume the ruler length and intervals will always be a positive integers less than 120
* Trailing whitespace is fine, but leading whitespace is not.
* Any fixed-single-wide space is allowed as a spacing character if you, for some reason, want to use something other than ASCII spaces.

Happy Golfing!

# Answer
# JavaScript (Node.js), 123 bytes

```
l=>g=([p,q,...t],h='┌'.padEnd(l,'┬')+`┐
`)=>p?h+g(t,h.replace(/\S/g,c=>'╵│ '[c>'╴'||++i%p?2:i/p%q<1|0],i=-1)):h

```

Try it online!

Use this function as `f(20)([5, 2])`.

---

Thanks Arnauld, saves 4 bytes.
> 5 votes

# Answer
# Perl 6, ~~130 122 102~~ 92 bytes

*-10 bytes thanks to nwellnhof!*

```
{'┌'~'┬'x$^a-1~'┐',|map {[~] <<' '╵ │>>[:1[$_ X%%@_]for 0..$a]},batch [\*] @^b: 2}

```

Try it online!

Ah yes, much shorter than my previous method. This is an anonymous code block that returns a list of lines.

### Explanation:

```
{                                                   }   # Anonymous code block
 '┌'~'┬'x$^a-1~'┐',     # Return the first line
 |[\*] @^b          # Get the cumulative product of the input list
              .batch(2) # And split it into pairs
  .map:{                                      }  # Map each pair to
                                    for 0..$a    # For each interval
                        :1[$_ X%%@_]    # Whether it is divisible by none of the pair, one of the pair, or both
            <<' '╵ │>>[                     ]      # Map to a list of characters
        [~]        # And join

```
> 3 votes

# Answer
# Dyalog APL, ~~66~~ ~~64~~ ~~58~~ 52 bytes

```
{'┌┐'@0⍵@0⍉('┬│',⎕UCS 9589)/⍤1⍨1,⍉0 2⊤⊥¨⍨0=(⍵+1)⍴⍳⍺}

```

Try it online!

~~¯2~~ ~~¯8~~ ¯14 bytes thanks to ngn!
> 3 votes

# Answer
# Python 3, ~~173~~ 172 bytes

```
def f(w,n):
 print('┌'+'┬'*~-w+'┐');R=r=range(w+1)
 for i,j in zip(*[iter(n+[0])]*2):a=r[::i];r=j*[0]and a[::j];print(''.join(' ╵│'[(v in a)+(v in r)]for v in R))

```

Try it online!
> 2 votes

# Answer
# 05AB1E, 51 bytes

```
ÝεyIηPÖO2‰•5·W4•2äç×SI¯Qiεõ}}•áΣ=Yô•3äçy¹QyĀ+èš}ζJ»

```

Not too happy with the `I¯Qiεõ}}` as work-around for empty input-lists.. And can definitely be golfed at some other parts as well..

NOTE: Uses compressed integers converted to the required characters, because using the required characters directly means I'll have to count the entire program in UTF-8, increasing it by too much for all 05AB1E's builtin characters as well.

Try it online or verify all test cases.

**Explanation:**

```
Ý             # Create a list in the range [0, first (implicit) input-integer]
 ε            # Map each value `y` to:
   Iη         #  Get the prefixes of the second input-list
     P        #  Get the product of each prefix
  y   Ö       #  Check for each if its evenly dividing the value `y`
       O      #  Take the sum of that
        2‰    #  And then the divmod 2
  •5·W4•      #  Push compressed integer 94749589
        2ä    #  Split into two equal-sized parts: [9474,9589]
          ç   #  Convert each to a character: ["│","╵"]
           ×  #  Repeat each based on the divmod 2 result
            S #  And convert it to a flattened list of characters
  I¯Qi   }    #  If the second input-list was empty:
      εõ}     #   Map each list to an empty string
              #   (for some reason `€õ` doesn't work here..)
  •áΣ=Yô•     #  Push compressed integer 948495169488
         3ä   #  Split into three equal-sized parts: [9484,9516,9488]
           ç  #  Convert each to a character: ["┌","┬","┐"]
  y¹Q         #  Check if the value `y` is equal to the first input-integer
              #  (1 if truthy; 0 if falsey)
     yĀ       #  Check if the value `y` is NOT 0 (1 if truthy; 0 if falsey)
       +      #  Add both checks together
        è     #  Use it to index into the list ["┌","┬","┐"]
         š    #  And prepend the result in front of the other characters
 }ζ           # After the map: zip/transpose; swapping rows and columns (with space filler)
   J          # Join every inner list together to a single string
    »         # Join the lines with newline delimiter (and output implicitly)

```

See this 05AB1E tip of mine (section *How to compress large integers?*) to understand why `•5·W4•` is `94749589` and `•áΣ=Yô•` is `948495169488`.
> 2 votes

# Answer
# Charcoal, 50 bytes

```
≔ＥηΠ…η⊕κη⪫┐┌×┬⊖θ↙↓ＥＥ⊕θΣＥη¬﹪ιλ⁺×│⊘ι×╵﹪ι²‖

```

Try it online! Link is to verbose version of code. Box-drawing characters have a 3 byte representation in Charcoal, so the above string is only 40 characters long. Explanation:

```
≔ＥηΠ…η⊕κη

```

Calculate the cumulative product of the intervals.

```
⪫┐┌×┬⊖θ↙

```

Print the first row of tick marks. The left and right characters are the wrong way around because the result is reflected later.

```
↓ＥＥ⊕θΣＥη¬﹪ιλ⁺×│⊘ι×╵﹪ι²

```

Calculate the number of intervals that are a factor of each tick mark. Generate a string of s of half that length and add  for odd lengths. Print each string downwards with subsequent strings in previous columns, i.e. reverse order.

Reflect everything to get the ruler in left-to-right order.
> 2 votes

# Answer
# Jelly,  ~~42~~  41 bytes

```
‘Rm×\}Ṭ€+2/
⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶
Ḷ¬;.Ḥ~W;ñị¢Y

```

A full program.
**Try it online!**

Or see a test-suite
Note: this code has been altered from a full program -- `ñ` (next link as a dyad) has been replaced with  (link at index 1 as a dyad) to allow it to be called multiple times by the footer.

### How?

```
‘Rm×\}Ṭ€+2/ - Link 1, lower interval tick types: length; intervals  e.g. 7; [3,2]
‘           - increment length                                           8
 R          - range                                                      [1,2,3,4,5,6,7,8]
     }      - use right argument for this monad as if it were a dyad:
   ×\       -   cumulative reduce by multiplication                      [3,6]
  m         - modulo slice (vectorises)                                  [[1,4,7],[1,7]]
      Ṭ€    - untruth €ach                               [[1,0,0,1,0,0,1],[1,0,0,0,0,0,1]]
        +2/ - pairwise reduce with addition                              [[2,0,0,1,0,0,2]]
            -   -- yielding a list of types for each row of characters below the first
            -      where 0 is a space, 1 is a short tick-mark and 2 is a long tick-mark

⁽!ṣ;“½¥÷I‘ÄỌṙ-;⁶ - Link 2, make character set: no arguments
⁽!ṣ              - literal 9474
    “½¥÷I‘       - list of code-page indices   = [10,4,28,73]
   ;             - concatenate              [9474,10,4,28,73]
          Ä      - cumulative addition      [9474,9484,9488,9516,9589]
           Ọ     - to characters            "│┌┐┬╵"
            ṙ-   - rotate left by -1        "╵│┌┐┬"
               ⁶ - literal space character  ' '
              ;  - concatenate              "╵│┌┐┬ "

Ḷ¬;.Ḥ~W;ñị¢Y - Main link: length, L; intervals, I
Ḷ            - lowered range         [ 0, 1, 2, ..., L-1]
 ¬           - logical Not           [ 1, 0, 0, ..., 0]
   .         - literal 0.5
  ;          - concatenate           [ 1, 0, 0, ..., 0, 0.5]
    Ḥ        - double                [ 2, 0, 0, ..., 0, 1]
     ~       - bitwise NOT           [-3,-1,-1, ...,-1,-2]
      W      - wrap that in a list  [[-3,-1,-1, ...,-1,-2]]
        ñ    - call next Link (1) as a dyad (f(L, I))
       ;     - (left) concatenated with (right)
          ¢  - call last Link (2) as a nilad (f())
         ị   - (left) index into (right)  (1-indexed and modular)
           Y - join with newline characters
             - implicit print

```
> 2 votes

# Answer
# Canvas, ~~42~~ ~~41~~ 40 bytes

```
┐”┬”┌”Ｏ⁸╷×ｏｏ╵（０）⁷｛＊Ｊ╵；∔｝ｍ｛２ｎ“╵”×；“│”××］⤢

```

Try it here! (with a font that monospaces the output)
> 2 votes

# Answer
# Emacs Lisp, 303 bytes

```
(defun f(a)(princ'┌)(dotimes(i(1-(car a)))(princ'┬))(princ'┐)(let((m 1))(while(cadr a)(let((q(caadr a))(w (cadadr a)))(princ"\n")(dotimes(i(1+(car a)))(cond((if w(= 0(mod i(* m q w))))(princ'│))((= 0(mod i (* m q)))(princ'╵))(t(princ" "))))(setq m(* m q(if w w 1)))(setcdr a`(,(cddadr a)))))))

```

Use this function as `(f '(30 (5 2)))`.

Better readable version:

```
(defun f (a)
  (princ '┌)
  (dotimes (i (1- (car a)))
    (princ '┬))
  (princ '┐)
  (let ((m 1))
    (while (cadr a)
      (let ((q (caadr a)) (w (cadadr a)))
    (princ "\n")
    (dotimes (i (1+ (car a)))
      (cond ((if w (= 0 (mod i (* m q w))))
        (princ '│))
       ((= 0 (mod i (* m q)))
        (princ '╵))
       (t
        (princ " "))))
    (setq m (* m q (if w w 1)))
    (setcdr a `(,(cddadr a)))))))

```
> 2 votes

# Answer
# Ruby, 126 bytes

```
->l,i{y=1;[?┌+?┬*~-l+?┐]+i.each_slice(2).map{|j,k|x=y*j;y=k&&x*k;(0..l).map{|z|'│╵ '[(z%x<=>0)+(k ?z%y<=>0:1)]}*''}}

```

Try it online!

Looks rather verbose with all that `each_slice` stuff, but will do for now, unless I manage to find a golfier approach.

Takes input as `l` for length and `i` for intervals, returns an array of strings.
> 1 votes

# Answer
# , ~~175~~ 170 bytes

```
function(l,i,`&`=rep)rbind(c('┌','┬'&l-1,'┐'),if(i)sapply(rowSums(!outer(0:l,cumprod(i),`%%`)),function(j,x=j%/%2,y=j%%2)c('│'&x,'╵'&y,' '&(1+sum(1|i))/2-x-y)))

```

Try it online!

Takes empty intervals as `0`, returns a matrix of characters. TIO link displays the output pretty-printed.
> 1 votes

# Answer
# Haskell, ~~167~~ ~~164~~ 149 bytes

```
n%l=unlines$("┌"++([2..n]>>"┬")++"┐"):[do p<-[0..n];let(j#a)b|1>p`rem`product(take j l)=a|1>0=b in(i-1)#(i#"│"$"╵")$" "|i<-[1,3..length l]]

```

Try it online! Slightly golfed different approach by Οurous.

---

```
n%l|let c=take(n+1).cycle;m&(x:y:r)=c('│':init([1..y]>>(m*x)!" "++"╵"))++'\n':(m*x*y)&r;m&[x]=c$'╵':(m*x)!" ";m&e=[]='┌':n!"┬"++"┐\n"++1&l
n!s=[2..n]>>s

```

Try it online! There are still some redundancies which look like they could be exploited, but so far they withstood all further golfing attempts.

---

The previous 167 byte solution is the same apart from newline handling and is probably slightly better readable:

```
n%l=unlines$('┌':n!"┬"++"┐"):(take(n+1)<$>1&l)
n!s=[2..n]>>s
m&(x:y:r)=cycle('│':init([1..y]>>(m*x)!" "++"╵")):(m*x*y)&r
m&[x]=[cycle$'╵':(m*x)!" "]
m&e=[]

```

Try it online!
> 1 votes

# Answer
# PowerShell, 152 bytes

```
param($t,$i)"┌$('┬'*--$t)┐"
$i|%{$s=++$s*$_-1;$p=".(.{$s}|.*$)"
if($r){$r-replace$p,'│$1';rv r}else{$r=' '*($t+2)-replace$p,'╵$1'}}
if($r){$r}

```

Try it online!

Unrolled:

```
param($ticks,$intervals)
"┌$('┬'*--$ticks)┐"                         # implicit output
$intervals|%{
    $step=++$step*$_-1
    $pattern=".(.{$step}|.*$)"
    if($row){
        $row-replace$pattern,'│$1'          # implicit output
        Remove-Variable row
    }else{
        $row=' '*($ticks+2)-replace$pattern,'╵$1'
    }
}
if($row){$row}                              # implicit output

```
> 1 votes

# Answer
# C# (Visual C# Interactive Compiler), 204 bytes

```
a=>b=>{Write("┌"+"┐\n".PadLeft(++a,'┬'));for(int i=1;;i++,WriteLine())for(int j=0;j<a;){var m=b.Select((c,d)=>b.Take(d+1).Aggregate((e,f)=>e*f)).Count(c=>j++%c<1);Write(m<1|i>m?" ":m<2?"╵":"|");}}

```

Try it online!

Outputs, but gets stuck in an infinite loop.
> 0 votes

# Answer
# Clean, ~~221~~ ~~201~~ ~~195~~ 162 bytes

```
import StdEnv
$n l=[["┌":repeatn(n-1)"┬"]++["┐"]:[[if(?(i-1))if(?i&&l%(i,i)>[])"│""╵"" "\\p<-[0..n],let?j=1>p rem(prod(l%(0,j)))
]\\i<-[1,3..length l]]]

```

Try it online!

Returns a list of lists of UTF-8 characters (as strings, since Clean has no innate UTF-8 support).

Works by generating the first line, then taking the product of prefixes of the list provided in groups of two, and checks which mark to draw based on whether the product divides the current character position.

Ungolfed:

```
$ n l
    = [
        ["┌": repeatn (n - 1) "┬"] ++ ["┐"]:
        [
            [
                if(? (i - 1))
                    if(? i && l%(i, i) > [])
                        "│"
                        "╵"
                    " "
                \\ p <- [0..n]
                , let
                    ? j = 1 > p rem (prod (l%(0, j)))
            ]
            \\ i <- [1, 3.. length l]
        ]
    ]

```
> 0 votes

---
Tags: code-golf, ascii-art
---


title: Draw Recamán's sequence with ASCII

text:
# Question
Title: Draw Recamán's sequence with ASCII
Recamán's sequence (A005132) is a mathematical sequence, defined as such:

$$A(n) = \begin{cases}0 & \textrm{if } n = 0 \\ A(n-1) - n & \textrm{if } A(n-1) - n \textrm{ is positive and not already in the sequence} \\ % Seems more readable than %A(n-1) - n & \textrm{if } A(n-1) \> n \wedge \not\exists m \< n: A(m) = A(n-1)-n \\ A(n-1) + n & \textrm{otherwise} \end{cases}$$

An alternative, simpler verbal explanation is as follows:

> Subtract unless you can't (the number is negative, or has been used before), in which case add.

The first few terms are \\$0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11\\$

Now, there is already this challenge which asks you to generate the `n`th term of the sequence. This one is slightly different.

# Challenge

Given a number `n`, draw the first `n` terms of the sequence. What do I mean by 'draw'? Let me demonstrate:

1. Draw a number line `max([A(y) for y<=n])` units long. We'll assume `n` is 5, for now, so the number line is 6 units long (since the largest of \\$A(1) = 0\\$, \\$A(2) = 1\\$, \\$A(3) = 3\\$, \\$A(4) = 6\\$ and \\$A(5) = 2\\$ is \\$6\\$). Make the line from underscores, starting at 0:

`______`

2. Start with the transition between the first and second terms: that is, 0 and 1. Use `|` and `-` to draw a *square* (equal length and height), going upwards. In this case, we'll have to miss out the `-` because the distance is only 1.

```
||
______

```
3. Now, we'll draw on the next step (\\$A(2) = 1\\$ to \\$A(3) = 3\\$) on the bottom of the line (we alternate between up and down each time):

```
||
______
 | |
 |-|

```

As you can see, this line also has a height of 2, since the height must be equal to the distance between the two terms.

If we continue, we will eventually get to:

```
   |--|
   |  |
|| |  |
______
 |||  |
 |||  |
  |   |
  |---|

```

# Rules

* If there is a `-` and `|` colliding, the later one takes priority.
* There may be preceeding/trailing **spaces** before/after the image, but trailing/preceeding `_`s or `-`s are not allowed (exception is 0- or 1- indexing)
* You can choose to set the 0 point just before the first `_` on the number line, or just after it.
* No alternative characters for `-`, `|` or `_` may be used.
* This is , so shortest answer in bytes wins.

# Test case

Here is another test case, with `n=10`

```
            |-------|
            ||-----||
            ||     ||
  |----|    ||     ||
  |    |    ||     ||
  ||--||    ||     ||
  ||  ||    ||     ||
||||  ||    ||     ||
_____________________
 |||  ||   |||     ||
 |||  ||   |||     ||
  |   ||   |||     ||
  |---||   |||     ||
       |   |||     ||
       |---|||     ||
           ||------||
           |--------|

```

# Answer
> 5 votes
# Jelly, ~~70~~ 65 bytes

```
µ_ż+ɗLṪ>Ƈ-ḟ⁸Ḣṭµ¡µL;ⱮṀ’ṭr,;ɗƝJW,RN¹ƭƲ€$+Lp""ƲZẎ€Ʋ‘ŒṬ×"J$»/ị“-|_ ”Y

```

Try it online!

A full program taking a single integer \\$n\\$ via STDIN and outputting the ASCII art based on zero-indexing.

---
Tags: code-golf, ascii-art, sequence
---


title: Draw ASCII Playing Cards

text:
# Question
Title: Draw ASCII Playing Cards
Consider these 15 ASCII playing card patterns (ace through Joker, and the back side), where `X` is a placeholder for the suit symbol: (they look better with less line spacing)

```
 -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------
|AX           | |2X           | |3X           | |4X           | |5X           | |6X           | |7X           | |8X           | |9X           | |10X          | |JX           | |QX           | |KX           | |J            | |* * * * * * *|
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |O  -------   | | * * * * * * |
|  |       |  | |  |       |  | |  |       |  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X      |  | |  |X      |  | |  |X      |  | |K |       |  | |* * * * * * *|
|  |       |  | |  |   X   |  | |  |   X   |  | |  |       |  | |  |       |  | |  |       |  | |  |   X   |  | |  |   X   |  | |  |       |  | |  |   X   |  | |  |       |  | |  |       |  | |  |       |  | |E | J     |  | | * * * * * * |
|  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |X     X|  | |  |X     X|  | |  |       |  | |  |       |  | |  |       |  | |R |  O    |  | |* * * * * * *|
|  |   X   |  | |  |       |  | |  |   X   |  | |  |       |  | |  |   X   |  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |   X   |  | |  |       |  | |  |   J   |  | |  |   Q   |  | |  |   K   |  | |  |   K   |  | | * * * * * * |
|  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |X     X|  | |  |X     X|  | |  |       |  | |  |       |  | |  |       |  | |  |    E  | J| |* * * * * * *|
|  |       |  | |  |   X   |  | |  |   X   |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |   X   |  | |  |       |  | |  |   X   |  | |  |       |  | |  |       |  | |  |       |  | |  |     R | O| | * * * * * * |
|  |       |  | |  |       |  | |  |       |  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |X     X|  | |  |      X|  | |  |      X|  | |  |      X|  | |  |       | K| |* * * * * * *|
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------  E| | * * * * * * |
|           XA| |           X2| |           X3| |           X4| |           X5| |           X6| |           X7| |           X8| |           X9| |          X10| |           XJ| |           XQ| |           XK| |            R| |* * * * * * *|
 -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------

```

Write a program that takes in a string denoting a space separated sequence of cards using...

* `A 2 3 4 5 6 7 8 9 10 J Q K` followed by one of `C D H S` (for clubs, diamonds, hearts, and spades) for the 52 standard cards.
* A single `R` for a Joker.
* A single `B` for the back side (a face down card).

So the string `B AS KH 10C R JD` denotes a face down card, followed by an ace of spades, followed by a king of hearts, followed by a ten of clubs, followed by a Joker, followed by a jack of diamonds.

Your program needs to print the corresponding ASCII playing cards to stdout, replacing`X` with the appropriate suit symbol.

For example, the output for `B AS KH 10C R JD` would be

```
 -------------   -------------   -------------   -------------   -------------   -------------
|* * * * * * *| |AS           | |KH           | |10C          | |J            | |JD           |
| * * * * * * | |   -------   | |   -------   | |   -------   | |O  -------   | |   -------   |
|* * * * * * *| |  |       |  | |  |H      |  | |  |C     C|  | |K |       |  | |  |D      |  |
| * * * * * * | |  |       |  | |  |       |  | |  |   C   |  | |E | J     |  | |  |       |  |
|* * * * * * *| |  |       |  | |  |       |  | |  |C     C|  | |R |  O    |  | |  |       |  |
| * * * * * * | |  |   S   |  | |  |   K   |  | |  |       |  | |  |   K   |  | |  |   J   |  |
|* * * * * * *| |  |       |  | |  |       |  | |  |C     C|  | |  |    E  | J| |  |       |  |
| * * * * * * | |  |       |  | |  |       |  | |  |   C   |  | |  |     R | O| |  |       |  |
|* * * * * * *| |  |       |  | |  |      H|  | |  |C     C|  | |  |       | K| |  |      D|  |
| * * * * * * | |   -------   | |   -------   | |   -------   | |   -------  E| |   -------   |
|* * * * * * *| |           SA| |           HK| |          C10| |            R| |           DJ|
 -------------   -------------   -------------   -------------   -------------   -------------

```

You can take the input from stdin or write a function that takes a string.

The submission with the shortest number of characters wins.

**Bonus:** Subtract **30** from your character count if you use the black Unicode suit symbols `♣ ♦ ♥ ♠` instead of `C D H S` in your output. (The input always uses `C D H S`.)

# Notes

* There may be more than 54 cards in the input string and there may be duplicates of any card.
* There should be no output if the input is the empty string.
* There should be no trailing spaces besides (optionally) the two that make up the right corners of the last card.
* You may assume the input is valid.
* **Update:** The lower right label on standard cards has been reversed so the value is in the corner. The lower right Joker label hasn't changed.

# Answer
# JavaScript (E6) 542 (572 - bonus 30) ~~553 564 576~~

3 kinds of shapes:

1. Back and Joker: more or less literal
2. JQK: mark at topleft and rightbottom, inner frame and 3 kind of rows inside, always the same structure
3. A...10: mark at topleft and rightbottom, inner frame with 3 kind of rows inside, variable with the numeric value. Taken care of with lookup using array and q variable

The `z` string (compressed) contains the basic building blocks for

* numeric cards - 3 blocks, 7 chars each
* joker - 11 blocks, 13 char each, used simply in sequence

*Bonus note* The code for winning the 30 points bonus is 29 chars.

```
F=c=>(
  p='|',b=' ',d=b+b,t=d+b,
  S='substr',
  z="9J2J4J55O102K |6|1E | J4|1R |1O3|3|2K2|3|3E1| J1|4R | O1|6| K201E55R".replace(/\d/g,n=>n++?b.repeat(n):l='-------'),
  i=7,
  console.log([c.split(b).map(c=>
    m<d
      ?b+l+l[S](1)+b
      :p+(c=='B'
        ?'* '.repeat(i)[S](i,13)
        :c=='R'
          ?z[S](i,13)
          :(
             [,h,k]=c.match(/(.+)(.)/),
             k='♣♦♥♠'['CDHS'.search(k)], //comment to avoid the unicode symbols
             n=h-1|0,
             s=t+t+t+(n>8?b:d),
             m-7
              ?m-8
                ?m-9
                  ?d+p+(h>'A'
                     ?-m?m-6?m-3?t+b+t:t+h+t:t+t+k:k+t+t
                     :z[S](([64,1028,1092,8194,8258,8322,8326,9350,8802,9766][n]>>m*2&3)*7,7).replace(/J/g,k)
                   )+p+d
                  :t+l+t
                :s+k+h
              :h+k+s
            )
       )+p
    ).join(b,i+=13)
  for(m of ' 79012345698 ')].join('\n'))
)

```

**Test** In FireFox/FireBug console

```
F('10C JD QH KS AC B R')

F('2C 3D 4H 5S 6C 7D 8H 9S')

```

*Output*

```
 -------------   -------------   -------------   -------------   -------------   -------------   -------------
|10♣          | |J♦           | |Q♥           | |K♠           | |A♣           | |* * * * * * *| |J            |
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | | * * * * * * | |O  -------   |
|  |♣     ♣|  | |  |♦      |  | |  |♥      |  | |  |♠      |  | |  |       |  | |* * * * * * *| |K |       |  |
|  |   ♣   |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | | * * * * * * | |E | J     |  |
|  |♣     ♣|  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |* * * * * * *| |R |  O    |  |
|  |       |  | |  |   J   |  | |  |   Q   |  | |  |   K   |  | |  |   ♣   |  | | * * * * * * | |  |   K   |  |
|  |♣     ♣|  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |* * * * * * *| |  |    E  | J|
|  |   ♣   |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | | * * * * * * | |  |     R | O|
|  |♣     ♣|  | |  |      ♦|  | |  |      ♥|  | |  |      ♠|  | |  |       |  | |* * * * * * *| |  |       | K|
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | | * * * * * * | |   -------  E|
|          ♣10| |           ♦J| |           ♥Q| |           ♠K| |           ♣A| |* * * * * * *| |            R|
 -------------   -------------   -------------   -------------   -------------   -------------   -------------

 -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------
|2♣           | |3♦           | |4♥           | |5♠           | |6♣           | |7♦           | |8♥           | |9♠           |
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   |
|  |       |  | |  |       |  | |  |♥     ♥|  | |  |♠     ♠|  | |  |♣     ♣|  | |  |♦     ♦|  | |  |♥     ♥|  | |  |♠     ♠|  |
|  |   ♣   |  | |  |   ♦   |  | |  |       |  | |  |       |  | |  |       |  | |  |   ♦   |  | |  |   ♥   |  | |  |       |  |
|  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |♠     ♠|  |
|  |       |  | |  |   ♦   |  | |  |       |  | |  |   ♠   |  | |  |♣     ♣|  | |  |♦     ♦|  | |  |♥     ♥|  | |  |   ♠   |  |
|  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |♠     ♠|  |
|  |   ♣   |  | |  |   ♦   |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |   ♥   |  | |  |       |  |
|  |       |  | |  |       |  | |  |♥     ♥|  | |  |♠     ♠|  | |  |♣     ♣|  | |  |♦     ♦|  | |  |♥     ♥|  | |  |♠     ♠|  |
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   |
|           ♣2| |           ♦3| |           ♥4| |           ♠5| |           ♣6| |           ♦7| |           ♥8| |           ♠9|
 -------------   -------------   -------------   -------------   -------------   -------------   -------------   -------------

```

**Not golfed code**

```
F=c=>
{
  p='|',b=' ',d=b+b,t=d+b;
  l='------';
  z="9X2X4XJ55O10-2K |6|1E | J4|1R |1O3|3|2K2|3|3E1| J1|4R | O1|6| K20-1E55R".replace(/\d/g,n=>-n?b.repeat(-~n):l);
  c=c.split(b);
  for(o=i=''; c[0]&&i<13; i++)
  {
    o+=c.map(c => {
      if (i==0 || i==12) r=' -'+l+l+b;
      else
      {
        if (c=='B') r=' *'.repeat(7).substr(i&1,13);
        else if (c=='R') r=z.substr(i*13+8,13);
        else {
          [,h,k]=c.match(/(.+)(.)/),n=h-1|0,
          k='♣♦♥♠'[{C:0,D:1,H:2,S:3}[k]],
          r=t+t+t+(n>8?b:d);
          if(i==1)r=h+k+r;
          else if(i==11)r+=k+h;
          else if(i==2||i==10)r=t+'-'+l+t;
          else {
            if (h>'A')
            {
              if(i==3)r=k+t+t;
              else if(i==9)r=t+t+k;
              else if(i==6)r=t+h+t;
              else r=t+b+t
            }
            else
            {
              q=[64,1028,1092,8194,8258,8322,8326,9350,8802,9766][n]>>(i+i-6)&3,
              r=z.substr(q*7,7).replace(/X/g,k)
            }
            r=d+p+r+p+d
          }
        }
        r=p+r+p
      }
      return r
    }).join(' ')+'\n'
  }
  console.log(o);
}

```
> 9 votes

# Answer
# C# - 906

Rather large and simple C# program that takes command-line input and outputs to standard output. There is probably a lot that can still be golfed, I've spotted a few boring bytes while writing this, but that will have to wait. I don't think I will be going for the Unicode suit character bonus.

Golfed code:

```
class P{static void Main(string[]A){int O,i=0,L,n;for(;i<13;i++){var k="";foreach(var a in A){var R=new char[208];System.Action<int,int,string,int>P=(s,l,g,w)=>{for(O=0;O<l;s+=O%w<1?17-w:1)R[s]=g[O++%g.Length];};P(0,208," ",16);P(1,13,"-",13);P(193,13,"-",13);P(16,11,"|",1);P(30,11,"|",1);if(a=="B")P(17,143,"* ",13);else{P(36,7,"-",7);P(164,7,"-",7);P(51,7,"|",1);P(59,7,"|",1);if(a=="R"){P(17,5,"JOKER",1);P(125,5,"JOKER",1);P(69,25,"J     O     K     E     R",5);}else{L=a.Length;var S=a.Substring(L-1);var v=a.Substring(0,L-1);P(17,L,a,L);P(190-L,L,S+v,L);if(int.TryParse(v,out n)){var f=new string[]{S="HEHI",S+"HG",S="EDKDEJKJ",S+"HG",v=S+"EGKG",v+="HE",v+"HI",(S+="EFEHKFKH")+"HG",S+"HEHI",}[n-2];for(O=0;O<f.Length;)R[f[O++]+f[O++]*16-1105]=a[L-1];}else{if(v=="A"){P(103,1,S,1);}else{P(52,1,S,1);P(154,1,S,1);P(103,1,v,1);}}}}for(O=0;O<16;)k+=R[i*16+O++];}System.Console.WriteLine(k.TrimEnd());}}}

```

Example output for `cardGolf.exe 7H QH 3S B R`

```
 -------------   -------------   -------------   -------------   -------------
|7H           | |QH           | |3S           | |* * * * * * *| |J            |
|   -------   | |   -------   | |   -------   | | * * * * * * | |O  -------   |
|  |H     H|  | |  |H      |  | |  |       |  | |* * * * * * *| |K |       |  |
|  |   H   |  | |  |       |  | |  |   S   |  | | * * * * * * | |E | J     |  |
|  |       |  | |  |       |  | |  |       |  | |* * * * * * *| |R |  O    |  |
|  |H     H|  | |  |   Q   |  | |  |   S   |  | | * * * * * * | |  |   K   |  |
|  |       |  | |  |       |  | |  |       |  | |* * * * * * *| |  |    E  | J|
|  |       |  | |  |       |  | |  |   S   |  | | * * * * * * | |  |     R | O|
|  |H     H|  | |  |      H|  | |  |       |  | |* * * * * * *| |  |       | K|
|   -------   | |   -------   | |   -------   | | * * * * * * | |   -------  E|
|           H7| |           HQ| |           S3| |* * * * * * *| |            R|
 -------------   -------------   -------------   -------------   -------------

```

Most of the rendering is done by the `P` anonymous method, which takes a position, length, string, and width, and renders a rectangle of the string end on end. For example, the back of the card is just `"* "` repeated. The `T` anonymous method is a modified version of one I used for a previous task, which renders lots of rectangles. It is, however, rather bulky, and would only allow me to render the borders and background in fewer bytes, which probably isn't worth it. A striped down version of `T` is `W` which renders cells rather than rectangles, and also isn't used, but an inlined version of it is used to render cards of value 2 through 10. Note that unused code *was* removed for the byte count, I'm leaving it in because I may end up using it, and I do use them for testing.

The program simply loops through each line of output (13 of them) and then renders each card in turn, and then extracts 1 slice from it, so each card is rendered in it's entirety 13 times. For the purpose of spacing them, each card is treated as a 16 by 13 block, and I trim each line of output to remove trailing spaces (the corner spaces are removed).

Formatted code, with comments and concept/testing code:

```
class P
{
    static void Main(string[]A)
    {
        int O,J,i=0,L,n,r,z;

        for(;i<13;i++)
        {
            var k="";
            foreach(var a in A)
            {
                // got card a and line i

                var R=new char[208];

                System.Action<int,int,string,int>P=(s,l,g,w)=>
                {
                    for(O=0;O<l;s+=O%w<1?17-w:1)
                        R[s]=g[O++%g.Length];
                };

                // not used
                System.Action<string>T=f=>
                {
                    f+="AAPM!";
                    for(J=64;J++<77;)
                        for(O=64;O++<80;R[z=O+J*16-1105]=f[r]=='!'?R[z]:f[r])
                            for(r=0;f[r++]>O|f[r++]>J|O>f[r++]|J>f[r++];r++);
                };

                // not used (derivative below)
                System.Action<string>W=f=>
                {
                    for(O=0;O<f.Length;)
                        R[f[O++]+f[O++]*16-1105]=f[O++];
                };

                // render

                // outer

                P(0,208," ",16); // fill
                P(1,13,"-",13); // top
                P(193,13,"-",13); // bottom
                P(16,11,"|",1); // left
                P(30,11,"|",1); // left

                //T("BBNL BANM-ABOL|AAPM ");

                if(a=="B") // back
                    P(17,143,"* ",13);
                else
                {
                    // inner

                    P(36,7,"-",7); // top
                    P(164,7,"-",7); // bottom
                    P(51,7,"|",1); // left
                    P(59,7,"|",1); // left

                    //T("EDKJ ECKK-DDLJ|");

                    // joker
                    if(a=="R")
                    {
                        P(17,5,"JOKER",1);
                        P(125,5,"JOKER",1);
                        P(69,25,"J     O     K     E     R",5);
                        //T("FEFEJGFGFOHGHGKIHIHEJIJIR");
                    }
                    else
                    {
                        L=a.Length;

                        // card
                        var S=a.Substring(L-1);
                        var v=a.Substring(0,L-1);

                        P(17,L,a,L);
                        P(190-L,L,S+v,L);

                        if(int.TryParse(v,out n))
                        {
                            // number card
                            var f=new string[]
                            {
                                S="HEHI",
                                S+"HG",
                                S="EDKDEJKJ",
                                S+"HG",
                                v=S+"EGKG",
                                v+="HE",
                                v+"HI",
                                (S+="EFEHKFKH")+"HG",
                                S+"HEHI",
                            }[n-2];
                            for(O=0;O<f.Length;)
                                R[f[O++]+f[O++]*16-1105]=a[L-1];
                        }
                        else
                        {
                            if(v=="A")
                            {
                                // ace
                                P(103,1,S,1);
                            }
                            else
                            {
                                // face card
                                P(52,1,S,1);
                                P(154,1,S,1);
                                P(103,1,v,1);
                            }
                        }
                    }
                }

                // write

                for(O=0;O<16;)
                    k+=R[i*16+O++];
            }
            System.Console.WriteLine(k.TrimEnd());
        }
    }
}

```
> 4 votes

# Answer
# PowerShell, score 442 = (~~509~~ ~~495~~ 472 bytes = (156 script + 316 archive) - 30 bonus)

```
param($s)tar xOf t|%{$l=$_
($s-split'1| '-ne''|%{($l|% s*g(14*('A234567890JQKRB'|% i*f $_[0]))15)-replace'X','♣♦♥♠'[('CDHS'|% i*f $_[1])]})-join' '}

```

Try it online!

Unrolled:

```
# # the tar archive t should be in default folder
param($s)
tar xOf t|%{ $line=$_
    ($s-split'1| '-ne''|%{
        $pos = 14*('A234567890JQKRB'|% indexOf $_[0])
        $x=$line|% SubString $pos 15

        $suit = 'CDHS'|% indexOf $_[1]
        $x-replace'X','♣♦♥♠'[$suit]
    })-join' '                                          # implicit output
}

```

Powershell script to create the tar archive `t` (see TIO):

```
(
' ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ',
'|AX           |2X           |3X           |4X           |5X           |6X           |7X           |8X           |9X           |10X          |JX           |QX           |KX           |J            |* * * * * * *|',
'|   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |O  -------   | * * * * * * |',
'|  |       |  |  |       |  |  |       |  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |X      |  |  |X      |  |  |X      |  |K |       |  |* * * * * * *|',
'|  |       |  |  |   X   |  |  |   X   |  |  |       |  |  |       |  |  |       |  |  |   X   |  |  |   X   |  |  |       |  |  |   X   |  |  |       |  |  |       |  |  |       |  |E | J     |  | * * * * * * |',
'|  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |X     X|  |  |X     X|  |  |       |  |  |       |  |  |       |  |R |  O    |  |* * * * * * *|',
'|  |   X   |  |  |       |  |  |   X   |  |  |       |  |  |   X   |  |  |X     X|  |  |X     X|  |  |X     X|  |  |   X   |  |  |       |  |  |   J   |  |  |   Q   |  |  |   K   |  |  |   K   |  | * * * * * * |',
'|  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |       |  |  |X     X|  |  |X     X|  |  |       |  |  |       |  |  |       |  |  |    E  | J|* * * * * * *|',
'|  |       |  |  |   X   |  |  |   X   |  |  |       |  |  |       |  |  |       |  |  |       |  |  |   X   |  |  |       |  |  |   X   |  |  |       |  |  |       |  |  |       |  |  |     R | O| * * * * * * |',
'|  |       |  |  |       |  |  |       |  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |X     X|  |  |      X|  |  |      X|  |  |      X|  |  |       | K|* * * * * * *|',
'|   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------   |   -------  E| * * * * * * |',
'|           XA|           X2|           X3|           X4|           X5|           X6|           X7|           X8|           X9|          X10|           XJ|           XQ|           XK|            R|* * * * * * *|',
' ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- '
) | Set-Content f -Force
tar zcf t f -o
Get-ChildItem t # output info about archive size

```
> 1 votes

---
Tags: code-golf, ascii-art, kolmogorov-complexity
---


title: How many pages have issues?

text:
# Question
Title: How many pages have issues?
At work I've been acting as quality control on our public documents, to make sure that they are WCAG 2.0 compliant. Given the length of some of these documents there tend to be issues, and so I record the issues and the pages they occur on.

# The challenge: Given a string input, output a count of all distinct pages within the string.

## Rules:

* Input will consist of of a non-empty string containing the pages, page ranges, and the issue. Multiple pages and page ranges are guaranteed to be separated by commas `,`.

```
pgs 810-812, 897, 1043, 1047, 1219, 1308, 1317, 1323 restructure reading boxes

```

```
pgs 810-812,897,1043, 1047,1219, 1308, 1317, 1323 restructure reading boxes

```

Both of the above are possible valid inputs.

* This input can be multiple lines, with each line representing a different issue.

```
pgs 810-812, 897, 1043, 1047, 1219, 1308, 1317, 1323 restructure reading boxes
pgs 816, 819, 826, 827, 829, 853, 861, 866, 885, 1043, 1142, 1143, 1164 table needs to be read as table or figure

```

You can take a multiline input as a list of strings, with each item in the list being a line. The output is still based on the entirety of the list.

* The input format is not necessarily `pgs <page numbers> <issue>`.

Both `pg 1324 read all` and `Read all` are valid inputs.

If the string consists of only `<Issue>`, this represents that the document is a single page, and thus the output would be `1` (no matter how many lines of input there are). If there is more than one page, you are guaranteed to not have this format as a line of the input.

## Test Cases:

```
Input:
------
pgs 810-812, 897, 1043, 1047, 1219, 1308, 1317, 1323 restructure reading boxes

Output:
-------
10

Input:
------
pgs 587,897, 936, 939,946, 1308 single figure
pgs 810-812, 897, 1043, 1047, 1219,1308,1317, 1323 restructure reading boxes

Output:
-------
14

Input:
------
pgs 824, 873, 941-943, 1032, 1034, 1036-1040, 1055, 1071, 1153, 1154, 1228 figures as figures
pgs 1036-1040 Color Contrast for negative balance numbers does not meet WGAC 2.0 guidelines
pg 1324 read all

Output:
-------
18

Input:
------
Incorrect Reading Order

Output:
-------
1

Input:
------
Incorrect Reading Order
Pg 1 Read Table as Table
Pgs 1 Color Contrast for negative balance numbers does not meet WGAC 2.0 guidelines

Output:
-------
1

```

---

This is , so shortest answer in bytes wins.

# Answer
> 3 votes
# 05AB1E, ~~51~~ 38 bytes

*-13 bytes thanks to Kevin Cruijssen!*

```
',ð:#ʒ'-м€.ïß}D.ï≠ÅÏ'-¡¤LsнUʒX<›]˜Ùg1M

```

Try it online!

### Explanation

```
                                      // Implicitly Read in multiline string
 ',ð:#                                //Swap commas with spaces and split on spaces
      ʒ'-м€.ïß}                       //Filter list to only those with - removed are numbers
               D                      //Duplicate
                .ï≠ÅÏ                 //For all the ones that aren't numbers (so the ranges)
                    '-¡               //Split on dashes
                       ¤L             //Generate list from 1 to the highest number
                         sнU          //Stick the lower number in the variable U
 ʒ®<›]                                //Filter out numbers less than the lower number
      ˜                               //deep flatten
        Ùg                            //Uniquify and count
          1M                          //Push 1 then output the largest number in the stack

```

# Answer
> 1 votes
# Perl 5 (`-p`), 63 bytes

```
s/-/../g;s/^pgs?|[^., \d].*//g;map$h{$_}=1,eval}{$\=(keys%h)||1

```

TIO

---
Tags: code-golf, string
---


title: Output the Euler Numbers

text:
# Question
Title: Output the Euler Numbers
Given a non-negative integer \\$n ,\\$ output the \\$n^{\text{th}}\\$ Euler number (OEIS A122045).

All odd-indexed Euler numbers are \\$0 .\\$ The even-indexed Euler numbers can be computed with the following formula (\\$i \equiv \sqrt{-1}\\$ refers to the imaginary unit): $$ E\_{2n} = i \sum\_{k=1}^{2n+1}{ \sum\_{j=0}^{k}{ \left(\begin{array}{c}k \\ j \end{array}\right) \frac{{\left(-1\right)}^{j} {\left(k-2j\right)}^{2n+1}}{2^k i^k k} } } \\,. $$

## Rules

* \\$n\\$ will be a non-negative integer such that the \\$n^{\text{th}}\\$ Euler number is within the representable range of integers for your language.

## Test Cases

```
0 -> 1
1 -> 0
2 -> -1
3 -> 0
6 -> -61
10 -> -50521
20 -> 370371188237525

```

# Answer
> 19 votes
# Mathematica, 6 bytes

```
EulerE

```

-cough-

# Answer
> 13 votes
# , 10 bytes

```
(1%6&o.)t:

```

Try it online!

Uses the definition for the exponential generating function sech(x).

# Answer
> 12 votes
# PARI/GP, 9 bytes

```
eulerfrac
```

This built-in was added in version 2.13.0, after this challenge was asked.

Attempt This Online!

---

# PARI/GP, 24 bytes

```
n->2*imag(polylog(-n,I))
```

Attempt This Online!

---

# PARI/GP, 32 bytes

```
n->n!*Vec(1/cosh(x+O(x^n++)))[n]
```

This is the original answer.

Attempt This Online!

# Answer
> 11 votes
# Maple, 5 bytes

```
euler

```

Hurray for builtins?

# Answer
> 11 votes
# Maxima, 5 bytes / 42 bytes

Maxima has a built in:

```
euler

```

Try it online!

The following solution does not require the built in from above, and uses the formula that originally defined the euler numbers.

We are basically looking for the n-th coefficient of the series expansion of `1/cosh(t) = sech(t)` (up to the `n!`)

```
f(n):=coeff(taylor(sech(x),x,0,n)*n!,x,n);

```

Try it online!

# Answer
> 9 votes
# Mathematica, without built-in, 18 bytes

Using @rahnema1's formula:

```
2Im@PolyLog[-#,I]&

```

---

**21 bytes:**

```
Sech@x~D~{x,#}/.x->0&

```

# Answer
> 8 votes
# JavaScript (Node.js), ~~70~~ ~~46~~ 44 bytes

```
F=(a,b=a)=>a?F(--a,b)*~b+F(a,b-=2)*(a-b):+!b

```

Try it online!

Surprised to find no JavaScript answer yet, so I'll have a try.

The code consists of only basic mathematics, but the mathematics behind the code requires calculus. The recursion formula is derived from the expansion of the derivatives of \\$\mathrm{sech}(x)\\$ of different orders.

### Explanation

Here I'll use some convenient notation. Let \\$T^n:=\mathrm{tanh}^n(t)\\$ and \\$S^n:=\mathrm{sech}^n(t)\\$. Then we have

$$\frac{d^nS}{dt^n}=\sum\_{i=0}^nF(n,i)T^{n-i}S^{i+1}$$

Since \\$\frac{dT}{dt}=S^2\\$ and \\$\frac{dS}{dt}=-TS\\$, we can deduce that

$$ \begin{equation} \begin{aligned} \frac{d}{dt}(T^aS^b)&=aT^{a-1}(S^2)(S^b)+bS^{b-1}(-TS)(T^a) \\ &=aT^{a-1}S^{b+2}-bT^{a+1}S^b \end{aligned} \end{equation} $$

Let \\$b=i+1\\$ and \\$a=n-i\\$, we can rewrite the relation above as

$$ \begin{equation} \begin{aligned} \frac{d}{dt}(T^{n-i}S^{i+1})&=(n-i)T^{n-i-1}S^{i+3}-(i+1)T^{n-i+1}S^{i+1}\\ &=(n-i)T^{(n+1)-(i+2)}S^{(i+2)+1}-(i+1)T^{(n+1)-i}S^{i+1} \end{aligned} \end{equation} $$

That is, \\$F(n,i)\\$ contributes to both \\$F(n+1,i+2)\\$ and \\$F(n+1,i)\\$. As a result, we can write \\$F(n,i)\\$ in terms of \\$F(n-1,i-2)\\$ and \\$F(n-1,i)\\$:

$$F(n,i)=(n-i+1)F(n-1,i-2)-(i+1)F(n-1,i)$$

with initial condition \\$F(0,0)=1\\$ and \\$F(0,i)=0\\$ where \\$i\neq 0\\$.

The related part of the code `a?F(--a,b)*~b+F(a,b-=2)*(a-b):+!b` is exactly calculating using the above recurrence formula. Here's the breakdown:

```
F(--a,b)                 // F(n-1, i)                   [ a = n-1, b = i   ]
*~b                      // *-(i+1)                     [ a = n-1, b = i   ]
+F(a,b-=2)               // +F(n-1, i-2)                [ a = n-1, b = i-2 ]
*(a-b)                   // *((n-1)-(i-2))              [ a = n-1, b = i-2 ]
                         // which is equivalent to *(n-i+1)

```

Since \\$T(0)=0\\$ and \\$S(0)=1\\$, \\$E\_n\\$ equals the coefficient of \\$S^{n+1}\\$ in the expansion of \\$\frac{d^nS}{dt^n}\\$, which is \\$F(n,n)\\$.

For branches that \\$F(0,0)\\$ can never be reached, the recurrences always end at 0, so \\$F(n,i)=0\\$ where \\$i\<0\\$ or \\$i\\$ is odd. The latter one, particularly, implies that \\$E\_n=0\\$ for all odd \\$n\\$s. For even \\$i\\$s strictly larger than \\$n\\$, the recurrence may eventually allow \\$0\leq i\leq n\\$ to happen at some point, but before that step it must reach a point where \\$i=n+1\\$, and the recurrence formula shows that the value must be 0 at that point (since the first term is multiplied by \\$n-i+1=n-(n+1)+1=0\\$, and the second term is farther from the "triangle" of \\$0\leq i\leq n\\$). As a result, \\$F(n,i)=0\\$ where \\$i \> n\\$. This completes the proof of the validity of the algorithm.

### Extensions

The code can be modified to calculate three more related sequences:

**Tangent Numbers (46 bytes)**

```
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):+!~b

```

**Secant Numbers (45 bytes)**

```
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):+!b

```

**Euler Zigzag Numbers (48 bytes)**

```
F=(a,b=a)=>a?F(--a,b)*++b+F(a,b-=3)*(a-b):!b+!~b

```

# Answer
> 5 votes
# Python 2.7, 46 bytes

Using scipy.

```
from scipy.special import*
lambda n:euler(n)[n]

```

# Answer
> 5 votes
# Perl 6, 78 bytes

```
{(->*@E {1-sum @E».&{$_*2**(@E-1-$++)*[*](@E-$++^..@E)/[*] 1..$++}}...*)[$_]}

```

Uses the iterative formula from here:

$$E\_n = 1 - \sum\_{k=0}^{n-1} \left\[ E\_k \cdot 2^{(n-1-k)} \cdot \binom{n}{k} \right\]$$

### How it works

The general structure is a lambda in which an infinite sequence is generated, by an expression that is called repeatedly and gets all previous values of the sequence in the variable `@E`, and then that sequence is indexed with the lambda argument:

```
{ ( -> *@E {    } ... * )[$_] }

```

The expression called for each step of the sequence, is:

```
1 - sum @E».&{              # 1 - ∑
    $_                      # Eₙ
    * 2**(@E - 1 - $++)     # 2ⁿ⁻ˡ⁻ᵏ
    * [*](@E - $++ ^.. @E)  # (n-k-1)·...·(n-1)·n
    / [*] 1..$++            # 1·2·...·k
}

```

# Answer
> 4 votes
# Maxima, 29 bytes

```
z(n):=2*imagpart(li[-n](%i));

```

Try It Online!

Two times imaginary part of polylogarithm function of order `-n` with argument `i` \[1\]

# Answer
> 3 votes
# Befunge, 115 bytes

This just supports a hardcoded set of the first 16 Euler numbers (i.e. E0 to E15). Anything beyond that wouldn't fit in a 32-bit Befunge value anyway.

```
&:2%v
v@.0_2/:
_1.@v:-1
v:-1_1-.@
_5.@v:-1
v:-1_"="-.@
_"}$#"*+.@v:-1
8**-.@v:-1_"'PO"
"0h;"3_"A+y^"9*+**.@.-*8+*:*

```

Try it online!

I've also done a full implementation of the formula provided in the challenge, but it's nearly twice the size, and it's still limited to the first 16 values on TIO, even though that's a 64-bit interpreter.

```
<v0p00+1&
v>1:>10p\00:>20p\>010g20g2*-00g1>-:30pv>\:
_$12 0g2%2*-*10g20g110g20g-240pv^1g03:_^*
>-#1:_!>\#<:#*_$40g:1-40p!#v_*\>0\0
@.$_^#`g00:<|!`g01::+1\+*/\<
+4%1-*/+\2+^>$$10g::2>\#<1#*-#2:#\_$*\1

```

Try it online!

The problem with this algorithm is that the intermediate values in the series overflow much sooner than the total does. On a 32-bit interpreter it can only handle the first 10 values (i.e. E0 to E9). Interpreters that use bignums should do much better though - PyFunge and Befungee could both handle at least up to E30.

# Answer
> 1 votes
# Python2, (sympy rational), 153 bytes

```
from sympy import *
t=n+2
print n,re(Add(*map(lambda (k,j):I**(k-2*j-1)*(k-2*j)**(n+1)*binomial(k,j)/(k*2**k),[(c/t+1,c%t) for c in range(0,t**2-t)])))

```

This is very suboptimal but it's trying to use basic sympy functions and avoid floating point. Thanks @Mego for setting me straight on the original formula listed above. I tried to use something like @xnor's "combine two loops" from Tips for golfing in Python

# Answer
> 1 votes
# Axiom, 5 bytes

```
euler

```

for OEIS A122045; this is 57 bytes

```
g(n:NNI):INT==factorial(n)*coefficient(taylor(sech(x)),n)

```

test code and results

```
(102) -> [[i,g(i)] for i in [0,1,2,3,6,10,20]]
   (102)
   [[0,1],[1,0],[2,- 1],[3,0],[6,- 61],[10,- 50521],[20,370371188237525]]

(103) -> [[i,euler(i)] for i in [0,1,2,3,6,10,20]]
   (103)
   [[0,1],[1,0],[2,- 1],[3,0],[6,- 61],[10,- 50521],[20,370371188237525]]

```

# Answer
> 1 votes
## CJam (34 bytes)

```
{1a{_W%_,,.*0+(+W%\_,,:~.*.+}@*W=}

```

Online demo which prints E(0) to E(19). This is an anonymous block (function).

The implementation borrows Shieru Akasoto's recurrence and rewrites it in a more CJam friendly style, manipulating entire rows at a time.

## Dissection

```
{           e# Define a block
  1a        e#   Start with row 0: [1]
  {         e#   Loop...
    _W%     e#     Take a copy and reverse it
    _,,.*   e#     Multiply each element by its position
    0+(+    e#     Pop the 0 from the start and add two 0s to the end
    W%      e#     Reverse again, giving [0 0 (i-1)a_0 (i-2)a_1 ... a_{i-2}]
    \       e#     Go back to the other copy
    _,,:~.* e#     Multiply each element by -1 ... -i
    .+      e#     Add the two arrays
  }         e#
  @*        e#   Bring the input to the top to control the loop count
  W=        e#   Take the last element
}

```

# Answer
> 1 votes
# APL(NARS), 42 chars, 84 bytes

```
E←{0≥w←⍵:1⋄1-+/{(⍵!w)×(2*w-1+⍵)×E⍵}¨¯1+⍳⍵}

```

Follow the formula showed from "smls", test:

```
  E 0
1
  E 1
0
  E 3
0
  E 6
¯61
  E 10
¯50521

```

the last case return one big rational as result because i enter 20x (the big rational 20/1) and not 20 as i think 20.0 float 64 bit...

```
  E 20x
370371188237525

```

It would be more fast if one return 0 soon but would be a little more long (50 chars):

```
  E←{0≥w←⍵:1⋄0≠2∣w:0⋄1-+/{(⍵!w)×(2*w-1+⍵)×E⍵}¨¯1+⍳⍵}
  E 30x
¯441543893249023104553682821

```

it would be more fast if it is used the definition on question (and would be a little more long 75 chars):

```
  f←{0≥⍵:1⋄0≠2∣⍵:0⋄0J1×+/{+/⍵{⍺÷⍨(0J2*-⍺)×(⍵!⍺)×(¯1*⍵)×(⍺-2×⍵)*n}¨0..⍵}¨⍳n←1+⍵}
  f 0
1
  f 1
0
  f 3
0
  f 6
¯61J0
  f 10
¯50521J¯8.890242766E¯9
  f 10x
¯50521J0
  f 20x
370371188237525J0
  f 30x
¯441543893249023104553682821J0
  f 40x
14851150718114980017877156781405826684425J0
  f 400x
290652112822334583927483864434329346014178100708615375725038705263971249271772421890927613982905400870578615922728
  107805634246727371465484012302031163270328101126797841939707163099497536820702479746686714267778811263343861
  344990648676537202541289333151841575657340742634189439612727396128265918519683720901279100496205972446809988
  880945212776281115581267184426274778988681851866851641727953206090552901049158520028722201942987653512716826
  524150450130141785716436856286094614730637618087804268356432570627536028770886829651448516666994497921751407
  121752827492669601130599340120509192817404674513170334607613808215971646794552204048850269569900253391449524
  735072587185797183507854751762384660697046224773187826603393443429017928197076520780169871299768968112010396
  81980247383801787585348828625J0

```

The result above it is one complex number that has only the real part.

# Answer
> 1 votes
# Wolfram Language (Mathematica), ~~47~~ 46 bytes

Without using any special functions:

```
e@0=1;e@n_:=-n!Sum[e[n-k]/k!/(n-k)!,{k,2,n,2}]

```

Try it online!

---
Tags: code-golf, math, number, sequence, integer
---


title: Build ASCII Podiums

text:
# Question
Title: Build ASCII Podiums
In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.

The podiums are presented below:

```
     @---@
     | @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |

```

This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered `3` wide.

For example, given the input `["Tom", "Ann", "Sue"]` representing first-, second-, and third-place respectively, output the following podiums:

```
      Tom
     @---@
 Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |

```

However, if we have `Anne` instead of `Ann`, we'll need to go up to the next size, `5`, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of `Anne` is to the left of center, but you can choose which side to align to.

```
         Tom
       @-----@
 Anne  |  @  |
@-----@|  |  |
|  @  ||  |  |  Sue
|  |  ||  |  |@-----@
|  |  ||  |  ||  @  |

```

Let's go for some longer names. How about `["William", "Brad", "Eugene"]`:

```
          William
         @-------@
  Brad   |   @   |
@-------@|   |   |
|   @   ||   |   | Eugene
|   |   ||   |   |@-------@
|   |   ||   |   ||   @   |

```

Here we can see that `Brad` has a lot of whitespace, `Eugene` less so, and `William` fits just right.

For a longer test case, how about `["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]`:

```
                                     A
                         @-----------------------@
           BC            |           @           |
@-----------------------@|           |           |
|           @           ||           |           | DEFGHIJKLMNOPQRSTUVWXYZ
|           |           ||           |           |@-----------------------@
|           |           ||           |           ||           @           |

```

Finally, we have the smallest possible input, something like `["A", "B", "C"]`:

```
       A
     @---@
  B  | @ |
@---@| | |
| @ || | |  C
| | || | |@---@
| | || | || @ |

```

---

* Input and output can be given by any convenient method.
* The input is guaranteed non-empty (i.e., you'll never receive `""` as a name).
* You can print it to STDOUT or return it as a function result.
* Either a full program or a function are acceptable.
* Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
* Standard loopholes are forbidden.
* This is so all usual golfing rules apply, and the shortest code (in bytes) wins.

# Answer
# JavaScript (ES8), 196 bytes

```
a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@   |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)

```

Try it online!
> 9 votes

# Answer
# Groovy, ~~187~~, ~~176~~, ~~156~~, 150 bytes

```
f={n->m=n*.size().max()|1;h=' '*(m/2);'30734715746756276647665'*.toLong().sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|",'\n'])[it]}}

```

Try it online!

(note: the tio groovy interpreter could not handle indexing Lists using Long values even though groovy 2.5.6 can. Thus the tio answer is using `*.toShort()` instead of `*.toLong()` which adds a byte)

Defines a closure `f` which can be called via:

```
println(f(['tom','ann','sue']))

```

where `f` returns a string.

### Explanation:

Unobfuscating the code, we have:

```
f={n->
  m=n*.size().max()|1
  h=' '*(m/2)
  a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|",'\n']
  '30734715746756276647665'*.toLong().sum{a[it]}
}

```
* `f={n->` \- define closure f with one in-param `n`
* `m=n*.size().max()|1` \- find max name len, binary-or to odd number
* `h=' '*(m/2)` \- h will contain floor(m/2) spaces, used later
* `a=...`\- creates an encoding list with elements:
    + indexes 0,1,2 - names, centered to max len
    + index 3 - m+2 spaces
    + index 4 - `@---@` pattern, padded to len
    + index 5 - `| @ |` pattern, padded to len
    + index 6 - `| | |` pattern, padded to len
    + index 7 - newline
* `'307...'*.toLong().sum{a[it]}`\- use indicies into the encoding list to build the result. `.sum` uses the fact that string + string in groovy is valid.
* note that the expression `'3073...'*.toLong()` uses the `*.` spread operator to call `toLong()` on each character, returning a list of numbers.
* note in the answer the variable `a` has been inlined,nelines removed etc.
> 7 votes

# Answer
# Canvas, 45 bytes

```
ｒ３５１⁰｛|＊@；∔；Ｊ└ｌ２Ｍ２％±├ ××ｌ⇵╷-×└＋-α∔ｋ＋│∔⇵；｝┐＋＋⇵

```

Try it here!

Explanation:

```
r    Center the input, preferring left. Converts to an ASCII-art object
     which pads everything with spaces. This is the bulk of the magic.

 251⁰{ .... }            for each number in [2, 5, 1]:
      |*                 repeat "|" vertically that many times
        @;∔              prepend an "@" - a vertical bar for later
           ;             swap top 2 stack items - put the centered art on top
            J            push the 1st line of it (removing it from the art)
             └           order the stack to [remaining, "@¶|¶|..", currentLine]
              l          get the length of the current line
               2M        max of that and 2
                 2%      that % 2
                   ±├    (-that) + 2
                      ×× prepend (-max(len,2)%2) + 2 spaces
l                 get the length of the new string
 ⇵╷               ceil(len / 2) -1
   -×             repeat "-" that many times - half of the podiums top
     └            order stack to [art, currLine, "@¶|¶|..", "----"]
      +           append the dashes to the vertical bar = "@-----¶|¶|.."
       -α∔        vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
          k       remove the last line of that to make up for the middles shortness
           +      and append that horizontally - half of the podium without the name
            │     palindromize the podium
             ∔    and prepend the name
              ⇵   reverse vertically so the outputs could be aligned to the bottom
               ;  and get the rest of the centered input on top
Finally,
┐     remove the useless now-empty input
 ++   join the 3 podium parts together
   ⇵  and undo the reversing

```

Abuses "and it doesn't need to be consistent", making it pretty unintelligible.
> 6 votes

# Answer
# Python 2, ~~197~~ 190 bytes

```
n=input()
w=max([3]+map(len,n))
w+=~w%2;W=w+2
S=('{:^%d}'%w).format
x,y,s='@| '
a,b,c=map(S,n);A,B,C=x+'-'*w+x,y+S(x)+y,y+S(y)+y
for l in-~W*s+a,s*W+A,s+b+s+B,A+C,B+C+s+c,C+C+A,C+C+B:print l

```

Try it online!

<sub>-6 bytes, thanks to Andrew Dunai</sub>
> 4 votes

# Answer
# Python 2, 157 bytes

```
a=input()
i=7
while i:print''.join(([a[k/2]]+list('-@||||    '))[7-i-k].center(max(map(len,a))|1,'- '[i+k!=6]).join('@ |'[cmp(i+k,6)]*2)for k in(2,0,4));i-=1

```

Try it online!
> 4 votes

# Answer
# Charcoal, 63 bytes

```
≔÷⌈ＥθＬι²ηＦ³«Ｊ×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕Ｌ§θι⟧≔⁻⁷ⅉιＰ↓ι@ηＰ↓ιＰ↓@@¹ηＰ↓ι@

```

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

```
≔÷⌈ＥθＬι²η

```

Calculate the number of spaces in each half of a podium.

```
Ｆ³«

```

Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.

```
Ｊ×ι⁺³⊗η⊗﹪⁻¹ι³

```

Position to the start of the line that will have the text.

```
⟦◧§θι⁺⊕η⊘⊕Ｌ§θι⟧

```

Output the text with enough left padding to centre it.

```
≔⁻⁷ⅉι

```

Get the height of the podium.

```
Ｐ↓ι@ηＰ↓ιＰ↓@@¹ηＰ↓ι@

```

Draw the podium.

Alternative approach, also 63 bytes:

```
≔÷⌈ＥθＬι²ηＦ³«Ｊ×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕Ｌ§θι⪫@-@×-η⟧Ｅ⁻⁷ⅉ⪫⪫||§|@¬κ× η

```

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

```
≔÷⌈ＥθＬι²η

```

Calculate the number of spaces in each half of a podium.

```
Ｆ³«

```

Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.

```
Ｊ×ι⁺³⊗η⊗﹪⁻¹ι³

```

Position to the start of the line that will have the text.

```
⟦◧§θι⁺⊕η⊘⊕Ｌ§θι

```

Output the text with enough left padding to centre it.

```
⪫@-@×-η⟧

```

Also output the top of the podium by inserting `-`s between the characters of the string `@-@` to reach the correct width.

```
Ｅ⁻⁷ⅉ⪫⪫||§|@¬κ× η

```

Print the remainder of the podium by spacing the `|`s appropriately, except that the middle character is a `@` on the first row.
> 3 votes

# Answer
# R 308 302 299

-6 bytes thanks to @JAD
-3 bytes thanks to @Guiseppe, now I'm under 300

```
function(a){i=max(1,nchar(a)%/%2)
e=2*i+1
`~`=rep
g=' '
s=g~e+2
b='@'
p='|'
t=c(b,'-'~e,b)
x=c(p,g~i,b,g~i,p)
h=sub(b,p,x)
a=lapply(a,function(q){r=nchar(q);l=(e-r)/2+1;if(r%%2<1)c(g~l,q,g~l+1)else c(g~l,q,g~l)})
cat(s,a[[1]],s,s,t,s,a[[2]],x,s,t,h,s,x,h,a[[3]],h,h,t,h,h,x,fill=length(t)*3,sep='')}

```

There's probably a better way to create the layout; I should try what options I have for data frames.

Try it online
> 3 votes

# Answer
# Clean, 209 bytes

```
import StdEnv,Data.List
k=[' @|||||']
$l#m=max(maxList(map length l))3/2*2+1
=flatlines(transpose[(spaces(n*2)++g)%(0,6)\\n<-[1,0,2],g<-[k:[[c,'-':tl if(i==m/2)k['  '..]]\\c<-cjustify m(l!!n)&i<-[0..]]]++[k]])

```

Try it online!
> 2 votes

# Answer
# Python 2, 188 bytes

```
a,b,c=l=input()
s=max(map(len,l))/2or 1
A='@'+'--'*s+'-@'
D=(' '*s).join
C=D('|@|')
D=D('|||')
d=str.center
S=s*2+3
for l in' '*S+d(a,S),' '*S+A,d(b,S)+C,A+D,C+D+d(c,S),D+D+A,D+D+C:print l

```

Try it online!

-5 thanks to TFeld.
> 2 votes

# Answer
# PHP, 147 bytes

golfed 93 bytes off my initial idea, a straight forward `<?=`:

```
for(;~$v=_616606256046543440445[++$i];)echo$b="@   || "[$v],str_pad(($v&4?"|@":$argv)[$v&3],max(array_map(strlen,$argv))," -"[!$v],2),$b,"
"[$i%3];

```

takes names from command line arguments. Run with `-nr` or try it online.
Requires PHP 7; yields warnings in PHP 7.2 (and later, presumably). See the TiO for a +5 byte fix.

## mapping:

```
0:@---@     = top border
1,2,3       = $argv with spaces
4: "| | |"  = default
5: "| @ |"  = below top
6: "     "  = empty

```

## breakdown:

```
for(;~$v=_616606256046543440445[++$i];)echo # loop through map:
    $b="@   || "[$v],                       # print left border
    str_pad(                                # print padded string:
        ($v&4?"|@":$argv)[$v&3],                # string to be padded
        max(array_map(strlen,$argv)),           # pad length = max argument length
        " -"[!$v],                              # pad with: dashes if top border, spaces else
        2                                       # option: center text (pad on both sides)
    ),
    $b,                                     # print right border
    "\n"[$i%3]                              # add linebreak every three items
;

```

The pre-increment for `$i` saves me from any tricks for the newlines.
The blank for `6` can also be empty; so I did that.
But using `$argv[0]` for the top border string `-` was the nicest golf ever. (and saved 9 bytes!)
> 2 votes

# Answer
# Go, 436 bytes

Go is terrible for golf. But:

```
package main;import ("fmt";"os");func main(){;z:=os.Args;f:=3;for i:=1;i<4;i++{;if len(z[i])>f{;f=len(z[i]);};};f+=1-f%2;p:=(f-1)/2+1;b:="@";for j:=0;j<f;j++{;b+="-";};b+="@";x:=fmt.Sprintf("|%*v%*v",p,"@",p,"|");y:=fmt.Sprintf("|%*v%[1]*v",p,"|");fmt.Printf("%*v%*v\n%*v%v\n%*v%*v\n%v%v\n%v%v%*v\n%v%v%v\n%v%v%v",f+2,"",p+1+len(z[1])/2,z[1],f+2,"",b,p+1+len(z[2])/2,z[2],2*f+3-p-len(z[2])/2,x,b,y,x,y,p+1+len(z[3])/2,z[3],y,y,b,y,y,x)}

```

Broken down:

```
package main
import (
  "fmt"
  "os"
)
func main() {
  z:=os.Args
  f:=3
  for i:=1;i<4;i++{
    if len(z[i])>f{
      f=len(z[i])
    }
  }
  f+=1-f%2
  p:=(f-1)/2+1
  b:="@"
  for j:=0;j<f;j++{
    b+="-"
  }
  b+="@"
  x:=fmt.Sprintf("|%*v%*v",p,"@",p,"|")
  y:=fmt.Sprintf("|%*v%[1]*v",p,"|")

  fmt.Printf("%*v%*v\n%*v%v\n%*v%*v\n%v%v\n%v%v%*v\n%v%v%v\n%v%v%v",
  f+2,"",p+1+len(z[1])/2,z[1],
  f+2,"",b,
  p+1+len(z[2])/2,z[2],2*f+3-p-len(z[2])/2,x,
  b,y,
  x,y,p+1+len(z[3])/2,z[3],
  y,y,b,y,y,x)
}

```
> 2 votes

# Answer
# Java 8, ~~399~~ ~~394~~ 373 Bytes

This solution is probably way too long, but it is a solution :)

~~```
static String r(String[]p){String s="";int l[]=new int[]{p[0].length(),p[1].length(),p[2].length()},m=Math.max(l[0],Math.max(l[1],l[2]))+2,i,q,j,a,k,t;if(m%2==0)m++;if(m==3)m=5;for(i=0;i<7;i++){for(q=0;q<3;q++)for(j=0;j<m;j++){a=(2*q+1)%3;k=2*a;t=(m-l[a])/2;s+=i==k?j>=t&j<t+l[a]?p[a].charAt(j-t):" ":i==k+1?j%(m-1)==0?"@":"-":i>=k+2?j%(m-1)==0?"|":j==m/2?i==k+2?"@":"|":" ":" ";}s+="\n";}return s;}

```~~

Saved 5 Bytes by directly iterating in order (a=1,0,2 instead of q=0,1,2; a=f(q))

~~```
static String r(String[]p){String s="";int l[]=new int[]{p[0].length(),p[1].length(),p[2].length()},m=Math.max(l[0],Math.max(l[1],l[2]))+2,i,j,a,k,t;if(m%2==0)m++;if(m==3)m=5;for(i=0;i<7;i++){for(a=1;a<4;a=a==1?0:a+2)for(j=0;j<m;j++){k=2*a;t=(m-l[a])/2;s+=i==k?j>=t&j<t+l[a]?p[a].charAt(j-t):" ":i==k+1?j%(m-1)==0?"@":"-":i>=k+2?j%(m-1)==0?"|":j==m/2?i==k+2?"@":"|":" ":" ";}s+="\n";}return s;}

```~~

Saved 21 Bytes thanks to @KevinCruijssen:

```
static String r(String[]p){String s="";int l[]=new int[3],m=0,i,j,a,k,t;for(String x:p)l[m++]=x.length();m=Math.max(l[0],Math.max(l[1],l[2]))+2;m+=m%2<1?1:m==3?2:0;for(i=0;i<7;i++,s+="\n")for(a=1;a<4;a=a==1?0:a+2)for(j=0,k=2*a,t=(m-l[a])/2;j<m;j++)s+=i==k?j>=t&j<t+l[a]?p[a].charAt(j-t):" ":i==k+1?j%~-m<1?"@":"-":i>=k+2?j%~-m<1?"|":j==m/2?i==k+2?"@":"|":" ":" ";return s;}

```

As @KevinCruijssen suggested, one could also use `var` instead of `String` in Java 10+ and save some extra Bytes. I don't do this for the simple reason that I don't have Java 10 yet :D also, lambdas could be used. But this would only reduce the amount of bytes if we would leave out assigning it to a `Function<String[],String>` variable.

In expanded form:

```
static String r(String[]p){
    String s=""; //The string that will be returned
    int l[]=new int[3], //An array containing the lengths of our three names
            m=0, //tmp variable for filling l
            i,j,a,k,t; //some declarations to save a few bytes lateron
    for(String x:p) l[m++]=x.length();
    m=Math.max(l[0],Math.max(l[1],l[2]))+2;
    m+=m%2<1? //ensure odd length of the podests
        1
        :m==3?2:0; //ensure the length is at least 3 (in my code, m is the length of the podests + 2)
    for(i=0;i<7;i++,s+="\n") //iterate by row
        for(a=1;a<4;a=a==1?0:a+2) //iterate by place: a=1,0,2
            for(j=0,k=2*a,t=(m-l[a])/2;j<m;j++) //iterate by column
                //k is the row number from top in which the a-th name goes
                //t is the column at which the name starts
                //now, append the right char:
                s+=i==k? //write the name
                    j>=t&j<t+l[a]?
                        p[a].charAt(j-t)
                        :" "
                    :i==k+1? //write the top of the podest ("@---@")
                        j%~-m<1?
                            "@"
                            :"-"
                    :i>=k+2? //write the bottom of the podest ("|  |@  |")
                        j%~-m<1? //the left and right edge of the podest
                            "|"
                            :j==m/2? //the center of the podest
                                i==k+2? //are we at the first row of the bottom?
                                    "@" //the case where we have to write "| @ |"
                                    :"|" //the case "| | |"
                                :" "
                        :" "
                ;
    return s;
}

```

The input has to be given as `String`-array of length 3. An example looks like this:

```
public static void main(String[] args){
    System.out.print(r(new String[]{"Anthony", "Bertram", "Carlos"}));
}

```

Output:

```
          Anthony
         @-------@
 Bertram |   @   |
@-------@|   |   |
|   @   ||   |   | Carlos
|   |   ||   |   |@-------@
|   |   ||   |   ||   @   |

```
> 1 votes

# Answer
# C(GCC) ~~302~~ ~~293~~ ~~292~~ ~~289~~ 287 bytes

-6 byte thanks to ceilingcat

```
#define P(h,n)r=w+2-L[n];i/h?printf("%*s%*s%*s",-~r/2,D,L[n],i>h?D:N[n],r/2,D):printf(~i/h?"@%s@":"|%*s%c%*s|",~i/h?D+1:w/2,D,i>h-3?64:'|',w/2,D);
f(int**N){char L[3],w=3,i=3,r,D[99]={};for(;i--;)w=w<(L[i]=strlen(N[i]))?L[i]|1:w;memset(D+1,45,w);for(i=7;i--;puts(D)){P(4,1)P(6,0)P(2,2)}}

```

Run it here

Ungolfed and explained (technically you can't have comments after back slashes in macros, so this won't run)

```
#define P(h,n)\
    r=w+2-L[n];\ //get leftover width
    i/h?\ //if i >= h
        printf("%*s%*s%*s",-~r/2,D,L[n],i>h?D:N[n],r/2,D):\//if too high print all spaces, otherwise center the name
        printf(~i/h?"@%s@":"|%*s%c%*s|",~i/h?D+1:w/2,D,i>h-3?64:'|',w/2,D);
//if (i == h - 1) print top row using D calculated if row right below top, else print '@'(64) in center, otherwise '|'
f(int**N){
    char
        L[3],//lengths of each string
        w=3,//width (init to minimum)
        i=3,//index, used in for loops
        l,//left padding
        r,//right padding
        D[99]={};//string of '-' of correct length (max 99) but first char is null for empty string
    for(;i--;)//i was set to 3 before, i will be {2,1,0}
        w=w<(L[i]=strlen(N[i]))?//set length to str len and compare to longest width so far
            L[i]|1://set it to length if longer, but make sure it is odd
            w;//do not replace
    memset(D+1,45,w); //set the first w bits of D to '-', leaves a null terminator
    for(i=7;i--;puts(D)){//i will be {6...0}
        P(4,1)//print second place, 4 high
        P(6,0)//print first place, 6 high
        P(2,2)//print thrid place, 2 high
    }
}

```

Here is the calling code

```
int main()
{
  char* N[3] = {"Tom", "Anne", "Sue"} ;
  f(N);
}

```

and output

```
         Tom
       @-----@
  Anne |  @  |
@-----@|  |  |
|  @  ||  |  |  Sue
|  |  ||  |  |@-----@
|  |  ||  |  ||  @  |

```
> 1 votes

# Answer
# PowerShell for Windows, ~~231~~ 223 bytes

```
param($a)$w=($a|% le*|sort)[-1]
if(3-gt$w){$w=3}$w+=1-$w%2
0..6|%{$r=$_
-join($a|%{$m=' -'[5-eq($o=$r+2*(++$i%3))]
$e='     @|||||'[$o]
$x=(,''*4+$_,'','@'+,'|'*4)[$o]
"$e$($x|% *ft(($x.Length+$w)/2-.1)$m|% *ht $w $m)$e"})}

```

Try it online!

Input is array `@('second','first','third')`. Unrolled version:

```
param($arr)
$width=($arr|% length|sort)[-1]
if(3-gt$width){$width=3}
$width+=1-$width%2

0..6|%{ $row=$_                         # 7 rows
    -join($arr|%{                       # 3 joined columns. Each column array contains 11 lines.
        $offset = $row+2*(++$i%3)       # (2,4,0) -> offset in column array #   0:
        $middle = ' -'[5-eq$offset]                                         #   1:
        $edge   = '     @|||||'[$offset]                                    #   2:
        $center = ('','','','',$_,'','@','|','|','|','|')[$offset]          #   3:
                                                                            #   4:  name
        # pad $x to a center                                                #   5: @---@
        $center = $center|% PadLeft (($center.Length+$width)/2-.1) $middle  #   6: | @ |
        $center = $center|% PadRight $width $middle                         #   7: | | |
                                                                            #   8: | | |
        # add the $edge                                                     #   9: | | |
        "$edge$center$edge"                                                 #  10: | | |
    })
}

```
> 1 votes

# Answer
# Stax, 43 bytes

```
¿⌐cF◄àë+±√¼∙]╔5B\d☺↨m█ewτ─º╞═ó○♣zG-█K↨ÄV┐§x

```

Run and debug it
> 0 votes

---
Tags: code-golf, ascii-art
---


title: Battle of the Jimmys

text:
# Question
Title: Battle of the Jimmys
`/o\` Jimmy has been receiving  lot of attention on this site recently and it has caused Jimmy to get a little stressed. The bodybuilder Jimmys `/-o-\` started bad mouthing the OG / acrobat `/o\` Jimmys saying they are way cooler because they are bigger. But of course the acrobat Jimmys thinks they are way cooler since after all they were the original.

This tension between Jimmys has resulted in somewhat of a Jimmy war, the acrobat Jimmys and the bodybuilder Jimmys are no longer at peace.

---

## Objective

Given a string of acrobat and bodybuilder Jimmys, determine would would win the battle.

* The input string will only contain bodybuilder Jimmys `/-o-\`, acrobat Jimmys `/o\` and spaces
* The bodybuilder Jimmys are stronger than acrobat Jimmys, so one bodybuilder Jimmy can take down 2 acrobat Jimmys BUT he will be taken down himself after the second Jimmy
`/o\ /-o-\` -\> `/-o-\`

`/o\ /o\ /-o-\` -\>
* The acrobat Jimmys are crafty and are good at surrounding the bodybuilder Jimmys, if 2 acrobat Jimmys surround a bodybuilder Jimmy, the bodybuilder Jimmy will be defeated with no damage to the acrobat Jimmys

`/o\ /-o-\ /o\` -\> `/o\ /o\`
* The acrobat Jimmys are also faster than the bodybuilder Jimmys so their actions will occur before the bodybuilder Jimmys

`/o\ /-o-\ /o\ /-o-\` -\> `/o\ /o\ /-o-\` -\>

## Notes

* Whitespace between Jimmys will have no affect on the battle, but it can be expected in the input.
* Whitespace in the output is acceptable and will be ignored as long as no Jimmys get cut in half
* Whitespace will only be spaces, you can assume there will be no tabs or newlines
* All Jimmys in the input will be whole, there will be no partial Jimmys `/o`
* The battle will continue until only 1 type of Jimmy (or no Jimmys at all) remain
* Both input and output should be in the form of a string
* Jimmy actions will occur going left -\> right across the field, but acrobat Jimmys have priority to bodybuilder Jimmy
* Bodybuilder Jimmys will only go down to two Jimmys if it occurs on the same turn (see last example)

## More Examples

```
/o\ /o\ /-o-\ /-o-\ /o\ /o\     // Input string

/-o-\ /o\ /o\                   // Leftmost bodybuilder took out left two acrobats

                                // Output will be whitespace

-----------------------------------

/o\ /o\ /-o-\ /o\ /-o-\ /o\ /o\  // Input string

/o\ /o\ /o\ /-o-\ /o\ /o\        // acrobat Jimmys got a surround

/o\ /o\ /o\ /o\ /o\              // acrobat Jimmys win

-----------------------------------

/o\ /o\ /-o-\ /o\ /-o-\ /-o-\ /o\ /o\   // Input string

/o\ /o\ /o\ /-o-\ /-o-\ /o\ /o\

/o\ /-o-\ /o\ /o\

/o\ /o\ /o\                             // acrobats win again

-----------------------------------

/o\ /o\ /-o-\ /o\ /-o-\ /-o-\ /o\ /-o-\  // Input string

/o\ /o\ /o\ /-o-\ /-o-\ /o\ /-o-\

/o\ /-o-\ /o\ /-o-\

/o\ /o\ /-o-\

                                        // Output is empty

-----------------------------------

/-o-\ /o\ /o\ /o\ /-o-\ /-o-\           // Input string

/o\ /-o-\ /-o-\

/-o-\ /-o-\                             // Bodybuilder Jimmys win

-----------------------------------

/o\ /-o-\ /-o-\ /o\ /o\ /o\            // Input string

/-o-\ /-o-\ /o\ /o\ /o\                // left most bb jimmy took out leftmost acrobat jimmy

/-o-\ /o\                              // right bb Jimmy took out left two acrobat Jimmys and himself

/-o-\                                  // leftmost jimmy took out a second jimmy but survives because it occurred on a different turn the the first jimmy he took out - bodybuilder Jimmys win

```

Standard rules apply, This is code-golf so may the shortest answer win!

# Answer
# Retina 0.8.2, 82 bytes

```

+1`/-o-./o./o.|(/-o-.)/o.|(/o.(/o.)?)/-o-.(/o.)|/o./o./-o-.|/o.(/-o-.)
$1$2$4$5

```

Try it online! Link includes test suite. Explanation: The first stage simply deletes whitespace. (The footer spaces the remaining Jimmies back out out.) The second stage then repeatedly replaces the first available match with the captures until no more replacements can be made. The matches are as follows:

* `/-o-./o./o.` Matches a bodybuilder next to two acrobats. There is no capture because this takes out the bodybuilder as well.
* `(/-o-.)/o.` Matches a bodybuilder next to an acrobat. There's no second acrobat here, because it would have matched above, so the lone acrobat is taken out, while the bodybuilder survives.
* `(/o.(/o.)?)/-o-.(/o.)` Matches a bodybuilder between two acrobats, with up to two acrobats to his left. The bodybuilder is taken out.
* `/o./o./-o-.` Matches a bodybuilder with two acrobats to his left (but no acrobats to his right, as that would have already matched). All three are taken out.
* `/o.(/-o-.)` Matches a bodybuilder with one acrobat to his left (but no acrobats to his right, as that would have already matched). The acrobat is taken out.
> 3 votes

# Answer
# Jelly, 54 bytes

```
ðœṣjW}Ẉiȯ.ɗ¦FðⱮ⁽^|DB¬Ðe¤B0¦ẈṀ$ÐṀF€Ṁḟ3Ḃ
Ḳ¹ƇµẈ<4ÇÐLịQṢṚƊ

```

A full program accepting a string which prints the result (as a monadic Link the result would be a list of lists of characters).

The input must have spaces(s) between Jimmys, and the output has no spaces (both allowed in the question).

**Try it online!** Or see the test-suite.

### How?

```
Ḳ¹ƇµẈ<4ÇÐLịQṢṚƊ - Main Link: list of characters
Ḳ               - split at spaces
 ¹Ƈ             - keep those which are truthy (just the Jimmys, since empty lists aren't)
   µ            - start a new monadic link ...i.e f(Jimmys)
    Ẉ<4         - length of each less than four? ...i.e: strongman->0 acrobat->1
        ÐL      - loop until a fixed point is reached using:
       Ç        -   last Link (1, see below) as a monad ...i.e. f(these "Binnys")
              Ɗ - last three links as a monad ...i.e. g(Jimmys)
           Q    -   de-duplicate
            Ṣ   -   sort (["/-o-\", "/o\"], or if only one then just that one in a list)
             Ṛ  -   reverse
          ị     - index into (1-indexed and modular) ...i.e. get back any remaining Jimmys
                - implicit, smashing print

ðœṣjW}Ẉiȯ.ɗ¦FðⱮ⁽^|DB¬Ðe¤B0¦ẈṀ$ÐṀF€Ṁḟ3Ḃ - Link 1: list of 1s and 0s, let's say "Binnys"
                       ¤               - nilad followed by link(s) as a monad:
               ⁽^|                     -   literal = 24625
                  D                    -   to decimal = [2,4,6,2,5]
                   B                   -   to binary = [[1,0],[1,0,0],[1,1,0],[1,0],[1,0,1]]
                     Ðe                -   apply to even indices:
                    ¬                  -     NOT     = [[1,0],[0,1,1],[1,1,0],[0,1],[1,0,1]]
ð            ðⱮ                        - map with the dyad: ...i.e. [f(Binnys,X) for X in that]
 œṣ                                    -   split Binnys at sublists equal to X
     }                                 -   use the right argument (X) with:
    W                                  -     wrap in a list
   j                                   -   join (the split Binnys) with (wrapped Xs)
           ¦                           -   sparse application...
          ɗ                            -   ...to indices: last three links as a dyad:
       i                               -     first index of (X) or 0 if not found
         .                             -     literal 0.5
        ȯ                              -     OR (since an index of a half doesn't exist)
      Ẉ                                -   ...action: length of each
                                       -   ...i.e. replace the first, wrapped X with its length
            F                          -   flatten
                          ¦            - sparse application...
                         0             - ...to indices: [0] (the [1,0,1] result)
                        B              - ...action: to binary (3 -> [1,1])
                              ÐṀ       - keep a list of those which are maximal under:
                             $         -   last two links as a monad:
                           Ẉ           -     length of each
                            Ṁ          -     maximum
                                       - ...i.e. keep only the one with [1,1] in if its there
                                F€     - flatten each
                                  Ṁ    - maximum
                                   ḟ3  - filter out threes (strongmen annihilating)
                                     Ḃ - modulo 2 (2->0 to cater for remaining strongmen)

```
> 3 votes

# Answer
# Jelly, 68 bytes

```
⁵R+⁴W;“|ẹẹrḟ“€Ƙ.q“¦ḍhƁ’b⁴¤ḃ2s2Z€ị“/o\“/-o-\”ḣẎẎF€⁸œṣjƭƒ@ƬṪ
ḟ⁶;ç1ɗ/ç2

```

Try it online!

A full program that takes a string as input and outputs the final state of the Jimmys as a string. Works well for all the test cases. It works through the input one character at a time at each stage replacing 4 Jimmy sets with the appropriate output until no change. At the end, it then also looks for trailing 3 and 2 Jimmy sets that need to be resolved. Jelly doesn’t have regex, so all the possible Jimmy sets that need replacement are built.
> 2 votes

# Answer
# JavaScript, ~~223~~ 202 bytes

## Code

### Non-recursive 206 bytes

```
x=>{x=x[u="replace"](/ /g,"");while(x[t='match'](/o...o/)){d=/(-..o|o..-)/,x=x[t](s=/o.{7}o/)?x[u](s,"o\\/o"):(a=x[t](c=/\/.{9}\\/))&&(b=x[t](d))&&(a.index<b.index)||(a&&!b)?x[u](c,""):x[u](d,"-")}return x}

```

Try it online!

### Recursive 202 bytes

```
f=x=>{x=x[u="replace"](/ /g,"");d=/(-..o|o..-)/;return x[t='match'](/o...o/)?f(x[t](s=/o.{7}o/)?x[u](s,"o\\/o"):(a=x[t](c=/\/.{9}\\/))&&(b=x[t](d))&&(a.index<b.index)||(a&&!b)?x[u](c,""):x[u](d,"-")):x}

```

Try it online!

### Explanation

```
x=x[u="replace"](/ /g,"");

```

Remove all spaces

```
while(x[t='match'](/o...o/))
return x[t='match'](/o...o/)?f(...)

```

While there is an acrobat next to a bodybuilder (o\\/-o or o-\\/o) Do one of the following

```
x=x[t](s=/o.{7}o/)?x[u](s,"o\\/o")

```

If there is a bodybuilder surrounded by acrobats remove the bodybuilder

```
:(a=x[t](c=/\/.{9}\\/))&&(b=x[t](d))&&(a.index<b.index)||(a&&!b)?x[u](c,"")

```

If the first acrobat next to a bodybuilder is also next to an acrobat remove both acrobats and the bodybuilder

```
:x[u](d,"-")

```

Otherwise remove only the acrobat.
> 1 votes

# Answer
# Perl 5 `-p`, 111 bytes

```
s/\s//g;$A=qr'/o\\';$B=qr'/-o-\\';1while s,$A\K$B$A,/o\\,g;s,($A?)$A$B|$B$A($A?),'/-o-\\'x!$+,e;/$A/*/$B/&&redo

```

Try it online!
> 1 votes

# Answer
# C# (Visual C# Interactive Compiler), 249 bytes

```
n=>{n=n.Replace(" ","");for(var s=@"o\/-o-\/o";n.Contains("/o")&n.Contains("-");n=new System.Text.RegularExpressions.Regex(@"/o.{4,7}-\\|/-.{4,7}o\\").Replace(n,m=>m.Value.Length>8?"":"/-o-\\",1))for(;n.Contains(s);)n=n.Replace(s,@"o\/o");return n;}

```

Try it online!
> 1 votes

# Answer
# Python 2, ~~216~~ 214 bytes

```
A='/o\\';B='/-o-\\';a=input().replace(' ','')
while(A in a)*(B in a):j,k=min(enumerate([A+B+A,A+A+B,B+A+A,B+A,A+B]),key=lambda(i,k):([1,i>0][k in a],(a+'.'+k).find(k),i));a=a.replace(k,[A+A,'','',B,B][j],1)
print a

```

Try it online!
> 0 votes

---
Tags: code-golf, string, ascii-art
---