Will Jimmy fall off his platform?

29

4

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.

  • Be mindful of the standard loopholes that are forbidden.

Test cases

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

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

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

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

    /o\                    ❌ FALSE
     -

Scoring

This is , so lowest byte count wins.

Leaderboard

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://xmikee1.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>

connectyourcharger

Posted 2019-07-02T22:40:54.767

Reputation: 2 056

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 – 2019-07-02T23:07:59.883

@NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that. – connectyourcharger – 2019-07-02T23:09:06.357

What if the input is taken as a matrix which has to be rectangular? Is that just not an accepted input method? – dzaima – 2019-07-02T23:10:35.453

@dzaima That is accepted, since you literally cannot make it anything but rectangular. I'm fine with that. – connectyourcharger – 2019-07-02T23:11:29.377

12Title is "will jimmy fall of the platform" and you required to output "will jimmy stay on the platform". Is this expected behavior? – tsh – 2019-07-03T03:29:02.073

When you say we have to account for trailing whitespace or not past the end of the platform, do you mean any amount of trailing whitespace, or enough to pad it to the length of the other line, or something else? – xnor – 2019-07-03T05:01:44.990

6Can you reformat your test cases to make them easier to copy & paste, please? – Shaggy – 2019-07-03T06:53:14.837

Suggested test case: /o\ & <sp><sp>---. My initial approach worked for all your test cases, but not for one where Jimmy falls of at the left side. – Kevin Cruijssen – 2019-07-03T08:20:47.390

2Is swapping truthy-falsy values allowed? (i.e. output true when Jimmy falls and false when that doesn't happen?) – Mr. Xcoder – 2019-07-03T09:48:24.410

Are we guaranteed only 1 platform? What if there's 2 platforms with a 1-space gap in between them, and he has one arm on each platform but his body is over the hole? – Darrel Hoffman – 2019-07-03T15:09:26.863

@DarrelHoffman I said the platform must be complete (fully connected) in the question. – connectyourcharger – 2019-07-03T15:49:39.280

Now I'm wondering whether one of the marbles-like languages here allows the input to be the program. If, by any chance, an o is a marble and the language outputs something different for whether that marble reaches the bottom or not, it would work. – tomsmeding – 2019-07-03T17:07:20.033

@tomsmeding Sounds like a convoluted quine in the works. – connectyourcharger – 2019-07-03T17:16:52.870

Is PETSCII acceptable in place of ASCII? And do you mean true ASCII, or extended ASCII? -> https://en.wikipedia.org/wiki/PETSCII

– Shaun Bebbers – 2019-07-04T09:04:10.560

...to be continued on the next episode of Jimmy!

– facepalm42 – 2019-07-19T07:18:47.107

@facepalm42 Next Jimmy challenge coming soon? – connectyourcharger – 2019-07-19T14:15:45.503

Answers

20

Jelly, 6 bytes

n⁶Sċ2Ẓ

Try it online!

Explanation:

n⁶Sċ2Ẓ  args: z (e.g. [['/', 'o', '\\'], [' ', '-']] => 0)
        implicit return value: z ([['/', 'o', '\\'], [' ', '-']])
n⁶      dyad-nilad pair ([[1, 1, 1], [0, 1]])
 ⁶       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   dyad-nilad pair (1)
    2    literal (2)
   ċ     number of occurrences of right in left (1)
     Ẓ  primality (0)

Erik the Outgolfer

Posted 2019-07-02T22:40:54.767

Reputation: 38 134

26Sometimes 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 – 2019-07-03T01:36:00.933

4@IMustBeSomeone, if I'm going to fall off a platform to my doom, I'd want someone to be quick in telling me! – Shaggy – 2019-07-03T07:02:55.617

19@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 – 2019-07-03T07:10:32.070

1I 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 – 2019-07-03T07:42:41.980

2@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 – 2019-07-03T08:08:36.613

@KevinCruijssen I've gotten around to adding an explanation. – Erik the Outgolfer – 2019-07-03T19:47:56.387

19

JavaScript (ES6), 38 bytes

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

a=>b=>b[a.search`o`]=='-'&/--/.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.search`o`] == '-'

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.search`o`]!=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.

Arnauld

Posted 2019-07-02T22:40:54.767

Reputation: 111 334

Wow. Could you explain how that works? – connectyourcharger – 2019-07-02T23:01:37.623

@connectyourcharger I've added an explanation. – Arnauld – 2019-07-02T23:10:19.500

3Genius! JS answers usually aren't that short. – connectyourcharger – 2019-07-02T23:12:36.397

Would this work for 35 bytes? – Oliver – 2019-07-03T02:13:58.517

@Oliver will fail for "/o\\\n__" – tsh – 2019-07-03T03:43:55.163

Could you not replace b[a.search\o`]!=0with!!b[a.search`o`]` in the second program? – Geza Kerecsenyi – 2019-08-02T13:06:53.470

@GezaKerecsenyi No, because (' '!=0) === false, but (!!' ') === true (see the footnote and see this test).

– Arnauld – 2019-08-02T13:11:14.027

10

Excel, 67 45 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 -?

Wernisch

Posted 2019-07-02T22:40:54.767

Reputation: 2 534

1@Keeta Edits within the first five minutes aren't shown in the edit history. – Fund Monica's Lawsuit – 2019-07-03T16:27:59.587

From the limited testing I did, I think that you can change <> to > – Taylor Scott – 2019-07-19T17:54:52.907

9

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.

mprogrammer

Posted 2019-07-02T22:40:54.767

Reputation: 461

8

Python 2, 42 37 bytes

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

Try it online!

5 bytes thx to negative seven

Chas Brown

Posted 2019-07-02T22:40:54.767

Reputation: 8 959

1"--"in [...] for -5 bytes – negative seven – 2019-07-03T05:57:43.550

@negative seven: nice; thanks! – Chas Brown – 2019-07-03T06:00:13.177

8

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\" ~^ "--"

Jo King

Posted 2019-07-02T22:40:54.767

Reputation: 38 234

7

Haskell, 34 bytes

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.

Haskell, 45 bytes

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.

Post Rock Garf Hunter

Posted 2019-07-02T22:40:54.767

Reputation: 55 382

1Can't you reduce by 2 bytes by converting to infix? – cole – 2019-07-03T02:49:11.920

1@cole Yep I was just doing the edit when you commented :) – Post Rock Garf Hunter – 2019-07-03T02:49:46.957

4

Dyalog APL Extended, 11 10 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?

-2 thanks to Adám.

dzaima

Posted 2019-07-02T22:40:54.767

Reputation: 19 048

1

-2: 2≤1⊥∧⌿⍤<

– Adám – 2019-07-03T00:20:32.877

4

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

maxb

Posted 2019-07-02T22:40:54.767

Reputation: 5 754

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 – 2019-07-03T08:52:51.853

1

Fails for https://tio.run/##y00syUjPz0n7/z/u8G7d/MMbH01d/v@/un5@TIy6grqurvp/3RQA

– Nick Kennedy – 2019-07-03T10:31:39.103

@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 – 2019-07-03T11:16:39.743

3

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)

remoel

Posted 2019-07-02T22:40:54.767

Reputation: 511

1Can't you use trim instead of len(replace? – Wernisch – 2019-07-03T10:59:43.743

oh! that never sink in my head. haha Thanks @Wernisch :) – remoel – 2019-07-04T06:19:50.773

3

05AB1E (legacy), 9 8 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.

Try it online or verify all test cases.

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)

Kevin Cruijssen

Posted 2019-07-02T22:40:54.767

Reputation: 67 575

1Your title breaks the leaderboard, smh :) – connectyourcharger – 2019-07-03T13:37:41.797

@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 – 2019-07-03T13:44:28.973

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 – 2019-07-03T13:47:03.223

1

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: https://github.com/xMikee1/ppcg-leaderboard/edit/master/docs/script.js. I may have to refactor the bytes parsing entirely.

– connectyourcharger – 2019-07-03T14:12:16.057

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. – 2019-07-18T03:26:16.233

3

Ruby, 28 bytes

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

Try it online!

G B

Posted 2019-07-02T22:40:54.767

Reputation: 11 099

3

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.

Keeta - reinstate Monica

Posted 2019-07-02T22:40:54.767

Reputation: 938

3

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

(Try it online!)

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.

Comrade SparklePony

Posted 2019-07-02T22:40:54.767

Reputation: 5 784

1The source code looks like some strange emoji. \(o)-(o)// – tsh – 2019-07-04T03:52:58.167

2

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.

Nick Kennedy

Posted 2019-07-02T22:40:54.767

Reputation: 11 829

2

Haskell, 59 bytes

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 (" -" &rightarrow; " - ..."

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

Leo Tenenbaum

Posted 2019-07-02T22:40:54.767

Reputation: 2 655

I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!

– Post Rock Garf Hunter – 2019-07-03T02:51:21.083

2

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!

tsh

Posted 2019-07-02T22:40:54.767

Reputation: 13 072

Suggest index() instead of strchr() – ceilingcat – 2019-07-06T20:39:20.797

2

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

Alex Papageorgiou

Posted 2019-07-02T22:40:54.767

Reputation: 41

Welcome to Code Golf! That's certainly a very nice first answer. – connectyourcharger – 2019-07-05T17:02:57.153

2

///, 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 !

stellatedHexahedron

Posted 2019-07-02T22:40:54.767

Reputation: 871

2

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

Superloach

Posted 2019-07-02T22:40:54.767

Reputation: 71

1

Japt, 8 bytes

Õ·kèS Êz

Try it

Embodiment of Ignorance

Posted 2019-07-02T22:40:54.767

Reputation: 7 014

Sorry, didn't see this before posting mine last night :\ – Shaggy – 2019-07-03T17:00:53.683

1

C# (Visual C# Interactive Compiler), 44 40 39 bytes

-4 bytes thanks to Jo King

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

Try it online!

Expired Data

Posted 2019-07-02T22:40:54.767

Reputation: 3 129

40 bytes that works – Jo King – 2019-07-04T03:01:49.380

@CharlesS I believe I fixed it and saved a byte in the process – Expired Data – 2019-07-05T17:25:17.277

@ExpiredData yep, nice! – CharlesS – 2019-07-05T21:45:03.337

1

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.

Neil

Posted 2019-07-02T22:40:54.767

Reputation: 95 035

1

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

Veskah

Posted 2019-07-02T22:40:54.767

Reputation: 3 580

Huh. I never considered PowerShell a great golfing language, but I guess it's actually not that bad. – connectyourcharger – 2019-07-03T17:39:47.267

@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 – 2019-07-03T17:43:27.377

I never bothered to learn it because of those pain-in-the-ass reasons. – connectyourcharger – 2019-07-03T17:45:12.063

1

nice! step back and save one more :)

– mazzy – 2019-07-03T23:32:32.583

1

Perl 5 -pl, 42 bytes

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

Try it online!

Xcali

Posted 2019-07-02T22:40:54.767

Reputation: 7 671

1

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.

DaveMongoose

Posted 2019-07-02T22:40:54.767

Reputation: 231

1

Python 3.7, 71 56 Bytes

lambda s:sum(j in'/o\\'and p=='-'for j,p in zip(*s))>1

Very simple version and the shortest I could think of using this approach. Input s is a list of two strings, the first one for the Jimmy-row, the second one for the platform. Zip the characters which are above one another and then check whether - is below a part of Jimmy in at least two instances.

EDIT: Reduced by quite a few Bytes thanks to Blue!

Michael

Posted 2019-07-02T22:40:54.767

Reputation: 11

1Hi, welcome to Code Golf! Couple things: you might want to specify the input format in your answer (looks like s should be two lists, one for jimmy and one for the platform?). Also, there are a few places you can save bytes: instead of summing a list, you can sum the raw iterator (remove the brackets); instead of checking >=2, check >1; you can sum True and False like 1 and 0, no need for the if-else. Finally, before posting a new answer in the same language, you should look at the previous ones to see if you can improve. – Blue – 2019-08-06T21:30:23.423

@Blue Hi, thanks a lot! And yeah I will keep that in mind in the future. :) – Michael – 2019-08-09T16:57:54.103

0

C (gcc), 103 bytes

i,j,l;f(char*s){for(i=0;*s-10;j=*s++-47?j:i)++i;l=strlen(s)>j+1;s+=j;return l&&*s+s[1]+(s[2]?:32)>109;}

Try it online!

Would be much shorter (75 bytes), if it could be assumed that there is trailing whitespace after the platform.

Steadybox

Posted 2019-07-02T22:40:54.767

Reputation: 15 798

95 bytes – ceilingcat – 2019-07-03T01:35:51.117

0

Retina, 31 29 bytes

^(.)*/.*¶(?<-1>.)*(?(1)!) ?--

Try it online!

Saved 2 bytes thanks to Neil!

A simple regex that determines whether at least two pieces of the platform are directly beneath Jimmy. Assumes that the input will contain no ! characters.

FryAmTheEggman

Posted 2019-07-02T22:40:54.767

Reputation: 16 206

I don't think you need the trailing -?. – Neil – 2019-07-03T10:30:44.470

@Neil Quite right, I don't know what case I thought I was covering with that. – FryAmTheEggman – 2019-07-03T15:50:57.833

0

Oliver

Posted 2019-07-02T22:40:54.767

Reputation: 7 160

1@SriotchilismO'Zaic Updated – Oliver – 2019-07-03T03:02:17.317

0

V, 18 bytes

0vt/"_dj.d3lVkp0#x

Try it online!

Output whitespace only if jimmy fall of the platform. Output something non-whitespace if jimmy stay on the platform.

tsh

Posted 2019-07-02T22:40:54.767

Reputation: 13 072

Not using Ctrl or Esc in Vim is funny. – tsh – 2019-07-03T06:07:28.013

0

Japt -!, 7 bytes

ÕèSi.)z

Try it

ÕèSi.)z     :Implicit input of multi-line string
Õ           :Transpose
 è          :Count the occurrences of
  S         :  Space
   i.       :  Prepended with ".", giving the regex /. /g
     )      :End count
      z     :Floor divide by 2
            :Implicit output as Boolean

Shaggy

Posted 2019-07-02T22:40:54.767

Reputation: 24 623

0

Pyth, 9 bytes

!!tt#rL6C

Try it here! (Note: This is a temporary interpreter, hosted on pythtemp.herokuapp.com; the official pyth.herokuapp.com can't be used for now)

If swapping truthy-falsy values were allowed, this would become 8 bytes by dropping one of the !s (awaiting confirmation). Moreover, if outputting an empty list for the case when Jimmy falls and a non-empty list otherwise would be an option, both !s could be dropped.

How it works

!!tt#rL6C – Full program. Receives a list of two strings through STDIN.
        C – Transpose / Zip (switch from rows to columns)
     rL6  – Strip the whitespace on both sides of each column.
   t#     – Filter-keep those that have a tail (i.e. that are length-2).
  t       – Tail. The result will be non-empty iff Jimmy doesn't fall.
!!        – Double negation (to output as a boolean...).

Mr. Xcoder

Posted 2019-07-02T22:40:54.767

Reputation: 39 774

0

40 column Commodore BASIC (C64, C16/+4, C128, PET, C64Mini) - non-competing* - 98 tokenized and BASIC bytes used

 0a=rN(.)*36:b=rN(.)*39:c=-rN(.)*(b-39):fOi=0tob:a$=a$+"-":nE:?tAa)"/o\
 1?tAc)a$:?-(a>c-2anda<c+b+2)

Here is the unobfuscated listing for explanation purposes

 0 let a=rnd(0) * 36
 1 let b=rnd(0) * 39
 2 let c=-rnd(0) * (b - 39)
 3 for i=0 to b
 4  let a$=a$+"-"
 5 next i
 6 print tab(a);"/o\"
 7 print tab(c);a$
 8 print -(a>c - 2 and a<c + b + 2)

The variable a is used for positioning Jimmy (using PRINT TAB(A) which is zero-indexed).

The varaible b is used for the length of the platform.

And finally the variable c is used for the position of the platform.

The loop in lines 3 through to 5 inclusive builds the platform for Jimmy, with line 6 printing Jimmy at his pre-determined position, and 7 for the pre-determined position of the platform. Finally, 1 or 0 is outputted to represent our TRUE or FALSE value.

Note, the listing includes keyword abbreviations to ensure we break the 80 character limit per line on standard Commodore C64 BASIC.

enter image description here

* Assumed non-competing because PETSCII is not ASCII. Jimmy looks better in PETSCII though, of course.

Shaun Bebbers

Posted 2019-07-02T22:40:54.767

Reputation: 1 814

0

Attache, 38 bytes

{2>Sum!`~&Sum[Ord@Grid@_-39]=>1'46'65}

Try it online!

Explanation

We convert the input string to a grid of ASCII codepoints, subtract 39 from each, then take the Sum, columnwise. (Sum[Ord@Grid@_-32]). Then, we bind this array to the ~ operator, which in this case counts the number of times the argument occurs in the bound array. We apply this function to each member of the array 1'46'65 with =>, which correspond to various body parts not above a platform. We then take the sum of this resulting array with Sum!. This is the count of body parts not above the platform. Finally, we check to see that 2 exceeds this sum; if it does, then we return false, for Jimmy has fallen. If it does not, we return true, for Jimmy is quite safe on his perch.

Conor O'Brien

Posted 2019-07-02T22:40:54.767

Reputation: 36 228

0

Charcoal, 19 bytes

η⸿Pθ…θ⌕θo≔№KM-ζ⎚›ζ¹

Try it online! Link is to verbose version of code. Outputs - if the Jimmy will balance, nothing if he will fall off. Explanation:

η

Print the platform.

⸿

Move down a line. (Reversed gravity turned out to be golfier.)

Pθ

Print Jimmy without moving the cursor.

…θ⌕θo

Print Jimmy's leg leaving the cursor over his body.

≔№KM-ζ

Count the number of adjacent -s from the platform.

Clear the canvas.

›ζ¹

Output a - if the platform was large enough.

Neil

Posted 2019-07-02T22:40:54.767

Reputation: 95 035

The challenge asks for boolean output rather than the two distinct value sort of output that tends to be common. – Post Rock Garf Hunter – 2019-07-06T02:03:55.220

@SriotchilismO'Zaic That's just the default output of a boolean expression in Charcoal. – Neil – 2019-07-06T09:36:33.813

0

Brain-Flak, 210 bytes

{({}<>)<>}<>{({}[(()()()()()){}]<>)<>}<>({<(<({}[((()()()()()){}()){}])>{()(<{}>)}{}<{({}<>)<>}{}({}[((((()()()()()))){}{}){}{}])>[()()]{()(<{}>)}<<>{({}<>)<>}<>>)>[()]{()(<{}>)}{}}<>)(()[{<({}())>{()<{}>}}]{})

Try it online!

String parsing is hard in Brain-Flak. It considers anything on the first line other than space to be Jimmy and anything on the second line other than - to be open air. The reason we test for - instead of space is that Brain-Flak pads the input indefinitely to the right with nulls (ASCII codepoint 0) which we need to consider open air. This luckily means we don't have to worry about needing trailing whitespace in the input.

Post Rock Garf Hunter

Posted 2019-07-02T22:40:54.767

Reputation: 55 382

0

PHP, 90 80 bytes

Code

<?=substr_count(substr(($v=explode("
",$argv[1]))[1],strpos($v[0],"/"),3),"--");

Try it online!

Mistakenly coded allowwing jimmy with just a leg on the edge

<?=count($v=explode("
",$argv[1]))>1&&substr_count(substr($v[1],strpos($v[0],"/"),3),"-");

Try it online!

Explanation

<?=
substr_count(
substr(($v=explode("\n",$argv[1]))[1],// explode and get Jimmy body
        strpos($v[0],"/"),  // find "/" position (position start)
        3),                 // substring of the platform length
        "--");              // platform has to contain "--" somewhere
// 
//

Francisco Hahn

Posted 2019-07-02T22:40:54.767

Reputation: 591

The puzzle states that the input is two lines, and the second one is not empty, so you can remove that check – Einacio – 2019-07-08T11:05:57.453

I tested the code on the TIO, and it fails with two spaces before the platform, or if jimmy is only with it's left leg (test case 3). it also fails the last test case – Einacio – 2019-07-08T11:09:30.983

Thank you @Einacio, i mistakenly coded allowing jimmy to have 1 leg and nothing else on the platform, also ty for the advice on removing the condition for 2 lines as input. – Francisco Hahn – 2019-07-08T14:17:55.547

0

Elm 0.19, 99 bytes

f j p=List.sum(List.map2(\a b->if a/=' '&&b/=' 'then 1 else 0)(String.toList j)(String.toList p))>1

Port of Maxwell's Python 3 answer. Verify all test cases here.

O.O.Balance

Posted 2019-07-02T22:40:54.767

Reputation: 1 499

0

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

spuck

Posted 2019-07-02T22:40:54.767

Reputation: 649

0

Julia 1.0, 42 40 bytes

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

Try it online!

user3263164

Posted 2019-07-02T22:40:54.767

Reputation: 381