An ogl-edocf challenge
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
Input
A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.
Output
The output is obtained by applying successive rotations to the input string.
For each letter ([a-zA-Z]
) in the input string, going from left to right:
- if the letter is in upper case, rotate all characters before it by one position to the left
- if the letter is in lower case, rotate all characters before it by one position to the right
Example
Input: "Cb-Ad"
- The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.
- The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.
- The character "-" does not trigger any rotation, as it's not a letter.
- The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"
- The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"
Therefore, the expected output is "Ab-Cd".
Rules
- You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.
- You may also output an array of characters instead of a string.
- This is
ogl-edocfcode-golf
Test cases
"cbad" -> "abcd"
"ACBD" -> "ABCD"
"Cb-Ad" -> "Ab-Cd"
"caeBDF" -> "aBcDeF"
"aEcbDF" -> "abcDEF"
"ogl-edocf" -> "code-golf"
"W o,ollelrHd!" -> "Hello, World!"
"ti HIs SSta ET!" -> "tHis IS a tEST!"
code-golf string
add a comment |Â
up vote
7
down vote
favorite
Input
A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.
Output
The output is obtained by applying successive rotations to the input string.
For each letter ([a-zA-Z]
) in the input string, going from left to right:
- if the letter is in upper case, rotate all characters before it by one position to the left
- if the letter is in lower case, rotate all characters before it by one position to the right
Example
Input: "Cb-Ad"
- The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.
- The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.
- The character "-" does not trigger any rotation, as it's not a letter.
- The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"
- The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"
Therefore, the expected output is "Ab-Cd".
Rules
- You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.
- You may also output an array of characters instead of a string.
- This is
ogl-edocfcode-golf
Test cases
"cbad" -> "abcd"
"ACBD" -> "ABCD"
"Cb-Ad" -> "Ab-Cd"
"caeBDF" -> "aBcDeF"
"aEcbDF" -> "abcDEF"
"ogl-edocf" -> "code-golf"
"W o,ollelrHd!" -> "Hello, World!"
"ti HIs SSta ET!" -> "tHis IS a tEST!"
code-golf string
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
Input
A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.
Output
The output is obtained by applying successive rotations to the input string.
For each letter ([a-zA-Z]
) in the input string, going from left to right:
- if the letter is in upper case, rotate all characters before it by one position to the left
- if the letter is in lower case, rotate all characters before it by one position to the right
Example
Input: "Cb-Ad"
- The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.
- The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.
- The character "-" does not trigger any rotation, as it's not a letter.
- The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"
- The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"
Therefore, the expected output is "Ab-Cd".
Rules
- You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.
- You may also output an array of characters instead of a string.
- This is
ogl-edocfcode-golf
Test cases
"cbad" -> "abcd"
"ACBD" -> "ABCD"
"Cb-Ad" -> "Ab-Cd"
"caeBDF" -> "aBcDeF"
"aEcbDF" -> "abcDEF"
"ogl-edocf" -> "code-golf"
"W o,ollelrHd!" -> "Hello, World!"
"ti HIs SSta ET!" -> "tHis IS a tEST!"
code-golf string
Input
A non-empty shuffled string consisting of ASCII characters in the range $[32..126]$.
Output
The output is obtained by applying successive rotations to the input string.
For each letter ([a-zA-Z]
) in the input string, going from left to right:
- if the letter is in upper case, rotate all characters before it by one position to the left
- if the letter is in lower case, rotate all characters before it by one position to the right
Example
Input: "Cb-Ad"
- The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.
- The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.
- The character "-" does not trigger any rotation, as it's not a letter.
- The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"
- The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"
Therefore, the expected output is "Ab-Cd".
Rules
- You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.
- You may also output an array of characters instead of a string.
- This is
ogl-edocfcode-golf
Test cases
"cbad" -> "abcd"
"ACBD" -> "ABCD"
"Cb-Ad" -> "Ab-Cd"
"caeBDF" -> "aBcDeF"
"aEcbDF" -> "abcDEF"
"ogl-edocf" -> "code-golf"
"W o,ollelrHd!" -> "Hello, World!"
"ti HIs SSta ET!" -> "tHis IS a tEST!"
code-golf string
code-golf string
asked 1 hour ago
Arnauld
64.5k580271
64.5k580271
add a comment |Â
add a comment |Â
6 Answers
6
active
oldest
votes
up vote
1
down vote
Python 2, 100 98 95 bytes
f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p
Try it online!
add a comment |Â
up vote
1
down vote
><>, 45 bytes
ii:2+7$.::&"`")$""(*?&:&:"@")$"["(*?&!
ror
Try it online!
add a comment |Â
up vote
0
down vote
Jelly, 19 bytes
Wâ¬ḷá¹Â01Ã
ÂlÃÂ?-Ã
ÂuÃÂ?};ÃÂ/
Try it online!
add a comment |Â
up vote
0
down vote
05AB1E, 18 bytes
õIvy.liÃÂëy.uiÃÂ}}yë
Try it online.
Explanation:
TODO: Will add an explanation and test suite if I'm unable to golf it further.
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 116 bytes
s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s
Try it online!
add a comment |Â
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Python 2, 100 98 95 bytes
f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p
Try it online!
add a comment |Â
up vote
1
down vote
Python 2, 100 98 95 bytes
f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 2, 100 98 95 bytes
f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p
Try it online!
Python 2, 100 98 95 bytes
f=lambda s,p='':s and f(s[1:],[p[x:]+p[:x]+s[0]for x in[s[0].isupper()-s[0].islower()]][0])or p
Try it online!
edited 49 mins ago
answered 55 mins ago
TFeld
11.6k2833
11.6k2833
add a comment |Â
add a comment |Â
up vote
1
down vote
><>, 45 bytes
ii:2+7$.::&"`")$""(*?&:&:"@")$"["(*?Â
up vote
1
down vote
><>, 45 bytes
ii:2+7$.::&"`")$""(*?&:&:"@")$"["(*?improve this answer
add a comment LNrBG1 ... by (N in lowercase alphabet) - (N in uppercase alphabet)...
+ N ... then append N to k.
k Output the result.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Pyth, 21 20 bytes
VQ=k+.>k-F}LNrBG1N)k
Try it here
Explanation
VQ=k+.>k-F}LNrBG1N)k
VQ ) For each N in the input...
=k .>k ... rotate k (initially '')...
-F}LNrBG1 ... by (N in lowercase alphabet) - (N in uppercase alphabet)...
+ N ... then append N to k.
k Output the result.
Pyth, 21 20 bytes
VQ=k+.>k-F}LNrBG1N)k
Try it here
Explanation
VQ=k+.>k-F}LNrBG1N)k
VQ ) For each N in the input...
=k .>k ... rotate k (initially '')...
-F}LNrBG1 ... by (N in lowercase alphabet) - (N in uppercase alphabet)...
+ N ... then append N to k.
k Output the result.
edited 8 mins ago
answered 13 mins ago
Mnemonic
4,1671427
4,1671427
add a comment |Â
add a comment |Â
up vote
0
down vote
Jelly, 19 bytes
Wâ¬ḷá¹Â01Ã
ÂlÃÂ?-Ã
ÂuÃÂ?};ÃÂ/
Try it online!
add a comment |Â
up vote
0
down vote
Jelly, 19 bytes
Wâ¬ḷá¹Â01Ã
ÂlÃÂ?-Ã
ÂuÃÂ?};ÃÂ/
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Jelly, 19 bytes
Wâ¬ḷá¹Â01Ã
ÂlÃÂ?-Ã
ÂuÃÂ?};ÃÂ/
Try it online!
Jelly, 19 bytes
Wâ¬ḷá¹Â01Ã
ÂlÃÂ?-Ã
ÂuÃÂ?};ÃÂ/
Try it online!
answered 23 mins ago
Erik the Outgolfer
29.5k42798
29.5k42798
add a comment |Â
add a comment |Â
up vote
0
down vote
05AB1E, 18 bytes
õIvy.liÃÂëy.uiÃÂ}}yë
Try it online.
Explanation:
TODO: Will add an explanation and test suite if I'm unable to golf it further.
add a comment |Â
up vote
0
down vote
05AB1E, 18 bytes
õIvy.liÃÂëy.uiÃÂ}}yë
Try it online.
Explanation:
TODO: Will add an explanation and test suite if I'm unable to golf it further.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
05AB1E, 18 bytes
õIvy.liÃÂëy.uiÃÂ}}yë
Try it online.
Explanation:
TODO: Will add an explanation and test suite if I'm unable to golf it further.
05AB1E, 18 bytes
õIvy.liÃÂëy.uiÃÂ}}yë
Try it online.
Explanation:
TODO: Will add an explanation and test suite if I'm unable to golf it further.
answered 7 mins ago
Kevin Cruijssen
30.2k553167
30.2k553167
add a comment |Â
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 116 bytes
s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s
Try it online!
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 116 bytes
s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
JavaScript (Node.js), 116 bytes
s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s
Try it online!
JavaScript (Node.js), 116 bytes
s=>Buffer(s).map((x,i)=>s=(t=s[S="slice"](i),i<2)?s:x>64&x<91?s[S](1,i)+s[0]+t:x>96&x<123?s[i-1]+s[S](0,i-1)+t:s)&&s
Try it online!
answered 7 mins ago
Shieru Asakoto
1,505310
1,505310
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172455%2fan-ogl-edocf-challenge%23new-answer', 'question_page');
);
Post as a guest
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
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
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