18
\$\begingroup\$

Jimmy has had a busy last week with all these platforms and ropes, and poor Jimmy doesn't even have legs or feet to stand on!


Your job is to take a string containing multiple Jimmys and give them legs and shoes!

Get input in the form of a Jimmy String

Jimmy String => /o\ /o\ /o\

containing only /o\ and

give each Jimmy in the input a pair of feet that look like this:

 /o\
_/ \_

Turn the inputed floating head Jimmy string into Jimmy with feet string, like so:

// Input

       /o\   /o\          /o\

// Output

       /o\   /o\          /o\
      _/ \_ _/ \_        _/ \_

If 2 Jimmys are close together they must move over to make room, Jimmys will always move towards the right to make room for other Jimmys.

// Input

/o\/o\

// Output

 /o\  /o\
_/ \__/ \_

Other Jimmys that are further away must not be moved unless necessary

// Input

/o\/o\      /o\

// Output

 /o\  /o\   /o\
_/ \__/ \_ _/ \_

// Input

/o\/o\    /o\

// Output

 /o\  /o\  /o\
_/ \__/ \__/ \_

Standard rules and loopholes apply,

This is code-golf, so may the shortest answer win.

\$\endgroup\$
1
  • \$\begingroup\$ Suggested test case: /o\<sp>/o\<sp><sp><sp><sp><sp><sp><sp><sp>/o\/o\, my current implementation fails because it moves the last two Jimmies towards the left instead of right.. All of your test cases succeed, though. \$\endgroup\$ Commented Jul 25, 2019 at 8:19

9 Answers 9

3
\$\begingroup\$

Python 2, 131 120 115 114 121 118 bytes

o=1;W=[]
for g in map(len,input().split('/o\\')):W+=[' '*(g-o)];o=max(o-g,0)+2
for q in' /o\ ','_/ \_':print q.join(W)

Try it online!

4 bytes thx to movatica; 10 bytes lost for bug fix.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ o+=2-len(g) saves you a byte \$\endgroup\$
    – movatica
    Commented Jul 10, 2019 at 20:17
  • \$\begingroup\$ 118 bytes \$\endgroup\$
    – movatica
    Commented Jul 10, 2019 at 20:29
  • 1
    \$\begingroup\$ @movatica: there was a bug, but it was offset by your edits :). \$\endgroup\$
    – Chas Brown
    Commented Jul 10, 2019 at 20:47
3
+50
\$\begingroup\$

Charcoal, 28 bytes

 F⌕Aθ/«J∧ι⊖ι¹WKK→P_/ \_M↗/o\

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

 

Print a space to defeat Charcoal's automatic left margin.

F⌕Aθ/«

Loop over all of the left arms.

J∧ι⊖ι¹

Jump to the desired left foot location. Note that Charcoal has no problem drawing at (-1, 1), but the question does not allow that, so we have to take care to avoid drawing at negative positions.

WKK→

Move past any existing output.

P_/ \_M↗/o\

Output the feet and then move to output the Jimmy.

\$\endgroup\$
3
\$\begingroup\$

Ruby -p, 77 75 bytes

The "don't move Jimmy if not needed" rule was quite an ordeal to work around but I think it worked out quite well. Shorter than Python by quite a bit (at time of writing), at least.

-2 bytes from recursive.

r=/(\\ ?|^)(\S+) ?/
gsub(r){"#$1 #$2"}while~r
puts$_
gsub(/ .o. ?/,'_/ \_')

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Could you use \S+ in place of \/\S*? \$\endgroup\$
    – recursive
    Commented Jul 11, 2019 at 3:32
3
\$\begingroup\$

PowerShell, 96 bytes

($o=$args-split'/o.'|%{' '*($w=($l+=$_.Length-1)*($l-gt0));$l-=$w+1})-join' /o\ '
$o-join'_/ \_'

Try it online!

Unrolled:

$o=$args-split'/o.'|%{
    $len += $_.Length-1
    $width = $len*($len-gt0)    # len or 0, if len < 0
    ' '*$width
    $len -= $width+1
}
# $o is array of space strings now
$o-join' /o\ '
$o-join'_/ \_'
\$\endgroup\$
2
\$\begingroup\$

Python 2, 152 148 140 bytes

o=[-4]
for i,c in enumerate(input()):o+=[max(i,o[-1]+5)]*('/'==c)
for s in' /o\ ','_/ \_':print''.join('%*s'%(b-a,s)for a,b in zip(o,o[1:]))

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Retina, 40 37 bytes

\+`(^|\S.)(/\S*) ?
$1 $2
 /o. ?
_/ \_

Try it online!

Thanks to Value Ink for golfing off 3 bytes.

\$\endgroup\$
3
  • 4
    \$\begingroup\$ Enjoy your new shoes! \$\endgroup\$
    – Quinn
    Commented Jul 10, 2019 at 14:11
  • 1
    \$\begingroup\$ Well, tried to pretend these challenges don't exists for a while. (No relation to that Jimmy.) \$\endgroup\$
    – jimmy23013
    Commented Jul 10, 2019 at 14:14
  • \$\begingroup\$ I believe the pattern match I used in my Ruby answer (\\ ?|^)(/\S*) ? is shorter than the one in your first line and should give the same results (probably; I don't know Retina at all) \$\endgroup\$
    – Value Ink
    Commented Jul 10, 2019 at 22:07
2
\$\begingroup\$

Stax, 29 28 24 25 bytes

¢▄▌ß╙EVäN»0►,δñï◙,Θ╙BÅhΓ?

Run and debug it

There was a bug in the 24 byte solution that caused some off-by-1 errors in some cases.

\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), 107 bytes

s=>` /o\\ 
_/ \\_`.replace(/.*/g,j=>s.split(/.o./).map(s=>s.slice(n,l=s.length,n=n>l?n-l+2:2),n=1).join(j))

Try it online!

\$\endgroup\$
1
\$\begingroup\$

MATLAB, 111 bytes

Try it online

function J(s)
s=[' ' s];s=replace(s,{'\/','\ /'},'\  /');for k=find(s=='o')
o(k-2:k+2)='_/ \_';end
char(s,o)
\$\endgroup\$

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.