$begingroup$
Write a program that takes a single line string that you can assume will only contain the characters /_‾
. (That's forward and backward slash, underline and overline. You can use ~
in place of overline if you need since overline is not convenient ASCII.)
For example, one possible input is:
__/‾‾/_/‾
Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.
The output for the above example would be true because the edges are connected:
To be clear on the connections:
/
connects on its bottom left and top rightconnects on its top left and bottom right
_
connects on its bottom left and bottom right‾
(or~
) connects on its top left and top right
Also:
It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.
You can assume the input string is non-empty, and of course just one line.
Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:
__/‾‾/_/‾
1
_
1
1
/
1
‾
1
___
1
/
1
//
1
//
1
‾‾‾
1
\
0
‾‾
1
_‾
0
‾_
0
_____/
1
/\/\___
0
/__/‾‾
1
______/_____
1
‾‾‾‾‾‾\_____
0
‾‾‾‾‾‾______
1
_____/‾‾‾‾‾
1
___/‾‾‾___/‾‾‾
1
_/__
0
_/_
1
////////////
1
____________________
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/
0
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
/‾/‾___/|_|/__/‾‾
0
The shortest code is the winner.
code-golf string decision-problem
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
Write a program that takes a single line string that you can assume will only contain the characters /_‾
. (That's forward and backward slash, underline and overline. You can use ~
in place of overline if you need since overline is not convenient ASCII.)
For example, one possible input is:
__/‾‾/_/‾
Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.
The output for the above example would be true because the edges are connected:
To be clear on the connections:
/
connects on its bottom left and top rightconnects on its top left and bottom right
_
connects on its bottom left and bottom right‾
(or~
) connects on its top left and top right
Also:
It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.
You can assume the input string is non-empty, and of course just one line.
Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:
__/‾‾/_/‾
1
_
1
1
/
1
‾
1
___
1
/
1
//
1
//
1
‾‾‾
1
\
0
‾‾
1
_‾
0
‾_
0
_____/
1
/\/\___
0
/__/‾‾
1
______/_____
1
‾‾‾‾‾‾\_____
0
‾‾‾‾‾‾______
1
_____/‾‾‾‾‾
1
___/‾‾‾___/‾‾‾
1
_/__
0
_/_
1
////////////
1
____________________
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/
0
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
/‾/‾___/|_|/__/‾‾
0
The shortest code is the winner.
code-golf string decision-problem
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
4
$begingroup$
Welcome to PPCG! Nice first challenge.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
Are the characters specified in your challenge the only ones that will appear in the string?
$endgroup$
– Embodiment of Ignorance
1 hour ago
$begingroup$
@EmbodimentofIgnorance Yes, only the 4.
$endgroup$
– Discrete Games
1 hour ago
add a comment |
$begingroup$
Write a program that takes a single line string that you can assume will only contain the characters /_‾
. (That's forward and backward slash, underline and overline. You can use ~
in place of overline if you need since overline is not convenient ASCII.)
For example, one possible input is:
__/‾‾/_/‾
Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.
The output for the above example would be true because the edges are connected:
To be clear on the connections:
/
connects on its bottom left and top rightconnects on its top left and bottom right
_
connects on its bottom left and bottom right‾
(or~
) connects on its top left and top right
Also:
It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.
You can assume the input string is non-empty, and of course just one line.
Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:
__/‾‾/_/‾
1
_
1
1
/
1
‾
1
___
1
/
1
//
1
//
1
‾‾‾
1
\
0
‾‾
1
_‾
0
‾_
0
_____/
1
/\/\___
0
/__/‾‾
1
______/_____
1
‾‾‾‾‾‾\_____
0
‾‾‾‾‾‾______
1
_____/‾‾‾‾‾
1
___/‾‾‾___/‾‾‾
1
_/__
0
_/_
1
////////////
1
____________________
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/
0
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
/‾/‾___/|_|/__/‾‾
0
The shortest code is the winner.
code-golf string decision-problem
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
Write a program that takes a single line string that you can assume will only contain the characters /_‾
. (That's forward and backward slash, underline and overline. You can use ~
in place of overline if you need since overline is not convenient ASCII.)
For example, one possible input is:
__/‾‾/_/‾
Your program needs to output a truthy or falsy value depending on whether the left edge of the string is "connected", so to speak, to the right edge of the string via the lines of the characters. So, if the kerning was a bit less, there would be a solid black (albeit kinky) line all the way from the left edge to the right, like an unbroken piece of string or twine.
The output for the above example would be true because the edges are connected:
To be clear on the connections:
/
connects on its bottom left and top rightconnects on its top left and bottom right
_
connects on its bottom left and bottom right‾
(or~
) connects on its top left and top right
Also:
It doesn't matter whether the edges of the string started on the top or the bottom, it only matters that they connect horizontally through the whole length of the string.
You can assume the input string is non-empty, and of course just one line.
Here are some more examples followed by 1 (truthy) if they are connected or 0 (falsy) if not:
__/‾‾/_/‾
1
_
1
1
/
1
‾
1
___
1
/
1
//
1
//
1
‾‾‾
1
\
0
‾‾
1
_‾
0
‾_
0
_____/
1
/\/\___
0
/__/‾‾
1
______/_____
1
‾‾‾‾‾‾\_____
0
‾‾‾‾‾‾______
1
_____/‾‾‾‾‾
1
___/‾‾‾___/‾‾‾
1
_/__
0
_/_
1
////////////
1
____________________
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾/
0
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1
/‾/‾___/|_|/__/‾‾
0
The shortest code is the winner.
code-golf string decision-problem
code-golf string decision-problem
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago


Discrete GamesDiscrete Games
963
963
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Discrete Games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
$begingroup$
Welcome to PPCG! Nice first challenge.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
Are the characters specified in your challenge the only ones that will appear in the string?
$endgroup$
– Embodiment of Ignorance
1 hour ago
$begingroup$
@EmbodimentofIgnorance Yes, only the 4.
$endgroup$
– Discrete Games
1 hour ago
add a comment |
4
$begingroup$
Welcome to PPCG! Nice first challenge.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
Are the characters specified in your challenge the only ones that will appear in the string?
$endgroup$
– Embodiment of Ignorance
1 hour ago
$begingroup$
@EmbodimentofIgnorance Yes, only the 4.
$endgroup$
– Discrete Games
1 hour ago
4
4
$begingroup$
Welcome to PPCG! Nice first challenge.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
Welcome to PPCG! Nice first challenge.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
Are the characters specified in your challenge the only ones that will appear in the string?
$endgroup$
– Embodiment of Ignorance
1 hour ago
$begingroup$
Are the characters specified in your challenge the only ones that will appear in the string?
$endgroup$
– Embodiment of Ignorance
1 hour ago
$begingroup$
@EmbodimentofIgnorance Yes, only the 4.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
@EmbodimentofIgnorance Yes, only the 4.
$endgroup$
– Discrete Games
1 hour ago
add a comment |
8 Answers
8
active
oldest
votes
$begingroup$
Ruby -n, 30 bytes
p !/[_\][\‾]|[/‾][_/]/
Try it online!
Reduces all of the string-breaking sequences to two cases using Regex character classes.
$endgroup$
2
$begingroup$
You can save 4 bytes by using~
instead of‾
. I'm not sure if it matters for this challenge, since the character count is the same.
$endgroup$
– iamnotmaynard
36 mins ago
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
The naive way.
s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)
Try it online!
$endgroup$
$begingroup$
So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
@DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)
$endgroup$
– Arnauld
1 hour ago
add a comment |
$begingroup$
Python 3, 126 bytes
lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])
$endgroup$
add a comment |
$begingroup$
C (gcc), 93 bytes
w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 29 bytes
„_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_
It sounded shorter in my head.. Will try to golf it down from here.
Try it online or verify all test cases.
Explanation:"
„_~S # Push the characters ["_","~"]
D2× # Duplicate it, and increase each to size 2: ["__","~~"]
s: # Swap and replace all "__" with "_" and all "~~" with "~"
# in the (implicit) input-string
Ç # Convert the remaining characters to unicode values
ü- # Calculate the difference between each pair
т+ # Add 100 to each
•6_üê{↕ # Push compressed integer 1781179816800959
ƵΔ # Push compressed integer 180
в # Convert the larger integer to Base-180 as list:
# [52,66,69,100,103,131,179]
å # Check for each if it's in the difference-list
# (1 if present; 0 if not)
O # Sum the truthy values
_ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)
# (and output this result implicitly)
See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕
is 1781179816800959
, ƵΔ
is 180
and •6_üê{↕ƵΔв
is [52,66,69,100,103,131,179]
.
Additional explanation:
There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]
; ["~", 66]
, ["_~", 69]
, ["//", 100]
, ["\", 100]
, ["_", 103]
, ["~_", 131]
, ["~/", 179]
, which is why I have the compressed integer list in my code containing these values.
Since __
and ~~
will just like //
and \
result in 0
(or 100
after I add 100), I first remove any adjacent duplicates of ~
and _
in the input-string, before calculating and verifying the pair-differences.
$endgroup$
add a comment |
$begingroup$
Python 3, 80 78 bytes
I don't realy do many python code golfs but I thought I could give it a try
- -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string
def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))
Try it online!
Python 3.8 (pre-release), 71 bytes
I wanted to try out the new :=
expression assignment
lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 14 bytes
Supports (and expects) the ‾
character in the input string. Returns $0$ or $1$.
O*Ɲ×12%29%15ḂẠ
Try it online!
O*Ɲ×12%29%15ḂẠ - main link, taking a string e.g. "_/"
O - get ASCII codes --> [92, 95, 47]
*Ɲ - exponentiation on all pairs --> [92**95, 95**97]
×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]
%29 - modulo 29 --> [11, 24]
%15 - modulo 15 --> [11, 9]
Ḃ - least significant bit (i.e. parity) --> [1, 1]
Ạ - all values equal to 1? --> 1
$endgroup$
add a comment |
$begingroup$
Dart, 94 bytes
f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));
Try it online!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
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
});
}
});
Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.
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%2f181708%2fwould-this-string-work-as-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Ruby -n, 30 bytes
p !/[_\][\‾]|[/‾][_/]/
Try it online!
Reduces all of the string-breaking sequences to two cases using Regex character classes.
$endgroup$
2
$begingroup$
You can save 4 bytes by using~
instead of‾
. I'm not sure if it matters for this challenge, since the character count is the same.
$endgroup$
– iamnotmaynard
36 mins ago
add a comment |
$begingroup$
Ruby -n, 30 bytes
p !/[_\][\‾]|[/‾][_/]/
Try it online!
Reduces all of the string-breaking sequences to two cases using Regex character classes.
$endgroup$
2
$begingroup$
You can save 4 bytes by using~
instead of‾
. I'm not sure if it matters for this challenge, since the character count is the same.
$endgroup$
– iamnotmaynard
36 mins ago
add a comment |
$begingroup$
Ruby -n, 30 bytes
p !/[_\][\‾]|[/‾][_/]/
Try it online!
Reduces all of the string-breaking sequences to two cases using Regex character classes.
$endgroup$
Ruby -n, 30 bytes
p !/[_\][\‾]|[/‾][_/]/
Try it online!
Reduces all of the string-breaking sequences to two cases using Regex character classes.
answered 1 hour ago


histocrathistocrat
19.1k43172
19.1k43172
2
$begingroup$
You can save 4 bytes by using~
instead of‾
. I'm not sure if it matters for this challenge, since the character count is the same.
$endgroup$
– iamnotmaynard
36 mins ago
add a comment |
2
$begingroup$
You can save 4 bytes by using~
instead of‾
. I'm not sure if it matters for this challenge, since the character count is the same.
$endgroup$
– iamnotmaynard
36 mins ago
2
2
$begingroup$
You can save 4 bytes by using
~
instead of ‾
. I'm not sure if it matters for this challenge, since the character count is the same.$endgroup$
– iamnotmaynard
36 mins ago
$begingroup$
You can save 4 bytes by using
~
instead of ‾
. I'm not sure if it matters for this challenge, since the character count is the same.$endgroup$
– iamnotmaynard
36 mins ago
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
The naive way.
s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)
Try it online!
$endgroup$
$begingroup$
So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
@DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)
$endgroup$
– Arnauld
1 hour ago
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
The naive way.
s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)
Try it online!
$endgroup$
$begingroup$
So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
@DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)
$endgroup$
– Arnauld
1 hour ago
add a comment |
$begingroup$
JavaScript (ES6), 45 bytes
The naive way.
s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)
Try it online!
$endgroup$
JavaScript (ES6), 45 bytes
The naive way.
s=>!///|\\|_~|~_|~/|_\|/_|\~/.test(s)
Try it online!
edited 1 hour ago
answered 1 hour ago


ArnauldArnauld
78.9k795327
78.9k795327
$begingroup$
So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
@DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)
$endgroup$
– Arnauld
1 hour ago
add a comment |
$begingroup$
So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
@DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)
$endgroup$
– Arnauld
1 hour ago
$begingroup$
So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
So this is checking all the invalid pairings, making sure they don't exist in the string? Smart.
$endgroup$
– Discrete Games
1 hour ago
$begingroup$
@DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)
$endgroup$
– Arnauld
1 hour ago
$begingroup$
@DiscreteGames Yes, exactly. (Except that I forgot 2 of them. Now fixed.)
$endgroup$
– Arnauld
1 hour ago
add a comment |
$begingroup$
Python 3, 126 bytes
lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])
$endgroup$
add a comment |
$begingroup$
Python 3, 126 bytes
lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])
$endgroup$
add a comment |
$begingroup$
Python 3, 126 bytes
lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])
$endgroup$
Python 3, 126 bytes
lambda s,d={'‾':'‾','_':'/_','/':'‾','\':'/_'}:len(s)<2or all([s[i+1] in d[s[i]]for i in range(len(s)-1)if s[i]in d])
answered 1 hour ago


Henry THenry T
1716
1716
add a comment |
add a comment |
$begingroup$
C (gcc), 93 bytes
w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 93 bytes
w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}
Try it online!
$endgroup$
add a comment |
$begingroup$
C (gcc), 93 bytes
w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}
Try it online!
$endgroup$
C (gcc), 93 bytes
w,o,r;k(char*_){for(r=0;w=*_,o=*++_;)r|=w-126&&w>47?w-95&&w-92?0:o>47&&o-95:o-92&&o<126;_=r;}
Try it online!
answered 1 hour ago


Jonathan FrechJonathan Frech
6,41311040
6,41311040
add a comment |
add a comment |
$begingroup$
05AB1E, 29 bytes
„_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_
It sounded shorter in my head.. Will try to golf it down from here.
Try it online or verify all test cases.
Explanation:"
„_~S # Push the characters ["_","~"]
D2× # Duplicate it, and increase each to size 2: ["__","~~"]
s: # Swap and replace all "__" with "_" and all "~~" with "~"
# in the (implicit) input-string
Ç # Convert the remaining characters to unicode values
ü- # Calculate the difference between each pair
т+ # Add 100 to each
•6_üê{↕ # Push compressed integer 1781179816800959
ƵΔ # Push compressed integer 180
в # Convert the larger integer to Base-180 as list:
# [52,66,69,100,103,131,179]
å # Check for each if it's in the difference-list
# (1 if present; 0 if not)
O # Sum the truthy values
_ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)
# (and output this result implicitly)
See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕
is 1781179816800959
, ƵΔ
is 180
and •6_üê{↕ƵΔв
is [52,66,69,100,103,131,179]
.
Additional explanation:
There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]
; ["~", 66]
, ["_~", 69]
, ["//", 100]
, ["\", 100]
, ["_", 103]
, ["~_", 131]
, ["~/", 179]
, which is why I have the compressed integer list in my code containing these values.
Since __
and ~~
will just like //
and \
result in 0
(or 100
after I add 100), I first remove any adjacent duplicates of ~
and _
in the input-string, before calculating and verifying the pair-differences.
$endgroup$
add a comment |
$begingroup$
05AB1E, 29 bytes
„_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_
It sounded shorter in my head.. Will try to golf it down from here.
Try it online or verify all test cases.
Explanation:"
„_~S # Push the characters ["_","~"]
D2× # Duplicate it, and increase each to size 2: ["__","~~"]
s: # Swap and replace all "__" with "_" and all "~~" with "~"
# in the (implicit) input-string
Ç # Convert the remaining characters to unicode values
ü- # Calculate the difference between each pair
т+ # Add 100 to each
•6_üê{↕ # Push compressed integer 1781179816800959
ƵΔ # Push compressed integer 180
в # Convert the larger integer to Base-180 as list:
# [52,66,69,100,103,131,179]
å # Check for each if it's in the difference-list
# (1 if present; 0 if not)
O # Sum the truthy values
_ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)
# (and output this result implicitly)
See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕
is 1781179816800959
, ƵΔ
is 180
and •6_üê{↕ƵΔв
is [52,66,69,100,103,131,179]
.
Additional explanation:
There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]
; ["~", 66]
, ["_~", 69]
, ["//", 100]
, ["\", 100]
, ["_", 103]
, ["~_", 131]
, ["~/", 179]
, which is why I have the compressed integer list in my code containing these values.
Since __
and ~~
will just like //
and \
result in 0
(or 100
after I add 100), I first remove any adjacent duplicates of ~
and _
in the input-string, before calculating and verifying the pair-differences.
$endgroup$
add a comment |
$begingroup$
05AB1E, 29 bytes
„_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_
It sounded shorter in my head.. Will try to golf it down from here.
Try it online or verify all test cases.
Explanation:"
„_~S # Push the characters ["_","~"]
D2× # Duplicate it, and increase each to size 2: ["__","~~"]
s: # Swap and replace all "__" with "_" and all "~~" with "~"
# in the (implicit) input-string
Ç # Convert the remaining characters to unicode values
ü- # Calculate the difference between each pair
т+ # Add 100 to each
•6_üê{↕ # Push compressed integer 1781179816800959
ƵΔ # Push compressed integer 180
в # Convert the larger integer to Base-180 as list:
# [52,66,69,100,103,131,179]
å # Check for each if it's in the difference-list
# (1 if present; 0 if not)
O # Sum the truthy values
_ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)
# (and output this result implicitly)
See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕
is 1781179816800959
, ƵΔ
is 180
and •6_üê{↕ƵΔв
is [52,66,69,100,103,131,179]
.
Additional explanation:
There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]
; ["~", 66]
, ["_~", 69]
, ["//", 100]
, ["\", 100]
, ["_", 103]
, ["~_", 131]
, ["~/", 179]
, which is why I have the compressed integer list in my code containing these values.
Since __
and ~~
will just like //
and \
result in 0
(or 100
after I add 100), I first remove any adjacent duplicates of ~
and _
in the input-string, before calculating and verifying the pair-differences.
$endgroup$
05AB1E, 29 bytes
„_~SD2×s:Çü-т+•6_üê{↕ƵΔвåO_
It sounded shorter in my head.. Will try to golf it down from here.
Try it online or verify all test cases.
Explanation:"
„_~S # Push the characters ["_","~"]
D2× # Duplicate it, and increase each to size 2: ["__","~~"]
s: # Swap and replace all "__" with "_" and all "~~" with "~"
# in the (implicit) input-string
Ç # Convert the remaining characters to unicode values
ü- # Calculate the difference between each pair
т+ # Add 100 to each
•6_üê{↕ # Push compressed integer 1781179816800959
ƵΔ # Push compressed integer 180
в # Convert the larger integer to Base-180 as list:
# [52,66,69,100,103,131,179]
å # Check for each if it's in the difference-list
# (1 if present; 0 if not)
O # Sum the truthy values
_ # Check if this sum is exactly 0 (1 if 0; 0 otherwise)
# (and output this result implicitly)
See this 05AB1E tip of mine (sections How to comrpess large integers? and How to compress integer lists?) to understand why •6_üê{↕
is 1781179816800959
, ƵΔ
is 180
and •6_üê{↕ƵΔв
is [52,66,69,100,103,131,179]
.
Additional explanation:
There are 16 ($2^4$) possible pairs of characters we have to verify. If we convert each character to its unicode value, and calculate the differences, we would get these differences. Because compressed integer lists in 05AB1E has to have positive integers only, I add 100 to each. The invalid pairs and their corresponding values are then: ["/_", 52]
; ["~", 66]
, ["_~", 69]
, ["//", 100]
, ["\", 100]
, ["_", 103]
, ["~_", 131]
, ["~/", 179]
, which is why I have the compressed integer list in my code containing these values.
Since __
and ~~
will just like //
and \
result in 0
(or 100
after I add 100), I first remove any adjacent duplicates of ~
and _
in the input-string, before calculating and verifying the pair-differences.
edited 35 mins ago
answered 58 mins ago


Kevin CruijssenKevin Cruijssen
40.7k566210
40.7k566210
add a comment |
add a comment |
$begingroup$
Python 3, 80 78 bytes
I don't realy do many python code golfs but I thought I could give it a try
- -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string
def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))
Try it online!
Python 3.8 (pre-release), 71 bytes
I wanted to try out the new :=
expression assignment
lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 3, 80 78 bytes
I don't realy do many python code golfs but I thought I could give it a try
- -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string
def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))
Try it online!
Python 3.8 (pre-release), 71 bytes
I wanted to try out the new :=
expression assignment
lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 3, 80 78 bytes
I don't realy do many python code golfs but I thought I could give it a try
- -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string
def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))
Try it online!
Python 3.8 (pre-release), 71 bytes
I wanted to try out the new :=
expression assignment
lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))
Try it online!
$endgroup$
Python 3, 80 78 bytes
I don't realy do many python code golfs but I thought I could give it a try
- -2 bytes: realised not(any()) is the same as all(not()) and could move the not into the r-string
def f(x):*l,=map(r'_/~'.find,x);return 1-any((i^j//2)%2for i,j in zip(l,l[1:]))
Try it online!
Python 3.8 (pre-release), 71 bytes
I wanted to try out the new :=
expression assignment
lambda x:all((i^j//2)%2for i,j in zip(l:=[*map(r'~_/'.find,x)],l[1:]))
Try it online!
edited 21 mins ago
answered 32 mins ago


KroppebKroppeb
1,306210
1,306210
add a comment |
add a comment |
$begingroup$
Jelly, 14 bytes
Supports (and expects) the ‾
character in the input string. Returns $0$ or $1$.
O*Ɲ×12%29%15ḂẠ
Try it online!
O*Ɲ×12%29%15ḂẠ - main link, taking a string e.g. "_/"
O - get ASCII codes --> [92, 95, 47]
*Ɲ - exponentiation on all pairs --> [92**95, 95**97]
×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]
%29 - modulo 29 --> [11, 24]
%15 - modulo 15 --> [11, 9]
Ḃ - least significant bit (i.e. parity) --> [1, 1]
Ạ - all values equal to 1? --> 1
$endgroup$
add a comment |
$begingroup$
Jelly, 14 bytes
Supports (and expects) the ‾
character in the input string. Returns $0$ or $1$.
O*Ɲ×12%29%15ḂẠ
Try it online!
O*Ɲ×12%29%15ḂẠ - main link, taking a string e.g. "_/"
O - get ASCII codes --> [92, 95, 47]
*Ɲ - exponentiation on all pairs --> [92**95, 95**97]
×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]
%29 - modulo 29 --> [11, 24]
%15 - modulo 15 --> [11, 9]
Ḃ - least significant bit (i.e. parity) --> [1, 1]
Ạ - all values equal to 1? --> 1
$endgroup$
add a comment |
$begingroup$
Jelly, 14 bytes
Supports (and expects) the ‾
character in the input string. Returns $0$ or $1$.
O*Ɲ×12%29%15ḂẠ
Try it online!
O*Ɲ×12%29%15ḂẠ - main link, taking a string e.g. "_/"
O - get ASCII codes --> [92, 95, 47]
*Ɲ - exponentiation on all pairs --> [92**95, 95**97]
×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]
%29 - modulo 29 --> [11, 24]
%15 - modulo 15 --> [11, 9]
Ḃ - least significant bit (i.e. parity) --> [1, 1]
Ạ - all values equal to 1? --> 1
$endgroup$
Jelly, 14 bytes
Supports (and expects) the ‾
character in the input string. Returns $0$ or $1$.
O*Ɲ×12%29%15ḂẠ
Try it online!
O*Ɲ×12%29%15ḂẠ - main link, taking a string e.g. "_/"
O - get ASCII codes --> [92, 95, 47]
*Ɲ - exponentiation on all pairs --> [92**95, 95**97]
×12 - multiply by 12 --> [(92**95)*12, (95**97)*12]
%29 - modulo 29 --> [11, 24]
%15 - modulo 15 --> [11, 9]
Ḃ - least significant bit (i.e. parity) --> [1, 1]
Ạ - all values equal to 1? --> 1
edited 8 mins ago
answered 25 mins ago


ArnauldArnauld
78.9k795327
78.9k795327
add a comment |
add a comment |
$begingroup$
Dart, 94 bytes
f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));
Try it online!
$endgroup$
add a comment |
$begingroup$
Dart, 94 bytes
f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));
Try it online!
$endgroup$
add a comment |
$begingroup$
Dart, 94 bytes
f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));
Try it online!
$endgroup$
Dart, 94 bytes
f(s)=>!(r'//,\,~/,_,~_,_~,/_,~'.split(',').map((t)=>s.contains(t)).fold(false,(p,e)=>p|e));
Try it online!
answered 21 mins ago
ElcanElcan
32115
32115
add a comment |
add a comment |
Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.
Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.
Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.
Discrete Games is a new contributor. Be nice, and check out our Code of Conduct.
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%2f181708%2fwould-this-string-work-as-string%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
4
$begingroup$
Welcome to PPCG! Nice first challenge.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
Are the characters specified in your challenge the only ones that will appear in the string?
$endgroup$
– Embodiment of Ignorance
1 hour ago
$begingroup$
@EmbodimentofIgnorance Yes, only the 4.
$endgroup$
– Discrete Games
1 hour ago