# A scene of Jimmy diversity

As you probably know, there have been multiple lovely Jimmy challenges recently popping up. In these challenges, you were challenged with our beloved friend's acrobatics skills. Now we've got a different challenge for you. Today you will be identifying different types of Jimmys!

# Explanation

There are three varieties of Jimmys: dwarf, acrobat, and bodybuilder.

This is dwarf Jimmy:               o

This is acrobat Jimmy:            /o\

This is bodybuilder Jimmy:       /-o-\


These Jimmys are all great friends and they like to stand on the same line as each other. Your task is, given a Jimmy scene like so:

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


Output the amount of dwarves, acrobats, and bodybuilders on the line, respectively.

# The challenge

• Take input in any reasonable form as a Jimmy scene, as shown in an example above.

1. The input string should be one line and optionally contains the three varieties of Jimmys and optional whitespace.

2. The string will not necessarily contain all of the Jimmy varieties or whitespace.

3. The string will not contain any characters not in o/\ -.

4. Any combination of Jimmy varieties is possible. This means that the same or different type of Jimmy can be next to each other. You must account for that.

5. Leading and trailing whitespace is optional and by no means required - your program should account for a string with or without leading and/or trailing whitespace.

6. The string should contain only valid Jimmys and whitespace. For instance, ---///--- is not allowed because it is not a valid Jimmy sequence.

• Output three numbers: The count of dwarves, acrobats, and bodybuilders in the scene (in respective order).

1. This may be an output to the console as space-separated integers, or it may be a return value from a function as some sort of container (i.e an array type).

2. The output, in whatever format, must be ordered as mentioned in the top bullet above this rule.

• Standard rules and loopholes apply.

# Test cases

     /-o-\           /-o-\     o/o\  /-o-\       /-o-\                /-o-\
OUTPUT: 1 1 5

o o               /o\    o o      o                    /o\             /o\
OUTPUT: 5 3 0

/-o-\     /-o-\            /-o-\/-o-\   o /o\/o\    /-o-\o /-o-\       /o\/-o-\
OUTPUT: 2 3 7

/-o-\  o                 /-o-\               o/o\
OUTPUT: 2 1 2


If you'd like more test cases, use this tool to generate more random test cases.

# Scoring

This is , so lowest score in bytes wins.

You can view the leaderboard for this post by expanding the widget/snippet below. In order for your post to be included in the rankings, you need a header (# header text) with the following info:

• The name of the language (end it with a comma , or dash -), followed by...

• The byte count, as the last number to appear in your header.

For example, JavaScript (ES6), 72 bytes is valid, but Fortran, 143 bytes (8-bit) is invalid because the byte count is not the last number in the header (your answer will be recognized as 8 bytes - don't take advantage of this).

<!-- Run the snippet to see the leaderboard. Report any bugs to @xMikee1 on Github. -->    <iframe src="https://ozewski.github.io/ppcg-leaderboard/?id=188391" width="100%" height="100%" style="border:none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>

• Can we assume all inputs will have at least one leading and trailing space? – Shaggy Jul 15 '19 at 15:51
• @connectyourcharger a more standard way would be to require answers to specify the order. – Expired Data Jul 15 '19 at 16:31
• Just to be explicit, can Dwarf Jimmys stand together? I see nothing suggesting otherwise. If so, a test case of oo /o\ o o would be nice – Veskah Jul 15 '19 at 17:10
• @Veskah: The test case generator is capable of generating the sequence oo. – recursive Jul 15 '19 at 18:42
• There needs to be a jimmy tag. – MilkyWay90 Jul 16 '19 at 20:21

# Jelly, (12?) 13 bytes

ċⱮ“-/o”H1¦ŻIṚ


A monadic Link accepting a list of characters which yields a list of integers, [ dwarves, acrobats, and body-builders] (save the Ṛ byte if we may specify our output)

Try it online!

### How?

All Jimmys show a o; all non-dwarves show a /; all body-builders show two -. Count these up, halve the count of -, and perform subtraction to find the Jimmy counts:

ċⱮ“-/o”H1¦ŻIṚ - Link: list of characters
“-/o”       - list of characters ['-', '/', 'o']
Ɱ            - map across right with:
ċ             -   count occurrences   = [n('-'), n('/'), n('o')]
¦    - sparse application...
1     - ...to indices: [1] -- i.e. n('-')
H      - ...action: halve    = [n('-')/2, n('/'), n('o')]
Ż   - prepend a zero =   [0, n('-')/2, n('/'), n('o')]
I  - incremental differences
-     = [n('-')/2, n('/')-n('-')/2, n('o')-n('/')]
Ṛ - reverse
-     = [n('o')-n('/'), n('/')-n('-')/2, n('-')/2]


# Python 3.8 (pre-release), 51 bytes

lambda s:((c:=s.count)('o')-c('/'),c('/o'),c('/-'))


Try it online!

• FINALLY python added something like this. I've been waiting for a while for Python to allow assignments as expressions. A shame it takes an extra byte, but I'll take it :P – HyperNeutrino Jul 15 '19 at 17:02
• @HyperNeutrino That's basically the one reason that you might now see "Python 3.8 (pre-release)" floating around the site. Another restriction is that, unless it's on its own and not the only expression in a statement (in which case you might prefer regular assignment instead), it must be parenthesized (+2 bytes). – Erik the Outgolfer Jul 15 '19 at 17:12
• How is the first count on the ('o') getting called without a c ? – Quinn Jul 15 '19 at 17:23
• @Quinn The assignment expression assigns s.count to c and then returns it. – Erik the Outgolfer Jul 15 '19 at 17:59
• @ErikTheOutgolfer cool, TIL – Quinn Jul 15 '19 at 18:05

# Python 2, 50 bytes

x,y,z=map(input().count,'o/-')
print x-y,y-z/2,z/2


Try it online!

-10 bytes by converting lambda expression to a full program thanks to @xnor (removes the double-lambda nested thing and uses assignment instead)

• This is a nice method, and it's shorter as a program. – xnor Jul 16 '19 at 5:49

# PowerShell, 59 55 bytes

$c=,0*3$args|sls '/?-?o'-a|% m*|% le*|%{++$c[$_-1]}
$c  Try it online! Unrolled: $counters=,0*3
$args|select-string '/?-?o'-AllMatches|% Matches|% Length|%{++$counters[$_-1]}$counters


# J, 36 25 bytes

-11 bytes thanks to cole!

2-/\0,~1 1 2%~1#.'o/-'=/]


Try it online!

# J, 36 bytes

[:(-/@}:,-/@}.,{:)1 1 2%~1#.'o/-'=/]


Try it online!

## Explanation:

                            'o/-'=/] compare the input with each one of "o/-" characters
/ the result is a 3-row matrix /
1#.         add up each row to find the number of occurences
of each character, the result is a vector of 3 items
1 1 2%~            divide the last item by 2 to find the number of
bodybuilder Jimmys
[:(              )                   use the result to construct the following vector:
{:                    the last item
,                      appended to
-/@}.                       the difference of the second and the third items
,                            appended to
-/@}:                             the difference of the first and the second items


A sample J session:

a=:'  /-o-\  o                 /-o-\               o/o\'
'o/-'=/a
0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1#.'o/-'=/a
5 3 4
1 1 2%~1#.'o/-'=/a
5 3 2
(-/@}:,-/@}.,{:)1 1 2%~1#.'o/-'=/a
2 1 2

• – cole Jul 16 '19 at 6:50
• Whoops, can no longer edit my comment - this is also 25 bytes if it's correct, does a different way of appending the 0. – cole Jul 16 '19 at 7:04
• @cole Hah, as it often occurs to me, I didn't see the pattern. Thank you! – Galen Ivanov Jul 16 '19 at 7:09
• it's unfortunate I only saw it right as you were editing in that explanation - always a shame to lose that much effort of explaining. – cole Jul 16 '19 at 7:10
• @cole That's why I will keep the explanation of my blunder visible :) – Galen Ivanov Jul 16 '19 at 7:12

# Excel as CSV, 130 bytes

,=LEN(A3)-LEN(A4)
=SUBSTITUTE(A1,"-o",""),=(LEN(A2)-LEN(A3))/2
=SUBSTITUTE(A2,"/o",""),=(LEN(A1)-LEN(A2))/2
=SUBSTITUTE(A3,"o","")


Insert input in space before first ,, save as .csv, open in Excel. Outputs Dwarfs, Acrobats and Bodybuilders in B1, B2 and B3 respectively.

Excel, 244 bytes

=LEN(SUBSTITUTE(SUBSTITUTE(A1,"-o",""),"/o",""))-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"-o",""),"/o",""),"o",""))&" "&(LEN(SUBSTITUTE(A1,"-o",""))-LEN(SUBSTITUTE(SUBSTITUTE(A1,"-o",""),"/o","")))/2&" "&(LEN(A1)-LEN(SUBSTITUTE(A1,"-o","")))/2


# APL (Dyalog Unicode), 20 bytesSBCS

2-/2÷⍨@2+/'o/-x'∘.=⎕


Try it online!

# Kotlin1311301291211179796 88 bytes

fun String.j(b:Int=count{'-'==it}/2,a:Int=count{'/'==it})=listOf(count{'o'==it}-a,a-b,b)


Try it online!

Edit - Wew, got it under 100! I doubt I can shrink it more, but only time will tell...

Edit - Spoke too soon, dropped one more byte by using a list instead of a string

Edit - minus 8 bytes thanks to AsoLeo suggesting using a extension function

• Let me tell you about extension methods, my friend: fun String.j(b:Int=count{'-'==it}/2,a:Int=count{'/'==it})=listOf(count{'o'==it}-a,a-b,b) 88 bytes. – Aso Leo Jul 16 '19 at 14:01
• @AsoLeo nice, I had actually written it as an extension function originally but I must've messed something else up because mine was more bytes – Quinn Jul 17 '19 at 18:09

# Retina, 39 35 bytes

Edit: -4 bytes thanks to @FryAmTheEggMan

^((o)|(/o.)|(/-o-.)| )*
$#2$#3 $#4  Try it online! Explanation: A simple replace stage. It finds all matches of the regex ^((o)|(/o.)|(/-o-.)| )* (which should result in one match - the whole string) and replaces it by the number of captures of groups 2, 3, and 4. Here is the regex broken down: ^((o)|(/o.)|(/-o-.)| )* ^ start at the beginning of the string ( )* have any amount of Jimmy / spaces | | | select one of: (o) capturing group 2 - dwarf (/o.) capturing group 3 - acrobat (/-o-.) capturing group 4 - bodybuilder  We have to start with ^ or the end of the input counts as a match too. In the substitution syntax of Retina, $n references the nth capturing group, and the modifier # counts how many matches it made.

• You can save some bytes by escaping less, since the string is guaranteed to be only jimmys: Try it online! – FryAmTheEggman Jul 15 '19 at 22:30

# JavaScript, 55 bytes

Searches the string using a regex pattern matching o, o-, or o-\; increments the corresponding count in an array, using the length of each match to determine the index.

s=>s.replace(/o-?\\?/g,m=>a[m.length-1]++,a=[0,0,0])&&a


Try it online!

• @JonathanAllan I rewrote my answer. – darrylyeo Jul 15 '19 at 17:26

# Clojure, 78 bytes

(defn ?[s](def c #(count(re-seq % s)))[(-(c #"o")(c #"/"))(c #"/o")(c #"/-")])


Try it online!

# Wolfram Language (Mathematica), 63 bytes

Reverse@{a=(m=CharacterCounts@#)["-"]/2,b=m["/"]-a,m["o"]-a-b}&


Try it online!

55 bytes if the pointless order requirement is dropped...

• @Xcali should now count dwarves at far left again – Expired Data Jul 16 '19 at 8:10

# Python 3, 696660 56 bytes

-4 bytes thanks to @Maarten Fabré

g=input().count
b,c=g('/'),g('/-')
print(g('o')-b,b-c,c)


Try it online!

• There is no need for x. You can do g=input().count immediately – Maarten Fabré Jul 16 '19 at 19:48

# R, 63 bytes

Uses Regex matching to find and count the Jimmys.

library(stringr)
str_count(scan(,''),c('(?<![/-])o','/o','/-'))


Try it online!

# K (oK), 25 bytes

{|-':|1 1 .5*+/x=\:"o/-"}


Try it online!

# Perl 5-p, 41 bytes

$_=1*s/o(?!\\|-)//g.$".1*s|/o||g.\$".y/o//


Try it online!

Counts the number of times o appears without being followed by \ or - to find the dwarves and removes them from the string. Then counts the number of times /o appears to find the acrobats and removes them from the string. Then counts the number of o remaining to determine the body builders. Inserts spaces between the numbers and implicitly outputs the result.

• -1 byte – Nahuel Fouilleul Jul 17 '19 at 5:49
• @NahuelFouilleul That doesn't work if there's a dwarf at the end of a line. It counts it as a body builder. – Xcali Jul 17 '19 at 19:27
• true, otherwise -4 bytes simply removing 1* – Nahuel Fouilleul Jul 18 '19 at 7:40
• @NahuelFouilleul That doesn't work, either. If there are no examples of those types, it outputs nothing (undef) instead of 0. – Xcali Jul 18 '19 at 15:02
• ok, i just looked at the test cases – Nahuel Fouilleul Jul 18 '19 at 15:09

# Ruby, 50 bytes

->s{%w(o /o -o).map{|x|s.scan(/[\/-]?o/).count x}}


Try it online!

# SNOBOL4 (CSNOBOL4), 135 bytes

	I =INPUT
B	I '-o' =	:F(A)
B =B + 1	:(B)
A	I '/o' =	:F(D)
A =A + 1	:(A)
D	I 'o' =	:F(O)
D =D + 1	:(D)
O	OUTPUT =+D ' ' +A ' ' +B
END


Try it online!

Removes -o, /o, and o from the string and increments the appropriate counters each time. Leaves behind a lot of arms and legs (/-\, \, and nothing).

# Forth (gforth), 118 bytes

: c -rot 0 tuck do over i + c@ 3 pick = - loop nip nip ;
: f 2dup '/ c >r 2dup '- c 2/ -rot 'o c i - . r> over - . . ;


Try it online!

### Explanation

• Get Count of /, -, and o characters
• Bodybuilder is number of - characters divided by 2
• Acrobat is number of / characters minus the number of body builders
• Dwarf is number of o characters minus the number of Acrobat and Bodybuilders

### Code Explanation

\ c counts the number of occurrences of the given character in a string
\ stack usage is ( c-addr u1 w1 - u )
: c                 \ start a new word definition
-rot 0 tuck       \ sets up parameters for a counted loop
do                \ loop from 0 to string-length - 1 (inclusive)
over i +        \ get the address of the current character in the string
c@              \ get the ascii value of the current character
3 pick =        \ compare it to the character we're counting
-               \ subtract result from the accumulator (subtract because -1 = true in forth)
loop              \ end the loop
nip nip           \ remove extra values from the stack
;                   \ end the word definition

\ Main function
: f                 \ start a new word definition
2dup              \ duplicate the string address and length
'/ c >r           \ count the number of '/' characters and stick the result on the return stack
2dup '- c 2/      \ count the number of '-' characters and divide by 2
-rot 'o c         \ move the string to the top of the stack and count the number of 'o characters
i - .             \ calculate number of dwarf jimmy's and print
r> over - .       \ calculate number of acrobat jimmy's and print (drop '/' count from return stack)
.                 \ print number of body-builder jimmy's
;                   \ end word definition


# 05AB1E, 13 bytes

…-/oS¢ć;š0š¥R


This one could be 12 bytes by removing the R if an output-order of [bodybuilder, acrobat, dwarf] would have been allowed.

Minor equal-bytes alternative:

…-/oS¢R;0)üα


Explanation:

…-/o           # Push string "-/o"
S          # Split to a list of characters: ["-","/","o"]
¢         # Count the occurrence of each character in the (implicit) input-string
š      # And prepend it back in front of the remainder-list
0š    # Then also prepend a 0
¥   # Get the deltas (forward differences)
R  # And reverse the list to get the required order of output-counts
# (after which the result is output implicitly)

…-/oS¢         # Same as above
R        # Reverse this list
# Pop the list and push its values separately to the stack
;      # Halve the top value on the stack
0     # Push a 0
)    # Wrap all values on the stack into a list
ü   # For each overlapping pair of values:
α  #  Get the absolute difference between the two values
# (after which the result is output implicitly)


# C (gcc), 9998 96 bytes

-1 byte thanks to ceilingcat

o,S,d,c;f(char*s){for(o=S=d=0;c=*s++;o+=c>93)d+=c==45,S+=c==47;printf("%d %d %d",o-S,S-d,d/=2);}


Try it online!