# Backstory

Meet my friend Jimmy:

/o\


Jimmy is a little character who likes to stand on platforms. Here's Jimmy safely standing on a platform:

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


Now, Jimmy has a good sense of balance, so he can safely stand with one leg off of the platform, like so:

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


Although if he stands with two or more body parts off of the platform, he will fall. Both of these are examples where Jimmy will fall:

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


# The challenge

Your challenge is to write a program to determine, given a string with Jimmy's platform and position, if Jimmy can stand on the platform without falling off.

• Input: Two lines showing Jimmy's position and the position of the platform under him. This can be from two separate inputs, a single input, or an array of some sort.
1. You may take input through any reasonable form, includings functions and standard input. Only resort to hard-coding if your language does not support the other input methods.
• Output: The boolean values true and false, or the integers 1 or 0 to represent true/false respectively.
1. The boolean value is based off of whether Jimmy can stay on the platform or not - true if Jimmy can stay on the platform, or false if he will fall off.
• The platform size is arbitrary and can be changed at will. Your program should account for that.
1. The platform cannot be a length of zero, and the platform must be complete (no holes in the platform).

2. Remember that Jimmy falls off when two of his body parts are hanging off the platform. A body part is one ASCII character of his body.

3. Trailing whitespace at the end of the platform is not required, but your program should account for both situations, where there is whitespace after the platform and where there is not.

# Test cases

         /o\               ✔️ TRUE
-------------

/o\                        ✔️ TRUE
----------

/o\    ❌ FALSE
------------------

/o\         ❌ FALSE
-------

/o\                    ❌ FALSE
-


# Scoring

This is , so lowest byte count 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 @ozewski on Github -->    <iframe src="https://ozewski.github.io/ppcg-leaderboard/?id=187586" 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 trailing whitespace after Jimmy? Also if you’re allowing arrays of characters, in some languages those will have to be padded with whitespace. – Nick Kennedy Jul 2 '19 at 23:07
• @NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that. – connectyourcharger Jul 2 '19 at 23:09
• Title is "will jimmy fall of the platform" and you required to output "will jimmy stay on the platform". Is this expected behavior? – tsh Jul 3 '19 at 3:29
• Can you reformat your test cases to make them easier to copy & paste, please? – Shaggy Jul 3 '19 at 6:53
• Is swapping truthy-falsy values allowed? (i.e. output true when Jimmy falls and false when that doesn't happen?) – Mr. Xcoder Jul 3 '19 at 9:48

# Jelly, 6 bytes

n⁶Sċ2Ẓ


Try it online!

Explanation:

n⁶Sċ2Ẓ  args: z (e.g. [['/', 'o', '\\'], [' ', '-']] => 0)
implicit return value: z ([['/', 'o', '\\'], [' ', '-']])
⁶       4th command-line argument or space [4th CLA assumed absent] (' ')
n        vectorized inequality ([[1, 1, 1], [0, 1]])
S     reduction by addition with base case 0 ([1, 2, 1])
2    literal (2)
ċ     number of occurrences of right in left (1)
Ẓ  primality (0)

• Sometimes I wonder how far humankind has advanced to see that in 6 bytes you can check if someone is going to fall off of a platform to their doom. – IMustBeSomeone Jul 3 '19 at 1:36
• @IMustBeSomeone, if I'm going to fall off a platform to my doom, I'd want someone to be quick in telling me! – Shaggy Jul 3 '19 at 7:02
• @Shaggy I always thought it was funny when people made challenges with an introduction: "Because we don't want to spend too much time on X, the code has to be as short as possible.", even though code-golf and performance are in most cases opposites. If we can save a byte going from $O(\log(n))$ to $O(n^n)$, who cares about performance, we got a byte off! ;p – Kevin Cruijssen Jul 3 '19 at 7:10
• I don't know Jelly, but why does the S sum the columns instead of the rows? :S If I looked at the wiki correctly the code does: n⁶ check for each character that it's not equal to a space (i.e. ['/o\\', ' -'] -> [[1,1,1],[0,1]]); S sum list (but for some reason this sums columns instead of rows.. so [[1,1,1],[0,1]] -> [1,2,1]); ċ2 count the amount of 2s; Ẓ check if this is a prime (so 2 or 3), after the result is output implicitly. But I would have expected [[1,1,1],[0,1]] to sum to [3,1].. – Kevin Cruijssen Jul 3 '19 at 7:42
• @KevinCruijssen S is equivalent to 0;+/Ɗ, that is, reduce by addition (which vectorizes) with initial value 0. § does what you expected S to do. – Erik the Outgolfer Jul 3 '19 at 8:08

# JavaScript (ES6), 38 bytes

Takes input as (a)(b). Returns $$\0\$$ or $$\1\$$.

a=>b=>b[a.searcho]=='-'&/--/.test(b)


Try it online!

### How?

We look for the position of the middle part "o" of Jimmy's body in the first string and test wether there's a dash in the second string at the same position.

b[a.searcho] == '-'


The only case where Jimmy would be unsafe in this situation is with a single-dash platform:

/o\
-


So we additionally make sure that the platform has a width of at least $$\2\$$:

/--/.test(b)


# JavaScript (ES6), 36 bytes

Alternate version if we assume that there's always either dashes or spaces below Jimmy (i.e. the input is rectangular).

a=>b=>b[a.searcho]!=0&/--/.test(b)


Try it online!

Takes advantage of the fact that the coercion to a numeric value is $$\0\$$ for a space and NaN for a dash.

• Wow. Could you explain how that works? – connectyourcharger Jul 2 '19 at 23:01
• @connectyourcharger I've added an explanation. – Arnauld Jul 2 '19 at 23:10
• Genius! JS answers usually aren't that short. – connectyourcharger Jul 2 '19 at 23:12
• Would this work for 35 bytes? – Oliver Jul 3 '19 at 2:13
• @Oliver will fail for "/o\\\n__" – tsh Jul 3 '19 at 3:43

# Excel, 6745 44 bytes

=(MID(A2,FIND("o",A1),1)="-")*(TRIM(A2)>"-")


Put Jimmy in A1, on a platform in A2.

2 conditions checked:

• Is Jimmy's torso (o) on the platform?
• Is the platform more than just -?
• @Keeta Edits within the first five minutes aren't shown in the edit history. – Fund Monica's Lawsuit Jul 3 '19 at 16:27
• From the limited testing I did, I think that you can change <> to > – Taylor Scott Jul 19 '19 at 17:54

## Python 3, 88 43 bytes

Input is given in the form of a list containing two strings: the first string is the first line; the second string is the second line.

lambda a:sum(1-(" "in i)for i in zip(*a))>1


Try it online!

Another version, tying for 43 bytes (I haven't been able to get it shorter than 43):

lambda a,b:b[a.find("/"):][:3].count("-")>1


Try it online!

Down by 42 bytes thanks to a tip from Jo King.

Old Version:

lambda s:sum((s.split("\n")[1]+" "*len(s))[i]=="-"and s[i]!=" "for i in range(len(s)))>1


-2 bytes thanks to Sriotchilism O'Zaic.

This works by taking two separate inputs, then pairing up corresponding letters. It counts the number of pairs where neither character is a space, then returns True if that number is greater than 1.

# Perl 6, 18 bytes

{?/''B|Bq/}o&[~^]


Try it online!

Takes a two parameters and returns a boolean of whether Jimmy will stay on the platform. This works by XORing the two lines together and checking if either part of Jimmy is still on the platform.

### Explanation:

             &[~^]   # String XOR operator
{          }o        # Combined with the anonymous function
?/       /          # That checks for the regex match
''B              # Unprintable, B, which is "/o" ~^ "--"
|Bq           # Or B, q, which is "o\" ~^ "--"


# Python 2, 42 37 bytes

lambda j,p:'--'in p[j.find('/'):][:3]


Try it online!

5 bytes thx to negative seven

• "--"in [...] for -5 bytes – negative seven Jul 3 '19 at 5:57
• @negative seven: nice; thanks! – Chas Brown Jul 3 '19 at 6:00

a#b=[1|(p,'-')<-zip a b,p>' ']>[1]


Try it online!

I got this one by combining my below technique with the other haskell answer.

x#'-'|x/=' '=1
x#y=0
(((>1).sum).).zipWith(#)


Try it online!

This counts the number of body parts (non-space characters) that are on top of the platform and then checks it is greater than 1. The reason we count body parts on the platform rather than body parts off is that zipWith will chop the top line to be the length of the bottom and thus can chop off Jimmy's body parts. This prevents us from having to do something like cycle" " to pad the list.

• Can't you reduce by 2 bytes by converting to infix? – cole Jul 3 '19 at 2:49
• @cole Yep I was just doing the edit when you commented :) – Wheat Wizard Jul 3 '19 at 2:49

# Dyalog APL Extended, 1110 8 bytes

2≤1⊥∧⌿⍤<


Try it online!

Explanation:

2≤1⊥∧⌿⍤<  a monadic train
<  Compare the input with the implicit prototype element - a space.
Returns a boolean matrix of characters that are greater than 0x20
∧⌿⍤   and-reduce that, i.e. places where both Jimmy and a platform is
1⊥      base 1 decode, aka sum - the amount of body parts over the platform
2≤        is that greater-or-equal to 2?


• – Adám Jul 3 '19 at 0:20

# ///, 85 93 87 bytes

/~/\/\///\/o\\/(o)~
/
~
~/ (o) /(o)~ (o)-/(o)~- -/--~(o) - ~/) ~/)-~/o~/(-/1~-~/(~/)~


Try it online!

Output's a 1 if Jimmy is safe. Otherwise outputs nothing. (Unary 1 and 0.) Because there is no other way to take input in ///, it needs to be hard-coded:

/~/\/\///\/o\\/(o)~
/
~
~/ (o) /(o)~ (o)-/(o)~- -/--~(o) - ~/) ~/)-~/o~/(-/1~-~/(~/)~ //<INPUT HERE>


For example:

/\/o\\/(o)//
/
//
/// (o) /(o)// (o)-/(o)//- -/--//(o) - ///) ///)-///o///(-/1//-///(///)//         /o\
-------------


Note the space after the <INPUT HERE>.

Explanation:

NOTE! The explanation code cannot be run due to the comments. The comments are enclosed in curly braces. Also, the original code uses a golf where // is replaced with ~. This code is omitted from the explanation.

/\/o\\/(o)/            {replace Jimmy with a Jimmy with curvy arms, because slashes are hard to manipulate in this language}
/
/
/                      {remove unneeded spaces after Jimmy, but before the floor}

/
//                     {get rid of the line break

/ (o) /(o)/            {remove all the spaces before both Jimmy and the floor}
/ (o)-/(o)/            {for each floor tile, remove it and one space before Jimmy. This detects whether Jimmy lines up with the floor.}
{If Jimmy is before the floor, then there will be extra floor.}
{If Jimmy is behind the floor, then there will be extra spaces before Jimmy.}
/- -/--/               {Handle the case where there is a hole beneath Jimmy but he is still well-supported}

/(o) - //              {Handle the case where only Jimmy's head is on the floor. The space at the end of the code is necessary for this.}
/) //                  {The rest of the substitutions clean up the result and handle each of the possible results that could exist at this point}
/)-//
/o//
/(-/1/
/-//
/(//
/)//

/o\
--
{there is a space right before this comment. The comment is only here to make the space visible and explain itself.}


• +8 bytes to fix a bug
• -6 bytes by applying a standard /// golf trick.
• The source code looks like some strange emoji. \\(o)-(o)// – tsh Jul 4 '19 at 3:52

# ///, 57 bytes

/|/\/\///\/o\\/J| J/J*|
/|* /|  -/  | /|*-/|--/!|-/|*/|J|


Try it online!

Append the input to the end of the program in order to run. Returns the empty string if Jimmy falls off the platform, a string of exclamation points otherwise.

• /|/\/\// replaces | with //, which makes the code both shorter and more readable (| is used to demarcate each replacement)
• /\/o\\/J| J/J*/ replaces Jimmy with J for brevity and changes the space to the left of him to * to the right of him
• The next replacement gets rid of newlines.
• /* /| -/ | // cancels out *s and with the space to the left of the platform. If there are two or more spaces left, Jimmy is falling off to the left, and the platform is deleted. This part also removes any whitespace to the right of the platform.
• /*-/|--/!/ cancels out *s and with length of the platform. If there are at least two - left, Jimmy isn't falling off to the right, so they are replaced with a !.
• /-/|*/|J// deletes every remaining character that isn't !

# MathGolf, 6 14 bytes

^@╞^αmÆû-oñ╧╙


Try it online!

8 bytes had to be added to account for the edge case presented by Nick Kennedy.

Checks if "-o-" is a substring of the zipped string of both lines, and the zipped string where the first input line has the first character removed. Takes input as two separate strings, with the only change being that the character is input as /o\\, since \\ is the correct way to input a backslash in a string in MathGolf.

## Explanation

                duplicate the top two items
^               zip top two elements on stack
@              rrot3
╞             discard from left of string/array
^            zip top two elements on stack
α           wrap last two elements in array
mÆ         explicit map using 5 operators
û-oñ     push "-o" and palindromize to make "-o-"
╧    pop a, b, a.contains(b)
map block ends here
╙   max of list

• Oh, that's a better approach than my MathGolf answer.. After the interleave I split it into parts of size 2 again instead of directly checking for "-o-". – Kevin Cruijssen Jul 3 '19 at 8:52
• – Nick Kennedy Jul 3 '19 at 10:31
• @NickKennedy good catch! I'll see how I can fix the code, and update the post once it passes. It'll probably add a few bytes though, which is unfortunate. – maxb Jul 3 '19 at 11:16

# chevron - 126 bytes

not an improvement over my old answer (at all), but rewritten after a rewrite of chevron itself.

> >^j
0>^i
^i+1>>^i
^j,^i~c>>^h
->+2??^h=/
->-3
> >^q
^q~s>>^s
->+5?^i>^s
^_p>^s
^q^s^s,^i,3~c>>^p
->+2??^s^s^s~^s^p^s
><1
><0


# 05AB1E (legacy), 98 7 bytes

ζðм2ùgp


-1 byte thanks to @Mr.Xcoder with the approach of ðм2ù.

Input as a list of two strings.

Only works in the legacy version of 05AB1E, because ζ can transpose a list of strings as well as a 2D list of characters, whereas the ζ in the new 05AB1E version only works with the 2D list of characters.

Explanation:

ζ        # Zip/transpose; swapping rows/columns, with space as default filler
ðм      # Remove all spaces from each string
2ù    # Only leave strings of size 2
g   # Count how many there are left
p  # Check if this is a prime (2 or 3)
# (after which the result is output implicitly)

• Your title breaks the leaderboard, smh :) – connectyourcharger Jul 3 '19 at 13:37
• @connectyourcharger Ah, probably because I always link the bytes to the code-page so you know it isn't encoded in UTF-8 but uses a custom encoding instead. ;) If you want I can edit my answer to put the encoding below the title, but honestly the leaderboard code should be able to handle it imho. – Kevin Cruijssen Jul 3 '19 at 13:44
• I feel like I need to add a special case for 05AB1E - it is one of the only languages that has issues with the codepage. Fix incoming soon-ish. – connectyourcharger Jul 3 '19 at 13:47
• Struggling to come up with a modified regex. For now that will be a persisting bug. If you'd like to contribute here's the script: github.com/xMikee1/ppcg-leaderboard/edit/master/docs/script.js. I may have to refactor the bytes parsing entirely. – connectyourcharger Jul 3 '19 at 14:12
• Can't you modify the URL to https://github.com/Adriandmen/05AB1E/wiki/Codepage?7 to make 7 the last number without invalidating the URL? – L. F. Jul 18 '19 at 3:26

# Ruby, 28 bytes

->a,b{!(/--/!~b[a=~/\//,3])}


Try it online!

# Excel, 36 bytes

=LEN(TRIM(MID(A2,FIND("/",A1),3)))>1


Jimmy in A1, on a platform in A2.

Finds the position of Jimmy, and takes the 3 bytes of the platform and trims off spaces. If the resulting platform length is long enough, Jimmy stands.

# EXCEL, 94 71 bytes . VBA (Excel), 87 bytes

A1 = Jimmy , A2 = platform

-23 bytes. Thank you @Wernisch.

=(FIND("-",A2)-FIND("/",A1)<2)*(FIND("\",A1)-LEN(A2)<2)*(TRIM(A2)<>"-")


?[(FIND("-",A2)-FIND("/",A1)<2)*(FIND("\",A1)-LEN(A2)<2)]*(len(replace([A2]," ",""))>1)

• Can't you use trim instead of len(replace? – Wernisch Jul 3 '19 at 10:59
• oh! that never sink in my head. haha Thanks @Wernisch :) – remoel Jul 4 '19 at 6:19

# Husk, 5 bytes

¬εδ#&


Try it online! This function takes the two lines as separate arguments. δ#& zips the two strings together and counts the number of pairs in which both characters are truthy, i.e., neither is a space character, and ¬ε tests that the count is greater than 1.

# R, 35 bytes

function(x)sum(colSums(x!=" ")>1)>1


Try it online!

Based on @EriktheOutgolfer’s excellent Jelly answer so please upvote that one too!

Input is a 2-d matrix of characters.

f a b=sum[1|(p,q)<-zip a$b++cycle" ",elem p"/o\\",q==' ']<2  Try it online! The function is called like so: f "/o\\ " " -- " How it works (for f "/o\\" " -"): b++cycle" " - Adds an infinite number of spaces after b to ensure that Jimmy is always above a - or (" -"" - ..." zip a$b++cycle" " - Zips the two strings together ([('/',' '), ('o','-'), ('\\',' ')])

(p,q)<-zip a$b++cycle - For each pair in the zipped list [1|(p,q)<-zip a$b++cycle" ",elem p"/o\\",q==' '] - Generates a list of 1s, whose length is the number of pairs satisfying the conditions:

elem p"/o\\" - The character in the top string is one of Jimmy's body parts. (Satisfied by all three pairs in this example)

q==' ' - The character in the bottom string is a space. (Satisfied by ('/', ' ') and ('\\', ' '))

So, the pair has to be one where one of Jimmy's body parts is above a space.

Because in this example, two pairs satisfy both conditions, the list is [1,1]

sum[1|(p,q)<-zip a$b++cycle" ",elem p"/o\\",q==' '] - Take the sum of those 1s (i.e. the length of the list), which in this example is 2. sum[1|(p,q)<-zip a$b++cycle" ",elem p"/o\\",q==' ']<2 - Check if the number of body parts above a space is less than 2. In this example, it's not, so Jimmy will fall off. :(

• I just thought I would let you know that your answer helped me to shorten my own answer. So thanks! – Wheat Wizard Jul 3 '19 at 2:51

# C (gcc), 73 bytes

f(s,t,c)char*s,*t;{for(t=strchr(s,c=10);*s%5**t;)c-=*++t%2**s++%8;c=c<0;}


Try it online!

• Suggest index() instead of strchr() – ceilingcat Jul 6 '19 at 20:39

# Kotlin, 60 bytes

fun String.c(b:String)=zip(b){i,j->i>' '&&j>' '}.count{it}>1


Explanation:

fun String.c  # Define an extension function on string, so we don't have to provide a first argument (and we also have string method calls for free)
(b:String)    # Pass the second string as argument
=             # Shorthand syntax for fun body
zip(b)        # Essentially a.zip(b). Creates a List<Pair> by joining both arrays.
# Takes care of trailing whitespace, because it will be the size of the smaller array
{i,j->        # Declare a transformer lambda as second function argument
i>' '&&j>' '} # This essentially translates to: If i!=' ' and j=='-'
.count{it}    # Count the true values
>1

• Welcome to Code Golf! That's certainly a very nice first answer. – connectyourcharger Jul 5 '19 at 17:02

# SnakeEx, 13 bytes

j:<R>o<T>\-\-


SnakeEx does well because it's a 2D pattern-matching language, but not too well because it wasn't designed to be very golfy. Try it here!

### Explanation

j:             Define the main snake, j (for Jimmy)
<R>          Pivot right (i.e. downward, since the snake starts out moving to the right)
o         Match Jimmy's torso (or is it his head?) and move down
<T>      Turn either left or right
\-\-  Match two platform characters


This will match if there are two platform characters under Jimmy, or fail to match if there are not. We don't need to consider the case where there are platforms only under his legs, since the platform cannot have holes.

# Japt, 8 bytes

Õ·kèS Êz


Try it

• Sorry, didn't see this before posting mine last night :\ – Shaggy Jul 3 '19 at 17:00

# Retina 0.8.2, 16 bytes

 (.*¶).
$1 ¶ ?--  Try it online! Link includes test suite. Explanation: +^ (.*¶).$1


While there is still a space on the first line, and both lines still have more than one character, delete the space and the first character of the next line. Note: This assumes that there is no trailing space after Jimmy. +1 byte needed if trailing space needs to be allowed.

¶ ?--


Check that there are at least two pieces of platform under Jimmy.

# Perl 5-pl, 42 bytes

/o/g;$_=(($_=<>)=~/./g)[-1+pos]eq'-'&&/--/


Try it online!

# Ruby 2.5.3, 44 bytes

->a,b{a.zip(b).map(&:join).grep(/\S-/).size>1}


Input taken as two arrays. Definitely not the most golf-friendly approach (see G B's answer), but I like any excuse to use the zip function.

# PowerShell, 63..55 53 bytes

-1 byte thanks to mazzy

param($j,$f)''+($f|% t*y|?{$j[$i++]-gt32})-match'- -'  Try it online! Takes input as two lines. Unrolled: param($j,$f) #Take$jimmy and $floor ''+ #Implicitly converts next part to string ($f |% ToCharArray      #Convert $f to a char[] and... |?{ #Only take the chars where...$j[$i++]-gt32 #The same indexed char in$j's ASCII # is > ' ' i.e. only get /o\
}
)-match'- -'            #Arrays.ToString are joined with a space and we need 2 -'s

• Huh. I never considered PowerShell a great golfing language, but I guess it's actually not that bad. – connectyourcharger Jul 3 '19 at 17:39
• @connectyourcharger It can do some pretty neat stuff with the pipeline but there's definitely a few areas where it's a huge pain in the ass. – Veskah Jul 3 '19 at 17:43
• I never bothered to learn it because of those pain-in-the-ass reasons. – connectyourcharger Jul 3 '19 at 17:45
• nice! step back and save one more :) – mazzy Jul 3 '19 at 23:32

# C# (Visual C# Interactive Compiler), 4440 39 bytes

-4 bytes thanks to Jo King

a=>b=>a.Zip(b,(x,y)=>x>y?y:0).Sum()>109


Try it online!

• 40 bytes that works – Jo King Jul 4 '19 at 3:01
• Does not quite work; tio.run/##Sy7WTS7O/… – CharlesS Jul 5 '19 at 17:14
• @CharlesS I believe I fixed it and saved a byte in the process – Expired Data Jul 5 '19 at 17:25
• @ExpiredData yep, nice! – CharlesS Jul 5 '19 at 21:45

# Bash, 49 bytes

[[ "${1:$((expr index "$0" /-1)):3}" =~ "--" ]]  Jimmy input as command line parameter 0, the platform as parameter 1; Must be aware of Bash's separating and eating whitespace (use single quotes): bash -c '[[ "${1:$((expr index "$0" /-1)):3}" =~ "--" ]]' '   /o\' '  -------'


# Julia 1.0, 42 40 bytes

y(a,b)=strip(b[findfirst("/o\\",a)])>"-"
`

Try it online!