29
\$\begingroup\$

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.

asked Jul 15, 2019 at 15:46
\$\endgroup\$
16
  • \$\begingroup\$ Can we assume all inputs will have at least one leading and trailing space? \$\endgroup\$ Commented Jul 15, 2019 at 15:51
  • 7
    \$\begingroup\$ @connectyourcharger a more standard way would be to require answers to specify the order. \$\endgroup\$ Commented Jul 15, 2019 at 16:31
  • 4
    \$\begingroup\$ 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 \$\endgroup\$ Commented Jul 15, 2019 at 17:10
  • 1
    \$\begingroup\$ @Veskah: The test case generator is capable of generating the sequence oo. \$\endgroup\$ Commented Jul 15, 2019 at 18:42
  • 10
    \$\begingroup\$ There needs to be a jimmy tag. \$\endgroup\$ Commented Jul 16, 2019 at 20:21

23 Answers 23

21
\$\begingroup\$

Python 3.8 (pre-release), 51 bytes

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

Try it online!

answered Jul 15, 2019 at 16:51
\$\endgroup\$
5
  • \$\begingroup\$ 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 \$\endgroup\$ Commented Jul 15, 2019 at 17:02
  • \$\begingroup\$ @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). \$\endgroup\$ Commented Jul 15, 2019 at 17:12
  • \$\begingroup\$ How is the first count on the ('o') getting called without a c ? \$\endgroup\$ Commented Jul 15, 2019 at 17:23
  • \$\begingroup\$ @Quinn The assignment expression assigns s.count to c and then returns it. \$\endgroup\$ Commented Jul 15, 2019 at 17:59
  • \$\begingroup\$ @ErikTheOutgolfer cool, TIL \$\endgroup\$ Commented Jul 15, 2019 at 18:05
12
\$\begingroup\$

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)

answered Jul 15, 2019 at 17:01
\$\endgroup\$
1
  • 3
    \$\begingroup\$ This is a nice method, and it's shorter as a program. \$\endgroup\$ Commented Jul 16, 2019 at 5:49
8
\$\begingroup\$

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]
answered Jul 15, 2019 at 16:28
\$\endgroup\$
8
\$\begingroup\$

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
answered Jul 15, 2019 at 17:44
\$\endgroup\$
5
\$\begingroup\$

J, (削除) 36 (削除ここまで) 25 bytes

-11 bytes thanks to cole!

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

Try it online!

Original solution

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
answered Jul 16, 2019 at 6:27
\$\endgroup\$
5
  • 1
    \$\begingroup\$ 25 bytes? \$\endgroup\$ Commented Jul 16, 2019 at 6:50
  • \$\begingroup\$ Whoops, can no longer edit my comment - this is also 25 bytes if it's correct, does a different way of appending the 0. \$\endgroup\$ Commented Jul 16, 2019 at 7:04
  • 1
    \$\begingroup\$ @cole Hah, as it often occurs to me, I didn't see the pattern. Thank you! \$\endgroup\$ Commented Jul 16, 2019 at 7:09
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 16, 2019 at 7:10
  • \$\begingroup\$ @cole That's why I will keep the explanation of my blunder visible :) \$\endgroup\$ Commented Jul 16, 2019 at 7:12
5
\$\begingroup\$

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
answered Jul 16, 2019 at 12:23
\$\endgroup\$
4
\$\begingroup\$

APL (Dyalog Unicode), 20 bytesSBCS

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

Try it online!

answered Jul 16, 2019 at 9:09
\$\endgroup\$
4
\$\begingroup\$

Kotlin (削除) 131 (削除ここまで) (削除) 130 (削除ここまで) (削除) 129 (削除ここまで) (削除) 121 (削除ここまで) (削除) 117 (削除ここまで) (削除) 97 (削除ここまで) (削除) 96 (削除ここまで) 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

answered Jul 15, 2019 at 16:19
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 16, 2019 at 14:01
  • \$\begingroup\$ @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 \$\endgroup\$ Commented Jul 17, 2019 at 18:09
3
\$\begingroup\$

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.

answered Jul 15, 2019 at 16:10
\$\endgroup\$
1
  • \$\begingroup\$ You can save some bytes by escaping less, since the string is guaranteed to be only jimmys: Try it online! \$\endgroup\$ Commented Jul 15, 2019 at 22:30
3
\$\begingroup\$

Python 3, (削除) 69 (削除ここまで) (削除) 66 (削除ここまで) (削除) 60 (削除ここまで) 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!

answered Jul 15, 2019 at 16:55
\$\endgroup\$
1
  • 1
    \$\begingroup\$ There is no need for x. You can do g=input().count immediately \$\endgroup\$ Commented Jul 16, 2019 at 19:48
3
\$\begingroup\$

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!

answered Jul 15, 2019 at 16:48
\$\endgroup\$
1
  • 1
    \$\begingroup\$ @JonathanAllan I rewrote my answer. \$\endgroup\$ Commented Jul 15, 2019 at 17:26
2
\$\begingroup\$

Clojure, 78 bytes

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

Try it online!

answered Jul 16, 2019 at 0:11
\$\endgroup\$
2
\$\begingroup\$

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

answered Jul 15, 2019 at 16:30
\$\endgroup\$
1
  • \$\begingroup\$ @Xcali should now count dwarves at far left again \$\endgroup\$ Commented Jul 16, 2019 at 8:10
2
\$\begingroup\$

R, 63 bytes

Uses Regex matching to find and count the Jimmys.

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

Try it online!

answered Jul 17, 2019 at 14:55
\$\endgroup\$
2
\$\begingroup\$

K (oK), 25 bytes

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

Try it online!

answered Jul 18, 2019 at 6:47
\$\endgroup\$
1
\$\begingroup\$

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.

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

Ruby, 50 bytes

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

Try it online!

answered Jul 17, 2019 at 10:38
\$\endgroup\$
1
\$\begingroup\$

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

answered Jul 26, 2019 at 19:07
\$\endgroup\$
0
\$\begingroup\$

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
answered Jul 22, 2019 at 18:47
\$\endgroup\$
0
\$\begingroup\$

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.

Try it online or verify all test cases.

Minor equal-bytes alternative:

...-/oS¢R`;0)üα

Try it online or verify all test cases.

Explanation:

...-/o # Push string "-/o"
 S # Split to a list of characters: ["-","/","o"]
 ¢ # Count the occurrence of each character in the (implicit) input-string
 ć # Extract the head; pop and push head and remainder-list
 ; # Halve this head
 š # 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)
answered Jul 25, 2019 at 12:15
\$\endgroup\$
0
\$\begingroup\$

C (gcc), (削除) 99 (削除ここまで) (削除) 98 (削除ここまで) 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!

answered Jul 25, 2019 at 20:23
\$\endgroup\$
0
0
\$\begingroup\$

Vyxal, 17 bytes

`-/o`f$vOḣ1ドル⁄2p0pṘ ̄

Try it Online!

answered Jun 9, 2021 at 5:35
\$\endgroup\$
0
\$\begingroup\$

Ly, 87 bytes

0>0>0>i['-=[pl'o=[p<1+>0]pp0]p'/=[p<<1+>>0]p'o=[p<<<1+>>>0]psp]<s<l-:l+sp<l-u>' ou>' ou

Try it online!

I think this could be shorter, but I've hit a brick wall at this point.

At a high level, it counts the number of - (matched), / and o characters, then subtracts to remove duplicate counts before printing the results.

First is initializes counters to 0 on three different stacks.

0>0>0>

Then it reads the input onto the stack a codepoints, and loops over each character. The code also saved the current character to the backup cell with s so we can only count matched - characters.

i[ ... sp]

The first check increments the counter on the first stack if it's - and the previous character was o. That works since the characters are processes in reverse order.

 '-=[pl'o=[p<1+>0]pp0]p

The second check increments the counter on the second stack anytime the code hits a / character.

 '/=[p<<1+>>0]p

And the last check increments the counter on the third stack when the code finds a o character.

 'o=[p<<<1+>>>0]p

Once all the input has been scanned and counted, to code subtracts the number of matched - characters (bodybuilders) from the number of / characters to find the number of acrobats.

<s<l-

Then it remember the number of acrobats plus the number of bodybuilders by stashing the sum of the two in the backup cell.

 :l+sp

Then is subtracts that from the number of o characters to get the final counter and prints it.

 <l-u

The last bits just shift to the next counter and prints with a space appended. >' ou

And does the same shift/print to output the last counter.

 >' ou
answered Jun 9, 2021 at 8:21
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.