Can Jimmy hang on his rope?Will Jimmy fall off his platform?How many Jimmys can fit?Jimmy needs your help!Tips for golfing in ///Jimmy needs a new pair of shoes!Count the bytes of a programCenter The Text!Analyse your ChairSplit a Shakespeare ScriptJimmy these arrays downNo strings attached!Would this string work as string?Will Jimmy fall off his platform?How many Jimmys can fit?Jimmy needs your help!
Why limit to revolvers?
Redox reactions redefined
Project Euler, problem # 9, Pythagorean triplet
Does optical correction give a more aesthetic look to the SBI logo?
Getting fresh water in the middle of hypersaline lake in the Bronze Age
Is this more than a packing puzzle?
How to make "plastic" sounding distored guitar
Are there any double stars that I can actually see orbit each other?
Why does the Earth have a z-component at the start of the J2000 epoch?
Is it okay to retroactively change things when running a published adventure?
Use of "sit" instead of "est" in Virgil
Why do they not say "The Baby"
I have accepted an internship offer. Should I inform companies I have applied to that have not gotten back to me yet?
Is a public company able to check out who owns its shares in very detailed format?
Why is dry soil hydrophobic? Bad gardener paradox
Can I activate an iPhone without an Apple ID?
Why do legislative committees exist?
How to draw a gif with expanding circles that reveal lines connecting a non-centered point to the expanding circle using Tikz
Why do mean value theorems have open interval for differentiablity while closed for continuity?
Did the Shuttle's rudder or elevons operate when flown on its carrier 747?
What is the standard dungeon scale at the table?
What are the arguments for California’s nonpartisan blanket primaries other than giving Democrats more power?
Are L-functions uniquely determined by their values at negative integers?
Possible isometry groups of open manifolds
Can Jimmy hang on his rope?
Will Jimmy fall off his platform?How many Jimmys can fit?Jimmy needs your help!Tips for golfing in ///Jimmy needs a new pair of shoes!Count the bytes of a programCenter The Text!Analyse your ChairSplit a Shakespeare ScriptJimmy these arrays downNo strings attached!Would this string work as string?Will Jimmy fall off his platform?How many Jimmys can fit?Jimmy needs your help!
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Yet another Jimmy challenge by his original father. See these other lovely challenges.
As you all know, recently we've been seeing challenges related to Jimmy on platforms. Now, Jimmy is an acrobat as I mentioned before, and he's got other tricks up his sleeve.
One of these tricks is hanging by ropes. Here's an example of a rope Jimmy could hang from:
||
||
||
||
||
||
When Jimmy hangs on a rope, it looks like this:
||
||
/o
||
||
||
He can hang on the left or the right of the rope, so this:
||
||
||
/o
||
||
is also valid. But he cannot hang by just one body part, so anything like this:
||
||
||
/o|
||
||
is invalid. Note that when he is hanging by one body part the other half of the rope is visible because Jimmy does not cover it up.
Also, Jimmy does not like hanging on the bottom of the rope - it scares him - so this:
||
||
||
||
||
/o
is invalid.
The challenge
Take input of a Jimmy situation like the ones above, and output whether Jimmy will hang on to the rope or not through a truthy or falsy value.
The specifics
Write a program that takes input. This can be through a function or any other appropriate input method.
- The input should be a scene of one Jimmy and a rope as exemplified above.
The program should output a truthy or falsy value to the console based on whether Jimmy can hang on to the rope or if he would fall off the rope, respectively.
The criteria for Jimmy being able to hang on the rope:
Two of his body parts are on the rope.
He is not on the bottom of the rope.
He is not floating in mid-air.
You can assume the rope will be straight, made up of
||
segments, and will be longer than one character in height.You can assume one whole rope and one singular Jimmy will be present in your scene, no more and no less.
You can assume there will be no trailing newlines at the bottom of the rope.
You must cover any amount of leading or trailing spaces before and after the rope.
Test cases
||
||
|| TRUTHY
/o
||
||
||
||
/o| FALSY
||
||
||
/o TRUTHY
||
||
/o FALSY
/o
|| TRUTHY
||
||
/o || FALSY
||
||
Scoring
This is code-golf, so lowest score in bytes wins after about a week.
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=187759" 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 string ascii-art parsing
$endgroup$
|
show 5 more comments
$begingroup$
Yet another Jimmy challenge by his original father. See these other lovely challenges.
As you all know, recently we've been seeing challenges related to Jimmy on platforms. Now, Jimmy is an acrobat as I mentioned before, and he's got other tricks up his sleeve.
One of these tricks is hanging by ropes. Here's an example of a rope Jimmy could hang from:
||
||
||
||
||
||
When Jimmy hangs on a rope, it looks like this:
||
||
/o
||
||
||
He can hang on the left or the right of the rope, so this:
||
||
||
/o
||
||
is also valid. But he cannot hang by just one body part, so anything like this:
||
||
||
/o|
||
||
is invalid. Note that when he is hanging by one body part the other half of the rope is visible because Jimmy does not cover it up.
Also, Jimmy does not like hanging on the bottom of the rope - it scares him - so this:
||
||
||
||
||
/o
is invalid.
The challenge
Take input of a Jimmy situation like the ones above, and output whether Jimmy will hang on to the rope or not through a truthy or falsy value.
The specifics
Write a program that takes input. This can be through a function or any other appropriate input method.
- The input should be a scene of one Jimmy and a rope as exemplified above.
The program should output a truthy or falsy value to the console based on whether Jimmy can hang on to the rope or if he would fall off the rope, respectively.
The criteria for Jimmy being able to hang on the rope:
Two of his body parts are on the rope.
He is not on the bottom of the rope.
He is not floating in mid-air.
You can assume the rope will be straight, made up of
||
segments, and will be longer than one character in height.You can assume one whole rope and one singular Jimmy will be present in your scene, no more and no less.
You can assume there will be no trailing newlines at the bottom of the rope.
You must cover any amount of leading or trailing spaces before and after the rope.
Test cases
||
||
|| TRUTHY
/o
||
||
||
||
/o| FALSY
||
||
||
/o TRUTHY
||
||
/o FALSY
/o
|| TRUTHY
||
||
/o || FALSY
||
||
Scoring
This is code-golf, so lowest score in bytes wins after about a week.
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=187759" 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 string ascii-art parsing
$endgroup$
1
$begingroup$
Is the rope always going to have the same number of spaces before it, or can that vary?
$endgroup$
– mprogrammer
Jul 6 at 15:53
$begingroup$
@Maxwell That can vary.
$endgroup$
– connectyourcharger
Jul 6 at 15:58
$begingroup$
Can we take the input as something like a list, where each line is a separate string, or does it have to be one single string?
$endgroup$
– mprogrammer
Jul 6 at 16:02
18
$begingroup$
Jimmy should really take a holiday
$endgroup$
– Luis Mendo
Jul 6 at 16:20
6
$begingroup$
@LuisMendo Jimmy is dedicated to what he does!
$endgroup$
– connectyourcharger
Jul 6 at 16:25
|
show 5 more comments
$begingroup$
Yet another Jimmy challenge by his original father. See these other lovely challenges.
As you all know, recently we've been seeing challenges related to Jimmy on platforms. Now, Jimmy is an acrobat as I mentioned before, and he's got other tricks up his sleeve.
One of these tricks is hanging by ropes. Here's an example of a rope Jimmy could hang from:
||
||
||
||
||
||
When Jimmy hangs on a rope, it looks like this:
||
||
/o
||
||
||
He can hang on the left or the right of the rope, so this:
||
||
||
/o
||
||
is also valid. But he cannot hang by just one body part, so anything like this:
||
||
||
/o|
||
||
is invalid. Note that when he is hanging by one body part the other half of the rope is visible because Jimmy does not cover it up.
Also, Jimmy does not like hanging on the bottom of the rope - it scares him - so this:
||
||
||
||
||
/o
is invalid.
The challenge
Take input of a Jimmy situation like the ones above, and output whether Jimmy will hang on to the rope or not through a truthy or falsy value.
The specifics
Write a program that takes input. This can be through a function or any other appropriate input method.
- The input should be a scene of one Jimmy and a rope as exemplified above.
The program should output a truthy or falsy value to the console based on whether Jimmy can hang on to the rope or if he would fall off the rope, respectively.
The criteria for Jimmy being able to hang on the rope:
Two of his body parts are on the rope.
He is not on the bottom of the rope.
He is not floating in mid-air.
You can assume the rope will be straight, made up of
||
segments, and will be longer than one character in height.You can assume one whole rope and one singular Jimmy will be present in your scene, no more and no less.
You can assume there will be no trailing newlines at the bottom of the rope.
You must cover any amount of leading or trailing spaces before and after the rope.
Test cases
||
||
|| TRUTHY
/o
||
||
||
||
/o| FALSY
||
||
||
/o TRUTHY
||
||
/o FALSY
/o
|| TRUTHY
||
||
/o || FALSY
||
||
Scoring
This is code-golf, so lowest score in bytes wins after about a week.
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=187759" 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 string ascii-art parsing
$endgroup$
Yet another Jimmy challenge by his original father. See these other lovely challenges.
As you all know, recently we've been seeing challenges related to Jimmy on platforms. Now, Jimmy is an acrobat as I mentioned before, and he's got other tricks up his sleeve.
One of these tricks is hanging by ropes. Here's an example of a rope Jimmy could hang from:
||
||
||
||
||
||
When Jimmy hangs on a rope, it looks like this:
||
||
/o
||
||
||
He can hang on the left or the right of the rope, so this:
||
||
||
/o
||
||
is also valid. But he cannot hang by just one body part, so anything like this:
||
||
||
/o|
||
||
is invalid. Note that when he is hanging by one body part the other half of the rope is visible because Jimmy does not cover it up.
Also, Jimmy does not like hanging on the bottom of the rope - it scares him - so this:
||
||
||
||
||
/o
is invalid.
The challenge
Take input of a Jimmy situation like the ones above, and output whether Jimmy will hang on to the rope or not through a truthy or falsy value.
The specifics
Write a program that takes input. This can be through a function or any other appropriate input method.
- The input should be a scene of one Jimmy and a rope as exemplified above.
The program should output a truthy or falsy value to the console based on whether Jimmy can hang on to the rope or if he would fall off the rope, respectively.
The criteria for Jimmy being able to hang on the rope:
Two of his body parts are on the rope.
He is not on the bottom of the rope.
He is not floating in mid-air.
You can assume the rope will be straight, made up of
||
segments, and will be longer than one character in height.You can assume one whole rope and one singular Jimmy will be present in your scene, no more and no less.
You can assume there will be no trailing newlines at the bottom of the rope.
You must cover any amount of leading or trailing spaces before and after the rope.
Test cases
||
||
|| TRUTHY
/o
||
||
||
||
/o| FALSY
||
||
||
/o TRUTHY
||
||
/o FALSY
/o
|| TRUTHY
||
||
/o || FALSY
||
||
Scoring
This is code-golf, so lowest score in bytes wins after about a week.
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=187759" 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=187759" 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=187759" 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 string ascii-art parsing
code-golf string ascii-art parsing
edited Jul 6 at 16:58
Glorfindel
2351 gold badge3 silver badges9 bronze badges
2351 gold badge3 silver badges9 bronze badges
asked Jul 6 at 15:26
connectyourchargerconnectyourcharger
7571 gold badge6 silver badges21 bronze badges
7571 gold badge6 silver badges21 bronze badges
1
$begingroup$
Is the rope always going to have the same number of spaces before it, or can that vary?
$endgroup$
– mprogrammer
Jul 6 at 15:53
$begingroup$
@Maxwell That can vary.
$endgroup$
– connectyourcharger
Jul 6 at 15:58
$begingroup$
Can we take the input as something like a list, where each line is a separate string, or does it have to be one single string?
$endgroup$
– mprogrammer
Jul 6 at 16:02
18
$begingroup$
Jimmy should really take a holiday
$endgroup$
– Luis Mendo
Jul 6 at 16:20
6
$begingroup$
@LuisMendo Jimmy is dedicated to what he does!
$endgroup$
– connectyourcharger
Jul 6 at 16:25
|
show 5 more comments
1
$begingroup$
Is the rope always going to have the same number of spaces before it, or can that vary?
$endgroup$
– mprogrammer
Jul 6 at 15:53
$begingroup$
@Maxwell That can vary.
$endgroup$
– connectyourcharger
Jul 6 at 15:58
$begingroup$
Can we take the input as something like a list, where each line is a separate string, or does it have to be one single string?
$endgroup$
– mprogrammer
Jul 6 at 16:02
18
$begingroup$
Jimmy should really take a holiday
$endgroup$
– Luis Mendo
Jul 6 at 16:20
6
$begingroup$
@LuisMendo Jimmy is dedicated to what he does!
$endgroup$
– connectyourcharger
Jul 6 at 16:25
1
1
$begingroup$
Is the rope always going to have the same number of spaces before it, or can that vary?
$endgroup$
– mprogrammer
Jul 6 at 15:53
$begingroup$
Is the rope always going to have the same number of spaces before it, or can that vary?
$endgroup$
– mprogrammer
Jul 6 at 15:53
$begingroup$
@Maxwell That can vary.
$endgroup$
– connectyourcharger
Jul 6 at 15:58
$begingroup$
@Maxwell That can vary.
$endgroup$
– connectyourcharger
Jul 6 at 15:58
$begingroup$
Can we take the input as something like a list, where each line is a separate string, or does it have to be one single string?
$endgroup$
– mprogrammer
Jul 6 at 16:02
$begingroup$
Can we take the input as something like a list, where each line is a separate string, or does it have to be one single string?
$endgroup$
– mprogrammer
Jul 6 at 16:02
18
18
$begingroup$
Jimmy should really take a holiday
$endgroup$
– Luis Mendo
Jul 6 at 16:20
$begingroup$
Jimmy should really take a holiday
$endgroup$
– Luis Mendo
Jul 6 at 16:20
6
6
$begingroup$
@LuisMendo Jimmy is dedicated to what he does!
$endgroup$
– connectyourcharger
Jul 6 at 16:25
$begingroup$
@LuisMendo Jimmy is dedicated to what he does!
$endgroup$
– connectyourcharger
Jul 6 at 16:25
|
show 5 more comments
23 Answers
23
active
oldest
votes
$begingroup$
Japt, 5 bytes
I think this is right; I've been working for 16 hours straight and barely know my own name so I wouldn't be surprised if it's not!
Õø|io
Try it
Õø|io :Implicit input
Õ :Transpose
ø :Contains?
|io : "|" prepended with "o"
$endgroup$
2
$begingroup$
16 hours? Now that's dedication!
$endgroup$
– connectyourcharger
Jul 7 at 9:08
1
$begingroup$
Wait so it took you 16 hours to write down 5 bytes? ;-)
$endgroup$
– Cullub
Jul 9 at 17:41
$begingroup$
Looks you like you need a break (same advice goes for little Jimmy!).
$endgroup$
– ihavenoidea
Jul 9 at 20:52
$begingroup$
@connectyourcharger, no, that's my life! Dedication would be doing it without a break. Which I did!
$endgroup$
– Shaggy
Jul 11 at 21:53
$begingroup$
@Cullub, not quite but it did take a hell of a lot longer than it should have given the state I was in!
$endgroup$
– Shaggy
Jul 11 at 21:54
|
show 1 more comment
$begingroup$
Python 2 or 3, 33 30 bytes
-3 thanks to Maxwell
lambda l:'o'in map(max,l[:-1])
An unnamed function accepting a list of lines
Try it online!
How?
There needs to be a section of rope obscured by Jimmy that is not the bottom one.
lambda l:'o'in map(max,l[:-1])
lambda l: # a function taking l (the lines as strings)
l[:-1] # strip off the last line
map(max, ) # maximum of each line (where '|'>'o'>''>'/'>' ')
'o'in # was 'o' one of them? (hence Jimmy obscured all the rope)
$endgroup$
$begingroup$
Save three bytes:lambda l:'o'in map(max,l[:-1])
$endgroup$
– mprogrammer
Jul 7 at 21:02
$begingroup$
Oh, very astute - thanks!
$endgroup$
– Jonathan Allan
Jul 7 at 21:21
$begingroup$
That's a very clever use of ASCII values. Nice.
$endgroup$
– Nic Hartley
Jul 8 at 15:03
add a comment |
$begingroup$
Python 2, 28 bytes
lambda x:"o', '|"in`zip(*x)`
Try it online!
How does it work? It takes input as a list of strings, and zip joins the string. Jimmy stays on the rope if there is a "|" below an "o", so this code joins all the lines and checks if there is an "o" followed by a "|".
Annotated code:
lambda x: # Creates an anonymous function that takes one argument
"o', '|" # If this substring is in the zip object, then Jimmy's "o" is above a "|"
in
` # Back quotes change the object into its string representation
zip(*x)` # Joins the lines together
(Old Answer) Python 2 or 3, 39 bytes
lambda x:1-all("|"in i for i in x[:-1])
A function that takes input as a list of strings, each string being a different line.
-11 bytes thanks to xnor! -2 bytes thanks to Jonathan Allan!
Try it online! (If you want to try more test cases, just put a "." after each set of lines in the input box.)
How does this work? Well, if Jimmy is fully on the rope, then that line will not have any "|" characters. Therefore, we can check each line, and if we find any with no "|" characters, then we know that Jimmy can stay on the rope. However, Jimmy can not hang on to the bottom of the rope; therefore, we don't include the final line in our check. If the final line is just another part of the rope, than it won't matter, because we'll still find a valid row higher up, but if the final line is the one with Jimmy, then it won't find a line without "|" anywhere, and will return False.
$endgroup$
$begingroup$
Can you do it without the check that the line has a "/"?
$endgroup$
– xnor
Jul 6 at 16:49
$begingroup$
@xnor Yup! -11 bytes
$endgroup$
– mprogrammer
Jul 6 at 16:50
1
$begingroup$
Save a couple like so:lambda x:1-all("|"in i for i in x[:-1])
$endgroup$
– Jonathan Allan
Jul 6 at 17:12
1
$begingroup$
Ouch, you was faster :)
$endgroup$
– Daniil Tutubalin
Jul 6 at 17:22
1
$begingroup$
@KlaymenDK The function iterates through x[:-1], not x. x[:-1] is all the elements of the list except the final element, because in Python you can use negative indices. Therefore, it (correctly) returns a falsy result if Jimmy is at the bottom of the rope.
$endgroup$
– mprogrammer
Jul 7 at 19:55
|
show 1 more comment
$begingroup$
Jelly, 9 7 6 bytes
Ṗ<”|ṀẠ
A monadic Link accepting a list of lines
Try it online!
How?
There needs to be a section of rope obscured by Jimmy that is not the bottom one.
Ṗ<”|ṀẠ - Main Link: list of lines of characters
Ṗ - remove last line
”| - pipe character
< - less than? (vectorises) - Note that all other characters are
Ṁ - maximum
Ạ - all?
$endgroup$
1
$begingroup$
I feel so weird writing these challenges about Jimmies. It starts to make you feel weird once you imagine multiple Jimmies hanging off of the same rope.
$endgroup$
– connectyourcharger
Jul 6 at 16:04
1
$begingroup$
@connectyourcharger Foreshadowing?
$endgroup$
– negative seven
Jul 6 at 16:05
$begingroup$
@negativeseven Possibly. I have already considered a meta community wiki to index all of the Jimmy posts.
$endgroup$
– connectyourcharger
Jul 6 at 16:07
1
$begingroup$
Nine bytes, and once again, we still find out how someone can die.
$endgroup$
– IMustBeSomeone
Jul 6 at 16:18
1
$begingroup$
"Note that all other characters are [less than '|']
"?
$endgroup$
– Erik the Outgolfer
Jul 6 at 19:06
|
show 1 more comment
$begingroup$
brainfuck, 79 64 bytes
>>+<<,[----------[<]>>[.-]+<[>-]+[---------<-->]<[<]>>[-]<[>]<,]
Try it online!
Outputs the 0x01 byte for truthy and nothing for falsy.
Z: 0
A: input
B: 0
C: has no | been found on this line?
>>+<< initialize C to 1
,[ loop over each char
---------- set A to 0 if input was n
[<]>> move to C if input was n; B otherwise
[ if input was n and C is true
.- output 1
]
+ this will reinitialize C to 1 if input was n
but also clobber B with 1 if it wasn't
now we have 0 0 0 (1) if input was n;
0 _ (1) _ otherwise
<[>-] clear own cell if the one to the left is positive
this yields 0 0 (0) 1 and
0 _ (0) _ as desired
+[---------<-->] set A to 0 if input was |
<[<]>> move to C if input was |; B otherwise
[-] zero out current cell: clears C if input was |
<[>]< realign pointer onto A
,] break on end of input
$endgroup$
add a comment |
$begingroup$
Grime, 5 bytes
o/|
Try it online!
The right tool for the job.
o # match an "o"
/ # above
| # a "|"
$endgroup$
add a comment |
$begingroup$
Stax, 6 bytes
é¿┤4╠q
Run and debug it
Transposes the input, then searches for "o|".
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 8 bytesSBCS
Anonymous tacit prefix function, taking a character matrix as argument.
1∊'o|'⍷⍉
Try it online!
⍉
transpose
'o|'⍷
mask for everywhere o
is immediate followed by |
1∊
is one a member thereof?
$endgroup$
add a comment |
$begingroup$
Dyalog APL Extended, 14 13 11 9 bytes
3∊¯1+/⍤↓<
Try it online!
$endgroup$
$begingroup$
-2:3∊¯1+/⍤↓<
$endgroup$
– Adám
Jul 7 at 1:42
add a comment |
$begingroup$
05AB1E, 5 bytes
Çü%àθ
Try it online!
Ç # convert the input to a 2D array of codepoints
ü% # pairwise modulo (vectorized)
à # maximum (*not* vectorized, returns a single number)
θ # tail (last digit)
The only characters that can appear in the input are o/ |
, with respective
codepoints 92, 111, 47, 32, 124 (there are no newlines, since we chose to take
input as an array of lines). The possible results by moduloing two of these
numbers are 0, 13, 15, 17, 19, 28, 30, 32, 45, 47, 92, 111. 111 is the largest
of those, and also the only one that ends with 1, so the code will output truthy
if and only if 111 is present in the list (only 1 is truthy in 05AB1E). 111
is 111 (o
) % 124 (|
), and so only occurs if there's an o
above a |
in the input.
$endgroup$
1
$begingroup$
Very nice with the pairwise modulo.
$endgroup$
– Kevin Cruijssen
Jul 8 at 13:10
add a comment |
$begingroup$
JavaScript, 39 33 bytes
Thanks @Daniil Tutubalin for golfing off 2 bytes
x=>!!x.match(/^( *)/[^|]*n/m)
This matches any line which is not the line where his left arm shows up and none of the rope shows.
Try it online!
$endgroup$
$begingroup$
It appears to fail if he is at the bottom of the rope
$endgroup$
– fəˈnɛtɪk
Jul 6 at 17:11
$begingroup$
It should fail if he is at the bottom, right? Because Jimmy falls if he is at the bottom fo the rope
$endgroup$
– mprogrammer
Jul 6 at 17:13
$begingroup$
I mean that when I put him at the bottom of the rope your function for some reason returned 1
$endgroup$
– fəˈnɛtɪk
Jul 6 at 17:28
$begingroup$
Hm, nevermind then.
$endgroup$
– mprogrammer
Jul 6 at 17:33
1
$begingroup$
What about/^ *.o. *n/
?
$endgroup$
– tsh
Jul 8 at 2:08
|
show 1 more comment
$begingroup$
///, 53 50 bytes
/~//~//o\/1~1 /1~ 1/1~|1~/1|~/|~/1.~/ ~/.~/
~.
Try it online!
Because there is no other way to take input in ///, it is hard-coded:
/~//~//o\/1~1 /1~ 1/1~|1~/1|~/|~/1.~/ ~/.~/
~<INPUT HERE>.
Explanation:
The general approach is to replace Jimmy with a unary 1, then remove him from all situations where he is in danger. If he survives, he is outputted. If he doesn't, then nothing is. The ~
in the code are a replacement for //
, which allow the code to be shortened by 3 bytes here. They are omitted from the explanation.
////
/////
The top two lines allow me to leave comments without disturbing the code.
//o\/1/ Replace Jimmy with a 1.
/1 /1/ Get rid of any spaces in front of Jimmy. This moves Jimmy towards the rope from the left.
/ 1/1/ Get rid of any spaces after Jimmy. This moves Jimmy towards the rope from the right.
/|1// If Jimmy is touching the rope, remove him and the rope.
/1|// This is based on the observation that in all cases where Jimmy is safe, there is no visible rope on his line.
/|// Remove any remaining rope. If Jimmy was touching a rope, it's already too late for him.
/1.// This handles the case where Jimmy is at the bottom of the rope (hence the period at the end).
/ // The remaining lines clean up the output.
/.//
/
//
||
||
||
/o
||.
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby 2.5.5, 22 bytes
->x/
Expects an array of lines. Requires a minimum of version 2.5.5 because this is when Array#all?(pattern)
was added.
Because of the constraints that the input will always be a valid scene of Jimmy and a rope, it boils down to whether any of the lines prior to the last line have the rope obscured.
$endgroup$
add a comment |
$begingroup$
Kotlin, 93 84 bytes
fun j(a:List<String>)print(a.count")==1&&!a.last().contains("o"))
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript, 38 37 bytes
r=>r.some(x=>!~x.search`\|`,r.pop())
Try it online!
$endgroup$
add a comment |
$begingroup$
Retina, 9 bytes
m`^[^|]+^
Try it online!
Now, I've never programmed in Retina before, but as far as I can tell this works. It is a regular expression that finds a string containing (1) the beginning of the input, (2) no "|" characters, and (3) a newline.
People more familiar with either regular expressions or Retina are encouraged to offer suggestions. -2 bytes thanks to Neil!
$endgroup$
$begingroup$
Two alternatives: 1) Remove then
because a new line is not a|
and so that will match anyway, and the final^
suffices to ensure that you actually matched a newline. 2) Use a pilcrow¶
instead ofn
and remove the trailing^
(because that's always true after a newline in multiline mode).
$endgroup$
– Neil
Jul 6 at 18:05
add a comment |
$begingroup$
Perl 5 -p
, 26 bytes
$||=!/|/;$;=/o/}improve this answer
$begingroup$
Perl 5 -p
, 26 bytes
$/;$;=/o/$&&=!$
Try it online!
answered Jul 7 at 1:56
XcaliXcali
6,3375 silver badges23 bronze badges
6,3375 silver badges23 bronze badges
add a comment |
add a comment |
$begingroup$
Befunge-98 (PyFunge), 26 24 bytes
]~:a-!#v_' `+
^_-3q#$<
@
Try it online!
Exits with return code 3 if n
is encountered and the last line contained 3 non-space characters, otherwise exits with return code 0 on EOF. Thus, this relies on the last line not containing a trailing newline.
Dissected
]~ :a-!#v_ ' `+
Read character, Branch downwards if Increment counter on
branch up (and equal to 10 ('n') the stack if greater
loop around) if than 32 (' ') and
end of stream implicitly loop
^_-3q#$< <
Return with code 3
if counter is equal to 3,
otherwise reset counter
and return to beginning
@
Return with exit
code 0
$endgroup$
add a comment |
$begingroup$
Befunge-98 (PyFunge), 26 24 bytes
]~:a-!#v_' `+
^_-3q#$<
@
Try it online!
Exits with return code 3 if n
is encountered and the last line contained 3 non-space characters, otherwise exits with return code 0 on EOF. Thus, this relies on the last line not containing a trailing newline.
Dissected
]~ :a-!#v_ ' `+
Read character, Branch downwards if Increment counter on
branch up (and equal to 10 ('n') the stack if greater
loop around) if than 32 (' ') and
end of stream implicitly loop
^_-3q#$< <
Return with code 3
if counter is equal to 3,
otherwise reset counter
and return to beginning
@
Return with exit
code 0
$endgroup$
add a comment |
$begingroup$
Befunge-98 (PyFunge), 26 24 bytes
]~:a-!#v_' `+
^_-3q#$<
@
Try it online!
Exits with return code 3 if n
is encountered and the last line contained 3 non-space characters, otherwise exits with return code 0 on EOF. Thus, this relies on the last line not containing a trailing newline.
Dissected
]~ :a-!#v_ ' `+
Read character, Branch downwards if Increment counter on
branch up (and equal to 10 ('n') the stack if greater
loop around) if than 32 (' ') and
end of stream implicitly loop
^_-3q#$< <
Return with code 3
if counter is equal to 3,
otherwise reset counter
and return to beginning
@
Return with exit
code 0
$endgroup$
Befunge-98 (PyFunge), 26 24 bytes
]~:a-!#v_' `+
^_-3q#$<
@
Try it online!
Exits with return code 3 if n
is encountered and the last line contained 3 non-space characters, otherwise exits with return code 0 on EOF. Thus, this relies on the last line not containing a trailing newline.
Dissected
]~ :a-!#v_ ' `+
Read character, Branch downwards if Increment counter on
branch up (and equal to 10 ('n') the stack if greater
loop around) if than 32 (' ') and
end of stream implicitly loop
^_-3q#$< <
Return with code 3
if counter is equal to 3,
otherwise reset counter
and return to beginning
@
Return with exit
code 0
edited Jul 7 at 10:15
answered Jul 6 at 17:52
negative sevennegative seven
1,0153 silver badges11 bronze badges
1,0153 silver badges11 bronze badges
add a comment |
add a comment |
$begingroup$
05AB1E (legacy), 6 bytes
ζJ„o|å
Port of @Shaggy's Japt answer.
Input as a list of lines.
Try it online.
Explanation:
ζ # Zip/transpose the (implicit) strings in the input-list, with space as filler
# (NOTE: zip/transpose doesn't work on string-list in the new version of 05AB1E,
# which is why we use the legacy version)
J # Join these zipped/transposed lines together to a single string
„o|å # And check if it contains the string "o|"
# (after which the result is output implicitly)
$endgroup$
1
$begingroup$
5 bytes on non-legacy
$endgroup$
– Grimy
Jul 8 at 13:06
add a comment |
$begingroup$
05AB1E (legacy), 6 bytes
ζJ„o|å
Port of @Shaggy's Japt answer.
Input as a list of lines.
Try it online.
Explanation:
ζ # Zip/transpose the (implicit) strings in the input-list, with space as filler
# (NOTE: zip/transpose doesn't work on string-list in the new version of 05AB1E,
# which is why we use the legacy version)
J # Join these zipped/transposed lines together to a single string
„o|å # And check if it contains the string "o|"
# (after which the result is output implicitly)
$endgroup$
1
$begingroup$
5 bytes on non-legacy
$endgroup$
– Grimy
Jul 8 at 13:06
add a comment |
$begingroup$
05AB1E (legacy), 6 bytes
ζJ„o|å
Port of @Shaggy's Japt answer.
Input as a list of lines.
Try it online.
Explanation:
ζ # Zip/transpose the (implicit) strings in the input-list, with space as filler
# (NOTE: zip/transpose doesn't work on string-list in the new version of 05AB1E,
# which is why we use the legacy version)
J # Join these zipped/transposed lines together to a single string
„o|å # And check if it contains the string "o|"
# (after which the result is output implicitly)
$endgroup$
05AB1E (legacy), 6 bytes
ζJ„o|å
Port of @Shaggy's Japt answer.
Input as a list of lines.
Try it online.
Explanation:
ζ # Zip/transpose the (implicit) strings in the input-list, with space as filler
# (NOTE: zip/transpose doesn't work on string-list in the new version of 05AB1E,
# which is why we use the legacy version)
J # Join these zipped/transposed lines together to a single string
„o|å # And check if it contains the string "o|"
# (after which the result is output implicitly)
answered Jul 8 at 7:56
Kevin CruijssenKevin Cruijssen
47.9k7 gold badges82 silver badges241 bronze badges
47.9k7 gold badges82 silver badges241 bronze badges
1
$begingroup$
5 bytes on non-legacy
$endgroup$
– Grimy
Jul 8 at 13:06
add a comment |
1
$begingroup$
5 bytes on non-legacy
$endgroup$
– Grimy
Jul 8 at 13:06
1
1
$begingroup$
5 bytes on non-legacy
$endgroup$
– Grimy
Jul 8 at 13:06
$begingroup$
5 bytes on non-legacy
$endgroup$
– Grimy
Jul 8 at 13:06
add a comment |
$begingroup$
Elm 0.19, 68 bytes
f r=List.any(not<<String.contains"|")(List.take((List.length r)-1)r)
Takes input as a list of lines. Disregarding the last line, it checks whether there are any with no '|'
in them – implying the rope is fully covered by Jimmy.
Verify all test cases here.
$endgroup$
add a comment |
$begingroup$
Elm 0.19, 68 bytes
f r=List.any(not<<String.contains"|")(List.take((List.length r)-1)r)
Takes input as a list of lines. Disregarding the last line, it checks whether there are any with no '|'
in them – implying the rope is fully covered by Jimmy.
Verify all test cases here.
$endgroup$
add a comment |
$begingroup$
Elm 0.19, 68 bytes
f r=List.any(not<<String.contains"|")(List.take((List.length r)-1)r)
Takes input as a list of lines. Disregarding the last line, it checks whether there are any with no '|'
in them – implying the rope is fully covered by Jimmy.
Verify all test cases here.
$endgroup$
Elm 0.19, 68 bytes
f r=List.any(not<<String.contains"|")(List.take((List.length r)-1)r)
Takes input as a list of lines. Disregarding the last line, it checks whether there are any with no '|'
in them – implying the rope is fully covered by Jimmy.
Verify all test cases here.
answered Jul 8 at 11:49
O.O.BalanceO.O.Balance
1,4681 gold badge4 silver badges18 bronze badges
1,4681 gold badge4 silver badges18 bronze badges
add a comment |
add a comment |
$begingroup$
PowerShell, 26 bytes
Port of Maxwell's answer for Retina.
"$args"-match'(?m)^[^|]+^'
Try it online!
Explanation:
true
if:
- there is a line in a scene that does not contain the character
|
- and after this line there is a start of a new line.
false
otherwise.
$endgroup$
add a comment |
$begingroup$
PowerShell, 26 bytes
Port of Maxwell's answer for Retina.
"$args"-match'(?m)^[^|]+^'
Try it online!
Explanation:
true
if:
- there is a line in a scene that does not contain the character
|
- and after this line there is a start of a new line.
false
otherwise.
$endgroup$
add a comment |
$begingroup$
PowerShell, 26 bytes
Port of Maxwell's answer for Retina.
"$args"-match'(?m)^[^|]+^'
Try it online!
Explanation:
true
if:
- there is a line in a scene that does not contain the character
|
- and after this line there is a start of a new line.
false
otherwise.
$endgroup$
PowerShell, 26 bytes
Port of Maxwell's answer for Retina.
"$args"-match'(?m)^[^|]+^'
Try it online!
Explanation:
true
if:
- there is a line in a scene that does not contain the character
|
- and after this line there is a start of a new line.
false
otherwise.
edited Jul 8 at 12:58
answered Jul 8 at 12:51
mazzymazzy
3,5961 gold badge4 silver badges19 bronze badges
3,5961 gold badge4 silver badges19 bronze badges
add a comment |
add a comment |
$begingroup$
Pyth, 9 bytes
sPm!sqR|
Test suite!
$endgroup$
add a comment |
$begingroup$
Pyth, 9 bytes
sPm!sqR|
Test suite!
$endgroup$
add a comment |
$begingroup$
Pyth, 9 bytes
sPm!sqR|
Test suite!
$endgroup$
Pyth, 9 bytes
sPm!sqR|
Test suite!
answered Jul 6 at 18:10
Mr. XcoderMr. Xcoder
32.7k7 gold badges61 silver badges202 bronze badges
32.7k7 gold badges61 silver badges202 bronze badges
add a comment |
add a comment |
$begingroup$
Pyret, 79 bytes
(l):all2((r,n):string-char-at(n,string-index-of(r,"o") == ",l,link(0,l))
Expects an array of lines as strings. Makes a copy in link(0,l)
where all rows shifted down by one. Goes through each row r
and n
where n is the row below r. Checks that if Jimmy's body "o"
is at some position, then the row below it has a pipe there (i.e. Jimmy's hanging on the rope and isn't at the bottom).
New contributor
$endgroup$
add a comment |
$begingroup$
Pyret, 79 bytes
(l):all2((r,n):string-char-at(n,string-index-of(r,"o") == ",l,link(0,l))
Expects an array of lines as strings. Makes a copy in link(0,l)
where all rows shifted down by one. Goes through each row r
and n
where n is the row below r. Checks that if Jimmy's body "o"
is at some position, then the row below it has a pipe there (i.e. Jimmy's hanging on the rope and isn't at the bottom).
New contributor
$endgroup$
add a comment |
$begingroup$
Pyret, 79 bytes
(l):all2((r,n):string-char-at(n,string-index-of(r,"o") == ",l,link(0,l))
Expects an array of lines as strings. Makes a copy in link(0,l)
where all rows shifted down by one. Goes through each row r
and n
where n is the row below r. Checks that if Jimmy's body "o"
is at some position, then the row below it has a pipe there (i.e. Jimmy's hanging on the rope and isn't at the bottom).
New contributor
$endgroup$
Pyret, 79 bytes
(l):all2((r,n):string-char-at(n,string-index-of(r,"o") == ",l,link(0,l))
Expects an array of lines as strings. Makes a copy in link(0,l)
where all rows shifted down by one. Goes through each row r
and n
where n is the row below r. Checks that if Jimmy's body "o"
is at some position, then the row below it has a pipe there (i.e. Jimmy's hanging on the rope and isn't at the bottom).
New contributor
New contributor
answered Jul 11 at 2:35
MLavrentyevMLavrentyev
1716 bronze badges
1716 bronze badges
New contributor
New contributor
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%2f187759%2fcan-jimmy-hang-on-his-rope%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
1
$begingroup$
Is the rope always going to have the same number of spaces before it, or can that vary?
$endgroup$
– mprogrammer
Jul 6 at 15:53
$begingroup$
@Maxwell That can vary.
$endgroup$
– connectyourcharger
Jul 6 at 15:58
$begingroup$
Can we take the input as something like a list, where each line is a separate string, or does it have to be one single string?
$endgroup$
– mprogrammer
Jul 6 at 16:02
18
$begingroup$
Jimmy should really take a holiday
$endgroup$
– Luis Mendo
Jul 6 at 16:20
6
$begingroup$
@LuisMendo Jimmy is dedicated to what he does!
$endgroup$
– connectyourcharger
Jul 6 at 16:25