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.
- 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.
- 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.
The platform cannot be a length of zero, and the platform must be complete (no holes in the platform).
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.
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 code-golf, 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>
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.3902Is 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