35
\$\begingroup\$

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.

\$\endgroup\$
16
  • \$\begingroup\$ 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. \$\endgroup\$ Jul 2, 2019 at 23:07
  • \$\begingroup\$ @NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that. \$\endgroup\$
    – moltarze
    Jul 2, 2019 at 23:09
  • 14
    \$\begingroup\$ Title is "will jimmy fall of the platform" and you required to output "will jimmy stay on the platform". Is this expected behavior? \$\endgroup\$
    – tsh
    Jul 3, 2019 at 3:29
  • 6
    \$\begingroup\$ Can you reformat your test cases to make them easier to copy & paste, please? \$\endgroup\$
    – Shaggy
    Jul 3, 2019 at 6:53
  • 3
    \$\begingroup\$ Is swapping truthy-falsy values allowed? (i.e. output true when Jimmy falls and false when that doesn't happen?) \$\endgroup\$
    – Mr. Xcoder
    Jul 3, 2019 at 9:48

50 Answers 50

21
\$\begingroup\$

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)
\$\endgroup\$
5
  • 4
    \$\begingroup\$ @IMustBeSomeone, if I'm going to fall off a platform to my doom, I'd want someone to be quick in telling me! \$\endgroup\$
    – Shaggy
    Jul 3, 2019 at 7:02
  • 19
    \$\begingroup\$ @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 \$\endgroup\$ Jul 3, 2019 at 7:10
  • 1
    \$\begingroup\$ 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].. \$\endgroup\$ Jul 3, 2019 at 7:42
  • 2
    \$\begingroup\$ @KevinCruijssen S is equivalent to 0;+/Ɗ, that is, reduce by addition (which vectorizes) with initial value 0. § does what you expected S to do. \$\endgroup\$ Jul 3, 2019 at 8:08
  • \$\begingroup\$ @KevinCruijssen I've gotten around to adding an explanation. \$\endgroup\$ Jul 3, 2019 at 19:47
20
\$\begingroup\$

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.

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

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.

\$\endgroup\$
0
10
\$\begingroup\$

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 -?
\$\endgroup\$
2
  • 1
    \$\begingroup\$ @Keeta Edits within the first five minutes aren't shown in the edit history. \$\endgroup\$
    – anon
    Jul 3, 2019 at 16:27
  • \$\begingroup\$ From the limited testing I did, I think that you can change <> to > \$\endgroup\$ Jul 19, 2019 at 17:54
9
\$\begingroup\$

Python 2, 42 37 bytes

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

Try it online!

5 bytes thx to negative seven

\$\endgroup\$
2
  • 1
    \$\begingroup\$ "--"in [...] for -5 bytes \$\endgroup\$ Jul 3, 2019 at 5:57
  • \$\begingroup\$ @negative seven: nice; thanks! \$\endgroup\$
    – Chas Brown
    Jul 3, 2019 at 6:00
8
\$\begingroup\$

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

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can't you reduce by 2 bytes by converting to infix? \$\endgroup\$
    – cole
    Jul 3, 2019 at 2:49
  • 1
    \$\begingroup\$ @cole Yep I was just doing the edit when you commented :) \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2019 at 2:49
6
\$\begingroup\$

///, 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.
\$\endgroup\$
1
  • 3
    \$\begingroup\$ The source code looks like some strange emoji. \\(o)-(o)// \$\endgroup\$
    – tsh
    Jul 4, 2019 at 3:52
6
\$\begingroup\$

///, 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 !
\$\endgroup\$
5
\$\begingroup\$

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.

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

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
\$\endgroup\$
3
  • \$\begingroup\$ 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-". \$\endgroup\$ Jul 3, 2019 at 8:52
  • 1
    \$\begingroup\$ Fails for tio.run/##y00syUjPz0n7/z/u8G7d/MMbH01d/v@/un5@TIy6grqurvp/3RQA \$\endgroup\$ Jul 3, 2019 at 10:31
  • \$\begingroup\$ @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. \$\endgroup\$
    – maxb
    Jul 3, 2019 at 11:16
4
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

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)
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Your title breaks the leaderboard, smh :) \$\endgroup\$
    – moltarze
    Jul 3, 2019 at 13:37
  • \$\begingroup\$ @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. \$\endgroup\$ Jul 3, 2019 at 13:44
  • \$\begingroup\$ 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. \$\endgroup\$
    – moltarze
    Jul 3, 2019 at 13:47
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – moltarze
    Jul 3, 2019 at 14:12
  • \$\begingroup\$ 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? \$\endgroup\$
    – L. F.
    Jul 18, 2019 at 3:26
3
\$\begingroup\$

Ruby, 28 bytes

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

Try it online!

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

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.

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

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)

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

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.

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

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.

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

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

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

\$\endgroup\$
1
  • \$\begingroup\$ I just thought I would let you know that your answer helped me to shorten my own answer. So thanks! \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2019 at 2:51
2
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Suggest index() instead of strchr() \$\endgroup\$
    – ceilingcat
    Jul 6, 2019 at 20:39
2
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf! That's certainly a very nice first answer. \$\endgroup\$
    – moltarze
    Jul 5, 2019 at 17:02
2
\$\begingroup\$

Julia 1.0, 42 40 bytes

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

Try it online!

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

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.

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

Japt, 8 bytes

Õ·kèS Êz

Try it

\$\endgroup\$
1
  • \$\begingroup\$ Sorry, didn't see this before posting mine last night :\ \$\endgroup\$
    – Shaggy
    Jul 3, 2019 at 17:00
1
\$\begingroup\$

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.

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

Perl 5 -pl, 42 bytes

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

Try it online!

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

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.

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

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
\$\endgroup\$
4
  • \$\begingroup\$ Huh. I never considered PowerShell a great golfing language, but I guess it's actually not that bad. \$\endgroup\$
    – moltarze
    Jul 3, 2019 at 17:39
  • \$\begingroup\$ @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. \$\endgroup\$
    – Veskah
    Jul 3, 2019 at 17:43
  • \$\begingroup\$ I never bothered to learn it because of those pain-in-the-ass reasons. \$\endgroup\$
    – moltarze
    Jul 3, 2019 at 17:45
  • 1
    \$\begingroup\$ nice! step back and save one more :) \$\endgroup\$
    – mazzy
    Jul 3, 2019 at 23:32
1
\$\begingroup\$

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.

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

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!

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

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.