Will Jimmy fall off his platform?Count the bytes of a programCenter The Text!Analyse your ChairReverse positive runsBuilding a BridgeWill the beam hit?How much will this cost?Will Mario fall into the Shrinking Satellite? (Diagram added)Prime or highest factorPoint out a string character
Data normalization before or after train-test split?
Why do we need a bootloader separate than our application program in MCU's?
Should I cheat if the majority does it?
Speeding up thousands of string parses
Minimizing medical costs with HSA
CPA filed late returns, stating I would get money; IRS says they were filed too late
Do intermediate subdomains need to exist?
Explain how 'Sharing the burden' puzzle from Professor Layton and the Miracle Mask should be solved
Will Jimmy fall off his platform?
Do I need to be legally qualified to install a Hive smart thermostat?
Can a Time Lord survive with just one heart?
In the Seventh Seal why does Death let the chess game happen?
How did Einstein know the speed of light was constant?
Why did the "Orks" never develop better firearms than Firelances and Handcannons?
What is the difference between a historical drama and a period drama?
What units are kpts?
How would an Amulet of Proof Against Detection and Location interact with the Comprehend Languages spell?
Will electrically joined dipoles of different lengths, at right angles, behave as a multiband antenna?
Taking advantage when the HR forgets to communicate the rules
What can a novel do that film and TV cannot?
Why does mean tend be more stable in different samples than median?
Term for a character that only exists to be talked to
How can I effectively map a multi-level dungeon?
What is exact meaning of “ich wäre gern”?
Will Jimmy fall off his platform?
Count the bytes of a programCenter The Text!Analyse your ChairReverse positive runsBuilding a BridgeWill the beam hit?How much will this cost?Will Mario fall into the Shrinking Satellite? (Diagram added)Prime or highest factorPoint out a string character
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$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.
- 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,bodymargin:0;padding:0;height:100%;overflow:hidden</style>
code-golf ascii-art
$endgroup$
|
show 2 more comments
$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.
- 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,bodymargin:0;padding:0;height:100%;overflow:hidden</style>
code-golf ascii-art
$endgroup$
$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$
– Nick Kennedy
7 hours ago
$begingroup$
@NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
What if the input is taken as a matrix which has to be rectangular? Is that just not an accepted input method?
$endgroup$
– dzaima
7 hours ago
1
$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
3 hours ago
1
$begingroup$
Can you reformat your test cases to make them easier to copy & paste, please?
$endgroup$
– Shaggy
2 mins ago
|
show 2 more comments
$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.
- 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,bodymargin:0;padding:0;height:100%;overflow:hidden</style>
code-golf ascii-art
$endgroup$
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,bodymargin:0;padding:0;height:100%;overflow:hidden</style>
<!-- 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,bodymargin:0;padding:0;height:100%;overflow:hidden</style>
<!-- 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,bodymargin:0;padding:0;height:100%;overflow:hidden</style>
code-golf ascii-art
code-golf ascii-art
edited 7 hours ago
connectyourcharger
asked 8 hours ago
connectyourchargerconnectyourcharger
4381 gold badge2 silver badges13 bronze badges
4381 gold badge2 silver badges13 bronze badges
$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$
– Nick Kennedy
7 hours ago
$begingroup$
@NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
What if the input is taken as a matrix which has to be rectangular? Is that just not an accepted input method?
$endgroup$
– dzaima
7 hours ago
1
$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
3 hours ago
1
$begingroup$
Can you reformat your test cases to make them easier to copy & paste, please?
$endgroup$
– Shaggy
2 mins ago
|
show 2 more comments
$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$
– Nick Kennedy
7 hours ago
$begingroup$
@NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
What if the input is taken as a matrix which has to be rectangular? Is that just not an accepted input method?
$endgroup$
– dzaima
7 hours ago
1
$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
3 hours ago
1
$begingroup$
Can you reformat your test cases to make them easier to copy & paste, please?
$endgroup$
– Shaggy
2 mins ago
$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$
– Nick Kennedy
7 hours ago
$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$
– Nick Kennedy
7 hours ago
$begingroup$
@NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
@NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
What if the input is taken as a matrix which has to be rectangular? Is that just not an accepted input method?
$endgroup$
– dzaima
7 hours ago
$begingroup$
What if the input is taken as a matrix which has to be rectangular? Is that just not an accepted input method?
$endgroup$
– dzaima
7 hours ago
1
1
$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
3 hours ago
$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
3 hours ago
1
1
$begingroup$
Can you reformat your test cases to make them easier to copy & paste, please?
$endgroup$
– Shaggy
2 mins ago
$begingroup$
Can you reformat your test cases to make them easier to copy & paste, please?
$endgroup$
– Shaggy
2 mins ago
|
show 2 more comments
15 Answers
15
active
oldest
votes
$begingroup$
Jelly, 6 bytes
n⁶Sċ2Ẓ
Try it online!
$endgroup$
1
$begingroup$
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.
$endgroup$
– IMustBeSomeone
5 hours ago
add a comment |
$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$
1
$begingroup$
Can't you reduce by 2 bytes by converting to infix?
$endgroup$
– cole
4 hours ago
1
$begingroup$
@cole Yep I was just doing the edit when you commented :)
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$begingroup$
Python 2, 42 37 bytes
lambda j,p:'--'in p[j.find('/'):][:3]
Try it online!
5 bytes thx to negative seven
$endgroup$
$begingroup$
"--"in [...]
for -5 bytes
$endgroup$
– negative seven
57 mins ago
$begingroup$
@negative seven: nice; thanks!
$endgroup$
– Chas Brown
55 mins ago
add a comment |
$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.
New contributor
$endgroup$
add a comment |
$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$
$begingroup$
Wow. Could you explain how that works?
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
@connectyourcharger I've added an explanation.
$endgroup$
– Arnauld
7 hours ago
$begingroup$
Genius! JS answers usually aren't that short.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Would this work for 35 bytes?
$endgroup$
– Oliver
4 hours ago
$begingroup$
@Oliver will fail for"/o\n__"
$endgroup$
– tsh
3 hours ago
add a comment |
$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 1
s, 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 1
s (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$
$begingroup$
I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$begingroup$
Dyalog APL Extended, 11 10 bytes
2≤+/∧⌿<⍵
Try it online! Takes the input as a matrix.
Explanation:
2≤+/∧⌿<⍵ a monadic function with argument ⍵
<⍵ Compare with the implicit prototype element - a space.
Returns a matrix of characters that are greater than 0x20
∧⌿ and-reduce, i.e. places where both Jimmy and a platform is
+/ sum that array, i.e. amount of body parts over a platform
2≤ is that greater-or-equal to 2?
$endgroup$
1
$begingroup$
-2:2≤1⊥∧⌿⍤<
$endgroup$
– Adám
6 hours ago
add a comment |
$begingroup$
Perl 6, 18 bytes
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$
add a comment |
$begingroup$
VBA (Excel), 87 bytes EXCEL, 94 bytes
A1
= Jimmy , A2
= platform
=(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)*(LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))>1)
?[(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)]*(len(replace([A2]," ",""))>1)
$endgroup$
add a comment |
$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$
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
95 bytes
$endgroup$
– ceilingcat
5 hours ago
add a comment |
$begingroup$
Retina, 31 bytes
^(.)*/.*¶(?<-1>.)*(?(1)!) ?---?
Try it online!
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.
$endgroup$
add a comment |
$begingroup$
Japt -¡
, 9 bytes
-1 byte if the input can be reversed.
VtUao)è-²
Try it online
$endgroup$
1
$begingroup$
@SriotchilismO'Zaic Updated
$endgroup$
– Oliver
3 hours ago
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
Not using Ctrl or Esc in Vim is funny.
$endgroup$
– tsh
48 mins ago
add a comment |
$begingroup$
Japt, 8 bytes
Õ·kèS Êz
Try it
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f187586%2fwill-jimmy-fall-off-his-platform%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
15 Answers
15
active
oldest
votes
15 Answers
15
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Jelly, 6 bytes
n⁶Sċ2Ẓ
Try it online!
$endgroup$
1
$begingroup$
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.
$endgroup$
– IMustBeSomeone
5 hours ago
add a comment |
$begingroup$
Jelly, 6 bytes
n⁶Sċ2Ẓ
Try it online!
$endgroup$
1
$begingroup$
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.
$endgroup$
– IMustBeSomeone
5 hours ago
add a comment |
$begingroup$
Jelly, 6 bytes
n⁶Sċ2Ẓ
Try it online!
$endgroup$
Jelly, 6 bytes
n⁶Sċ2Ẓ
Try it online!
answered 7 hours ago
Erik the OutgolferErik the Outgolfer
34.2k4 gold badges30 silver badges107 bronze badges
34.2k4 gold badges30 silver badges107 bronze badges
1
$begingroup$
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.
$endgroup$
– IMustBeSomeone
5 hours ago
add a comment |
1
$begingroup$
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.
$endgroup$
– IMustBeSomeone
5 hours ago
1
1
$begingroup$
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.
$endgroup$
– IMustBeSomeone
5 hours ago
$begingroup$
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.
$endgroup$
– IMustBeSomeone
5 hours ago
add a comment |
$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$
1
$begingroup$
Can't you reduce by 2 bytes by converting to infix?
$endgroup$
– cole
4 hours ago
1
$begingroup$
@cole Yep I was just doing the edit when you commented :)
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$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$
1
$begingroup$
Can't you reduce by 2 bytes by converting to infix?
$endgroup$
– cole
4 hours ago
1
$begingroup$
@cole Yep I was just doing the edit when you commented :)
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$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$
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.
edited 4 hours ago
answered 4 hours ago
Sriotchilism O'ZaicSriotchilism O'Zaic
36.1k10 gold badges162 silver badges371 bronze badges
36.1k10 gold badges162 silver badges371 bronze badges
1
$begingroup$
Can't you reduce by 2 bytes by converting to infix?
$endgroup$
– cole
4 hours ago
1
$begingroup$
@cole Yep I was just doing the edit when you commented :)
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
1
$begingroup$
Can't you reduce by 2 bytes by converting to infix?
$endgroup$
– cole
4 hours ago
1
$begingroup$
@cole Yep I was just doing the edit when you commented :)
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
1
1
$begingroup$
Can't you reduce by 2 bytes by converting to infix?
$endgroup$
– cole
4 hours ago
$begingroup$
Can't you reduce by 2 bytes by converting to infix?
$endgroup$
– cole
4 hours ago
1
1
$begingroup$
@cole Yep I was just doing the edit when you commented :)
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
$begingroup$
@cole Yep I was just doing the edit when you commented :)
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$begingroup$
Python 2, 42 37 bytes
lambda j,p:'--'in p[j.find('/'):][:3]
Try it online!
5 bytes thx to negative seven
$endgroup$
$begingroup$
"--"in [...]
for -5 bytes
$endgroup$
– negative seven
57 mins ago
$begingroup$
@negative seven: nice; thanks!
$endgroup$
– Chas Brown
55 mins ago
add a comment |
$begingroup$
Python 2, 42 37 bytes
lambda j,p:'--'in p[j.find('/'):][:3]
Try it online!
5 bytes thx to negative seven
$endgroup$
$begingroup$
"--"in [...]
for -5 bytes
$endgroup$
– negative seven
57 mins ago
$begingroup$
@negative seven: nice; thanks!
$endgroup$
– Chas Brown
55 mins ago
add a comment |
$begingroup$
Python 2, 42 37 bytes
lambda j,p:'--'in p[j.find('/'):][:3]
Try it online!
5 bytes thx to negative seven
$endgroup$
Python 2, 42 37 bytes
lambda j,p:'--'in p[j.find('/'):][:3]
Try it online!
5 bytes thx to negative seven
edited 55 mins ago
answered 6 hours ago
Chas BrownChas Brown
5,6891 gold badge6 silver badges23 bronze badges
5,6891 gold badge6 silver badges23 bronze badges
$begingroup$
"--"in [...]
for -5 bytes
$endgroup$
– negative seven
57 mins ago
$begingroup$
@negative seven: nice; thanks!
$endgroup$
– Chas Brown
55 mins ago
add a comment |
$begingroup$
"--"in [...]
for -5 bytes
$endgroup$
– negative seven
57 mins ago
$begingroup$
@negative seven: nice; thanks!
$endgroup$
– Chas Brown
55 mins ago
$begingroup$
"--"in [...]
for -5 bytes$endgroup$
– negative seven
57 mins ago
$begingroup$
"--"in [...]
for -5 bytes$endgroup$
– negative seven
57 mins ago
$begingroup$
@negative seven: nice; thanks!
$endgroup$
– Chas Brown
55 mins ago
$begingroup$
@negative seven: nice; thanks!
$endgroup$
– Chas Brown
55 mins ago
add a comment |
$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.
New contributor
$endgroup$
add a comment |
$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.
New contributor
$endgroup$
add a comment |
$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.
New contributor
$endgroup$
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.
New contributor
edited 43 mins ago
New contributor
answered 4 hours ago
MaxwellMaxwell
1314 bronze badges
1314 bronze badges
New contributor
New contributor
add a comment |
add a comment |
$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$
$begingroup$
Wow. Could you explain how that works?
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
@connectyourcharger I've added an explanation.
$endgroup$
– Arnauld
7 hours ago
$begingroup$
Genius! JS answers usually aren't that short.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Would this work for 35 bytes?
$endgroup$
– Oliver
4 hours ago
$begingroup$
@Oliver will fail for"/o\n__"
$endgroup$
– tsh
3 hours ago
add a comment |
$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$
$begingroup$
Wow. Could you explain how that works?
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
@connectyourcharger I've added an explanation.
$endgroup$
– Arnauld
7 hours ago
$begingroup$
Genius! JS answers usually aren't that short.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Would this work for 35 bytes?
$endgroup$
– Oliver
4 hours ago
$begingroup$
@Oliver will fail for"/o\n__"
$endgroup$
– tsh
3 hours ago
add a comment |
$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$
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.
edited 7 hours ago
answered 7 hours ago
ArnauldArnauld
87.4k7 gold badges102 silver badges357 bronze badges
87.4k7 gold badges102 silver badges357 bronze badges
$begingroup$
Wow. Could you explain how that works?
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
@connectyourcharger I've added an explanation.
$endgroup$
– Arnauld
7 hours ago
$begingroup$
Genius! JS answers usually aren't that short.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Would this work for 35 bytes?
$endgroup$
– Oliver
4 hours ago
$begingroup$
@Oliver will fail for"/o\n__"
$endgroup$
– tsh
3 hours ago
add a comment |
$begingroup$
Wow. Could you explain how that works?
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
@connectyourcharger I've added an explanation.
$endgroup$
– Arnauld
7 hours ago
$begingroup$
Genius! JS answers usually aren't that short.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Would this work for 35 bytes?
$endgroup$
– Oliver
4 hours ago
$begingroup$
@Oliver will fail for"/o\n__"
$endgroup$
– tsh
3 hours ago
$begingroup$
Wow. Could you explain how that works?
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Wow. Could you explain how that works?
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
@connectyourcharger I've added an explanation.
$endgroup$
– Arnauld
7 hours ago
$begingroup$
@connectyourcharger I've added an explanation.
$endgroup$
– Arnauld
7 hours ago
$begingroup$
Genius! JS answers usually aren't that short.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Genius! JS answers usually aren't that short.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
Would this work for 35 bytes?
$endgroup$
– Oliver
4 hours ago
$begingroup$
Would this work for 35 bytes?
$endgroup$
– Oliver
4 hours ago
$begingroup$
@Oliver will fail for
"/o\n__"
$endgroup$
– tsh
3 hours ago
$begingroup$
@Oliver will fail for
"/o\n__"
$endgroup$
– tsh
3 hours ago
add a comment |
$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 1
s, 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 1
s (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$
$begingroup$
I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$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 1
s, 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 1
s (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$
$begingroup$
I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$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 1
s, 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 1
s (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$
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 1
s, 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 1
s (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. :(
answered 5 hours ago
Leo TenenbaumLeo Tenenbaum
9752 gold badges4 silver badges10 bronze badges
9752 gold badges4 silver badges10 bronze badges
$begingroup$
I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$begingroup$
I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
$begingroup$
I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
$begingroup$
I just thought I would let you know that your answer helped me to shorten my own answer. So thanks!
$endgroup$
– Sriotchilism O'Zaic
4 hours ago
add a comment |
$begingroup$
Dyalog APL Extended, 11 10 bytes
2≤+/∧⌿<⍵
Try it online! Takes the input as a matrix.
Explanation:
2≤+/∧⌿<⍵ a monadic function with argument ⍵
<⍵ Compare with the implicit prototype element - a space.
Returns a matrix of characters that are greater than 0x20
∧⌿ and-reduce, i.e. places where both Jimmy and a platform is
+/ sum that array, i.e. amount of body parts over a platform
2≤ is that greater-or-equal to 2?
$endgroup$
1
$begingroup$
-2:2≤1⊥∧⌿⍤<
$endgroup$
– Adám
6 hours ago
add a comment |
$begingroup$
Dyalog APL Extended, 11 10 bytes
2≤+/∧⌿<⍵
Try it online! Takes the input as a matrix.
Explanation:
2≤+/∧⌿<⍵ a monadic function with argument ⍵
<⍵ Compare with the implicit prototype element - a space.
Returns a matrix of characters that are greater than 0x20
∧⌿ and-reduce, i.e. places where both Jimmy and a platform is
+/ sum that array, i.e. amount of body parts over a platform
2≤ is that greater-or-equal to 2?
$endgroup$
1
$begingroup$
-2:2≤1⊥∧⌿⍤<
$endgroup$
– Adám
6 hours ago
add a comment |
$begingroup$
Dyalog APL Extended, 11 10 bytes
2≤+/∧⌿<⍵
Try it online! Takes the input as a matrix.
Explanation:
2≤+/∧⌿<⍵ a monadic function with argument ⍵
<⍵ Compare with the implicit prototype element - a space.
Returns a matrix of characters that are greater than 0x20
∧⌿ and-reduce, i.e. places where both Jimmy and a platform is
+/ sum that array, i.e. amount of body parts over a platform
2≤ is that greater-or-equal to 2?
$endgroup$
Dyalog APL Extended, 11 10 bytes
2≤+/∧⌿<⍵
Try it online! Takes the input as a matrix.
Explanation:
2≤+/∧⌿<⍵ a monadic function with argument ⍵
<⍵ Compare with the implicit prototype element - a space.
Returns a matrix of characters that are greater than 0x20
∧⌿ and-reduce, i.e. places where both Jimmy and a platform is
+/ sum that array, i.e. amount of body parts over a platform
2≤ is that greater-or-equal to 2?
edited 7 hours ago
answered 7 hours ago
dzaimadzaima
16.9k2 gold badges26 silver badges64 bronze badges
16.9k2 gold badges26 silver badges64 bronze badges
1
$begingroup$
-2:2≤1⊥∧⌿⍤<
$endgroup$
– Adám
6 hours ago
add a comment |
1
$begingroup$
-2:2≤1⊥∧⌿⍤<
$endgroup$
– Adám
6 hours ago
1
1
$begingroup$
-2:
2≤1⊥∧⌿⍤<
$endgroup$
– Adám
6 hours ago
$begingroup$
-2:
2≤1⊥∧⌿⍤<
$endgroup$
– Adám
6 hours ago
add a comment |
$begingroup$
Perl 6, 18 bytes
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$
add a comment |
$begingroup$
Perl 6, 18 bytes
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$
add a comment |
$begingroup$
Perl 6, 18 bytes
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$
Perl 6, 18 bytes
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" ~^ "--"
edited 2 hours ago
answered 5 hours ago
Jo KingJo King
29.3k3 gold badges69 silver badges135 bronze badges
29.3k3 gold badges69 silver badges135 bronze badges
add a comment |
add a comment |
$begingroup$
VBA (Excel), 87 bytes EXCEL, 94 bytes
A1
= Jimmy , A2
= platform
=(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)*(LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))>1)
?[(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)]*(len(replace([A2]," ",""))>1)
$endgroup$
add a comment |
$begingroup$
VBA (Excel), 87 bytes EXCEL, 94 bytes
A1
= Jimmy , A2
= platform
=(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)*(LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))>1)
?[(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)]*(len(replace([A2]," ",""))>1)
$endgroup$
add a comment |
$begingroup$
VBA (Excel), 87 bytes EXCEL, 94 bytes
A1
= Jimmy , A2
= platform
=(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)*(LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))>1)
?[(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)]*(len(replace([A2]," ",""))>1)
$endgroup$
VBA (Excel), 87 bytes EXCEL, 94 bytes
A1
= Jimmy , A2
= platform
=(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)*(LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))>1)
?[(FIND("-",A2)-FIND("/",A1)<2)*(FIND("",A1)-LEN(A2)<2)]*(len(replace([A2]," ",""))>1)
edited 1 hour ago
answered 1 hour ago
remoelremoel
4612 silver badges6 bronze badges
4612 silver badges6 bronze badges
add a comment |
add a comment |
$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$
add a comment |
$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$
add a comment |
$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$
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.
answered 7 hours ago
Nick KennedyNick Kennedy
4,0497 silver badges12 bronze badges
4,0497 silver badges12 bronze badges
add a comment |
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
95 bytes
$endgroup$
– ceilingcat
5 hours ago
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
95 bytes
$endgroup$
– ceilingcat
5 hours ago
add a comment |
$begingroup$
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.
$endgroup$
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.
answered 5 hours ago
SteadyboxSteadybox
15k4 gold badges29 silver badges81 bronze badges
15k4 gold badges29 silver badges81 bronze badges
$begingroup$
95 bytes
$endgroup$
– ceilingcat
5 hours ago
add a comment |
$begingroup$
95 bytes
$endgroup$
– ceilingcat
5 hours ago
$begingroup$
95 bytes
$endgroup$
– ceilingcat
5 hours ago
$begingroup$
95 bytes
$endgroup$
– ceilingcat
5 hours ago
add a comment |
$begingroup$
Retina, 31 bytes
^(.)*/.*¶(?<-1>.)*(?(1)!) ?---?
Try it online!
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.
$endgroup$
add a comment |
$begingroup$
Retina, 31 bytes
^(.)*/.*¶(?<-1>.)*(?(1)!) ?---?
Try it online!
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.
$endgroup$
add a comment |
$begingroup$
Retina, 31 bytes
^(.)*/.*¶(?<-1>.)*(?(1)!) ?---?
Try it online!
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.
$endgroup$
Retina, 31 bytes
^(.)*/.*¶(?<-1>.)*(?(1)!) ?---?
Try it online!
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.
answered 5 hours ago
FryAmTheEggmanFryAmTheEggman
15.1k3 gold badges25 silver badges85 bronze badges
15.1k3 gold badges25 silver badges85 bronze badges
add a comment |
add a comment |
$begingroup$
Japt -¡
, 9 bytes
-1 byte if the input can be reversed.
VtUao)è-²
Try it online
$endgroup$
1
$begingroup$
@SriotchilismO'Zaic Updated
$endgroup$
– Oliver
3 hours ago
add a comment |
$begingroup$
Japt -¡
, 9 bytes
-1 byte if the input can be reversed.
VtUao)è-²
Try it online
$endgroup$
1
$begingroup$
@SriotchilismO'Zaic Updated
$endgroup$
– Oliver
3 hours ago
add a comment |
$begingroup$
Japt -¡
, 9 bytes
-1 byte if the input can be reversed.
VtUao)è-²
Try it online
$endgroup$
Japt -¡
, 9 bytes
-1 byte if the input can be reversed.
VtUao)è-²
Try it online
edited 3 hours ago
answered 3 hours ago
OliverOliver
5,5451 gold badge8 silver badges33 bronze badges
5,5451 gold badge8 silver badges33 bronze badges
1
$begingroup$
@SriotchilismO'Zaic Updated
$endgroup$
– Oliver
3 hours ago
add a comment |
1
$begingroup$
@SriotchilismO'Zaic Updated
$endgroup$
– Oliver
3 hours ago
1
1
$begingroup$
@SriotchilismO'Zaic Updated
$endgroup$
– Oliver
3 hours ago
$begingroup$
@SriotchilismO'Zaic Updated
$endgroup$
– Oliver
3 hours ago
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
Not using Ctrl or Esc in Vim is funny.
$endgroup$
– tsh
48 mins ago
add a comment |
$begingroup$
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.
$endgroup$
$begingroup$
Not using Ctrl or Esc in Vim is funny.
$endgroup$
– tsh
48 mins ago
add a comment |
$begingroup$
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.
$endgroup$
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.
answered 50 mins ago
tshtsh
10.3k1 gold badge16 silver badges57 bronze badges
10.3k1 gold badge16 silver badges57 bronze badges
$begingroup$
Not using Ctrl or Esc in Vim is funny.
$endgroup$
– tsh
48 mins ago
add a comment |
$begingroup$
Not using Ctrl or Esc in Vim is funny.
$endgroup$
– tsh
48 mins ago
$begingroup$
Not using Ctrl or Esc in Vim is funny.
$endgroup$
– tsh
48 mins ago
$begingroup$
Not using Ctrl or Esc in Vim is funny.
$endgroup$
– tsh
48 mins ago
add a comment |
$begingroup$
Japt, 8 bytes
Õ·kèS Êz
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 8 bytes
Õ·kèS Êz
Try it
$endgroup$
add a comment |
$begingroup$
Japt, 8 bytes
Õ·kèS Êz
Try it
$endgroup$
Japt, 8 bytes
Õ·kèS Êz
Try it
answered 45 mins ago
Embodiment of IgnoranceEmbodiment of Ignorance
4,3461 silver badge28 bronze badges
4,3461 silver badge28 bronze badges
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f187586%2fwill-jimmy-fall-off-his-platform%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$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$
– Nick Kennedy
7 hours ago
$begingroup$
@NickKennedy You need to account for trailing whitespace or no trailing whitespace. I didn't set strict rules on that.
$endgroup$
– connectyourcharger
7 hours ago
$begingroup$
What if the input is taken as a matrix which has to be rectangular? Is that just not an accepted input method?
$endgroup$
– dzaima
7 hours ago
1
$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
3 hours ago
1
$begingroup$
Can you reformat your test cases to make them easier to copy & paste, please?
$endgroup$
– Shaggy
2 mins ago