/o\ Jimmy has been receiving a 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.


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


  • 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!

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – DJMcMayhem
    Jul 22, 2019 at 23:18

7 Answers 7


Retina 0.8.2, 82 bytes



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.

Jelly, 54 bytes


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.


Ḳ¹ƇµẈ<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)

Jelly, 68 bytes


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.


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!


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!

  • \$\begingroup\$ @fəˈnɛtɪk I think it's fixed? \$\endgroup\$
    – Gymhgy
    Jul 21, 2019 at 1:10

JavaScript, 223 202 bytes


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!


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

Remove all spaces

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


If there is a bodybuilder surrounded by acrobats remove the bodybuilder


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


Otherwise remove only the acrobat.

  • \$\begingroup\$ seems to break on inputs with extra whitespace: Try it online! \$\endgroup\$
    – Quinn
    Jul 19, 2019 at 17:12
  • \$\begingroup\$ This doesn't seem to halt on /-o-\ /o\ /-o-\ /o\ . \$\endgroup\$
    – Nitrodon
    Jul 19, 2019 at 17:15
  • 1
    \$\begingroup\$ @Quinn It should be fixed now \$\endgroup\$ Jul 19, 2019 at 18:24
  • \$\begingroup\$ @fəˈnɛtɪk nice! \$\endgroup\$
    – Quinn
    Jul 19, 2019 at 18:26

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!


Your Answer

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

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