Clock (transliterate) Cipher
Clash Royale CLAN TAG#URR8PPP
$begingroup$
Introduction:
I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the third and easiest one (after the Computer Cipher and Trifid Cipher I posted earlier).
With a Clock Cipher we use the following image to encipher text:
So a sentence like this is a clock cipher
would become:
t h i s i s a c l o c k c i p h e r (without additional spaces of course, but added as clarification)
19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17
Challenge:
Given a string sentence_to_encipher
, encipher it as described above.
Challenge rules:
- You can assume the
sentence_to_encipher
will only contain letters and spaces. - You can use either full lowercase or full uppercase (please state which one you've used in your answer).
- You are not allowed to add leading zeros for the single-digit enciphered letters
b
throughj
, but two zeros00
are mandatory for spaces. - You should use
:
as separator, and an additional leading or trailing:
is not allowed. - You are allowed to use lowercase
am
andpm
instead of uppercaseAM
andPM
, as long as it's consistent.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: "this is a clock cipher"
Output: "19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17"
Input: "test"
Output: "19:4:18:19"
Input: "what time is it"
Output: "22:7:AM:19:00:19:8:12:4:00:8:18:00:8:19"
Input: "acegikmoqsuwy bdfhjlnprtvxz"
Output: "AM:2:4:6:8:10:12:14:16:18:20:22:24:00:1:3:5:7:9:11:13:15:17:19:21:23:PM"
Input: "easy peazy"
Output: "4:AM:18:24:00:15:4:AM:PM:24"
code-golf string cipher encoding
$endgroup$
add a comment |
$begingroup$
Introduction:
I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the third and easiest one (after the Computer Cipher and Trifid Cipher I posted earlier).
With a Clock Cipher we use the following image to encipher text:
So a sentence like this is a clock cipher
would become:
t h i s i s a c l o c k c i p h e r (without additional spaces of course, but added as clarification)
19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17
Challenge:
Given a string sentence_to_encipher
, encipher it as described above.
Challenge rules:
- You can assume the
sentence_to_encipher
will only contain letters and spaces. - You can use either full lowercase or full uppercase (please state which one you've used in your answer).
- You are not allowed to add leading zeros for the single-digit enciphered letters
b
throughj
, but two zeros00
are mandatory for spaces. - You should use
:
as separator, and an additional leading or trailing:
is not allowed. - You are allowed to use lowercase
am
andpm
instead of uppercaseAM
andPM
, as long as it's consistent.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: "this is a clock cipher"
Output: "19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17"
Input: "test"
Output: "19:4:18:19"
Input: "what time is it"
Output: "22:7:AM:19:00:19:8:12:4:00:8:18:00:8:19"
Input: "acegikmoqsuwy bdfhjlnprtvxz"
Output: "AM:2:4:6:8:10:12:14:16:18:20:22:24:00:1:3:5:7:9:11:13:15:17:19:21:23:PM"
Input: "easy peazy"
Output: "4:AM:18:24:00:15:4:AM:PM:24"
code-golf string cipher encoding
$endgroup$
$begingroup$
Related
$endgroup$
– Kevin Cruijssen
Jan 4 at 7:40
$begingroup$
Is it allowed to output[7, ":", 8, ":", "00", ":", 1, ":", 14, ":", 1]
forhi bob
, or must one join the result? By the way, neat cipher!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:27
$begingroup$
@Mr.Xcoder Sorry, for the sake of the cipher theme I'd say it should be joined to a single string (or the entire thing as a list of characters like['7', ':', '8', ':', '0', '0', ':', '1', ':', '1', '4', ':', '1']
).
$endgroup$
– Kevin Cruijssen
Jan 4 at 9:32
add a comment |
$begingroup$
Introduction:
I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the third and easiest one (after the Computer Cipher and Trifid Cipher I posted earlier).
With a Clock Cipher we use the following image to encipher text:
So a sentence like this is a clock cipher
would become:
t h i s i s a c l o c k c i p h e r (without additional spaces of course, but added as clarification)
19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17
Challenge:
Given a string sentence_to_encipher
, encipher it as described above.
Challenge rules:
- You can assume the
sentence_to_encipher
will only contain letters and spaces. - You can use either full lowercase or full uppercase (please state which one you've used in your answer).
- You are not allowed to add leading zeros for the single-digit enciphered letters
b
throughj
, but two zeros00
are mandatory for spaces. - You should use
:
as separator, and an additional leading or trailing:
is not allowed. - You are allowed to use lowercase
am
andpm
instead of uppercaseAM
andPM
, as long as it's consistent.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: "this is a clock cipher"
Output: "19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17"
Input: "test"
Output: "19:4:18:19"
Input: "what time is it"
Output: "22:7:AM:19:00:19:8:12:4:00:8:18:00:8:19"
Input: "acegikmoqsuwy bdfhjlnprtvxz"
Output: "AM:2:4:6:8:10:12:14:16:18:20:22:24:00:1:3:5:7:9:11:13:15:17:19:21:23:PM"
Input: "easy peazy"
Output: "4:AM:18:24:00:15:4:AM:PM:24"
code-golf string cipher encoding
$endgroup$
Introduction:
I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the third and easiest one (after the Computer Cipher and Trifid Cipher I posted earlier).
With a Clock Cipher we use the following image to encipher text:
So a sentence like this is a clock cipher
would become:
t h i s i s a c l o c k c i p h e r (without additional spaces of course, but added as clarification)
19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17
Challenge:
Given a string sentence_to_encipher
, encipher it as described above.
Challenge rules:
- You can assume the
sentence_to_encipher
will only contain letters and spaces. - You can use either full lowercase or full uppercase (please state which one you've used in your answer).
- You are not allowed to add leading zeros for the single-digit enciphered letters
b
throughj
, but two zeros00
are mandatory for spaces. - You should use
:
as separator, and an additional leading or trailing:
is not allowed. - You are allowed to use lowercase
am
andpm
instead of uppercaseAM
andPM
, as long as it's consistent.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: "this is a clock cipher"
Output: "19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17"
Input: "test"
Output: "19:4:18:19"
Input: "what time is it"
Output: "22:7:AM:19:00:19:8:12:4:00:8:18:00:8:19"
Input: "acegikmoqsuwy bdfhjlnprtvxz"
Output: "AM:2:4:6:8:10:12:14:16:18:20:22:24:00:1:3:5:7:9:11:13:15:17:19:21:23:PM"
Input: "easy peazy"
Output: "4:AM:18:24:00:15:4:AM:PM:24"
code-golf string cipher encoding
code-golf string cipher encoding
edited Jan 4 at 8:01
Kevin Cruijssen
asked Jan 4 at 7:39
Kevin CruijssenKevin Cruijssen
36.4k555192
36.4k555192
$begingroup$
Related
$endgroup$
– Kevin Cruijssen
Jan 4 at 7:40
$begingroup$
Is it allowed to output[7, ":", 8, ":", "00", ":", 1, ":", 14, ":", 1]
forhi bob
, or must one join the result? By the way, neat cipher!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:27
$begingroup$
@Mr.Xcoder Sorry, for the sake of the cipher theme I'd say it should be joined to a single string (or the entire thing as a list of characters like['7', ':', '8', ':', '0', '0', ':', '1', ':', '1', '4', ':', '1']
).
$endgroup$
– Kevin Cruijssen
Jan 4 at 9:32
add a comment |
$begingroup$
Related
$endgroup$
– Kevin Cruijssen
Jan 4 at 7:40
$begingroup$
Is it allowed to output[7, ":", 8, ":", "00", ":", 1, ":", 14, ":", 1]
forhi bob
, or must one join the result? By the way, neat cipher!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:27
$begingroup$
@Mr.Xcoder Sorry, for the sake of the cipher theme I'd say it should be joined to a single string (or the entire thing as a list of characters like['7', ':', '8', ':', '0', '0', ':', '1', ':', '1', '4', ':', '1']
).
$endgroup$
– Kevin Cruijssen
Jan 4 at 9:32
$begingroup$
Related
$endgroup$
– Kevin Cruijssen
Jan 4 at 7:40
$begingroup$
Related
$endgroup$
– Kevin Cruijssen
Jan 4 at 7:40
$begingroup$
Is it allowed to output
[7, ":", 8, ":", "00", ":", 1, ":", 14, ":", 1]
for hi bob
, or must one join the result? By the way, neat cipher!$endgroup$
– Mr. Xcoder
Jan 4 at 9:27
$begingroup$
Is it allowed to output
[7, ":", 8, ":", "00", ":", 1, ":", 14, ":", 1]
for hi bob
, or must one join the result? By the way, neat cipher!$endgroup$
– Mr. Xcoder
Jan 4 at 9:27
$begingroup$
@Mr.Xcoder Sorry, for the sake of the cipher theme I'd say it should be joined to a single string (or the entire thing as a list of characters like
['7', ':', '8', ':', '0', '0', ':', '1', ':', '1', '4', ':', '1']
).$endgroup$
– Kevin Cruijssen
Jan 4 at 9:32
$begingroup$
@Mr.Xcoder Sorry, for the sake of the cipher theme I'd say it should be joined to a single string (or the entire thing as a list of characters like
['7', ':', '8', ':', '0', '0', ':', '1', ':', '1', '4', ':', '1']
).$endgroup$
– Kevin Cruijssen
Jan 4 at 9:32
add a comment |
14 Answers
14
active
oldest
votes
$begingroup$
Python 2, 74 72 bytes
lambda s:':'.join(['AM','PM','00',`ord(c)-97`]['az '.find(c)]for c in s)
Try it online!
Takes input as all lowercase
$endgroup$
add a comment |
$begingroup$
05AB1E, 22 21 bytes
„AM24L„PM00)˜Að«s‡':ý
Try it online!
or as a Test Suite
Some alternate 21 byte solutions:
':ýAð«24L„AMš„PMª00ª‡
00„AM24L„PM)˜AIk>è':ý
$endgroup$
$begingroup$
Nice answer, I managed to get 23 bytes through multiple approaches (one of which was my currently deleted answer). That's a neat way to arrange your stack to save a byte!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:41
1
$begingroup$
An alternate 22 byter combining our answers: Try it Online!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:43
$begingroup$
@Mr.Xcoder: My first idea actually looked like that, but 2 bytes worse because I didn't remember thatª
had changed :)
$endgroup$
– Emigna
Jan 4 at 9:48
$begingroup$
I've found a 20 byter using a portion of @Mr.Xcoder's approach, but I'll let you figure it out yourself before I reveil it. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 10:57
1
$begingroup$
@KevinCruijssen: I'll let you know after I've looked some more ;)
$endgroup$
– Emigna
Jan 4 at 13:39
|
show 6 more comments
$begingroup$
Perl 6, 47 bytes
*.ords>>.&<<00 AM1..24PM>>[$_%32].join(":")
Try it online!
Anonymous Whatever lambda that takes a string of either case and returns the encrypted string.
Explanation:
*.ords>>.& # Map the ordinal values to
<< >>[$_%32] # The index in the list
00 AM1..24PM # 00, AM, the numbers 1 to 24 and PM
.join(":") # And join with colons
$endgroup$
add a comment |
$begingroup$
Pyth, 25 bytes
j:m@+++"AM"S24"PM""00"xG
Try it online here, or verify all the test cases at once here.
j:m@+++"AM"S24"PM""00"xGdQ Implicit: Q=eval(input()), G=lowercase alphabet
Trailing dQ inferred
S24 [1-24]
+"AM" Prepend "AM"
+ "PM" Append "PM"
+ "00" Append "00" - this is the dictionary
m Q Map each element of Q, as d, using:
xGd Get the index of d in G, -1 if not present (i.e. space)
@ Get the element from the dictionary at the above index
j: Join the result on ":", implicit print
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 72 bytes
Takes input in lowercase.
s=>[...s].map(c=>c<1?'00':(x=Buffer(c)[0]-1&31)>24?'PM':x||'AM').join`:`
Try it online!
$endgroup$
add a comment |
$begingroup$
Java (JDK), 95 bytes
s->int a=0;for(var c:s)System.out.print((a++<1?"":":")+(c<33?"00":c<66?"AM":c>89?"PM":c-65));
Try it online!
Credits
- -1 byte thanks to Kevin Cruijssen
$endgroup$
$begingroup$
One easy golf:char
tovar
. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 11:00
$begingroup$
Thanks! So obvious now that you show it to me...
$endgroup$
– Olivier Grégoire
Jan 4 at 11:02
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 70 bytes
s=>string.Join(":",s.Select(a=>a<33?"00":a<66?"AM":a>89?"PM":a%65+""))
Takes input as a string of lowercase letters. First checks if the char is a space, and if it is, converts it to 00
. Next, it checks for if the char is an A, and converts it to AM
. It checks again for Z and converts it to PM
if it is. Lastly, if the char passes all the checks, it gets converted to its alphabetic order-1.
-2 bytes thanks to @dana
Try it online!
// Input taking a string
s =>
// Join the following IEnumerable<char> with a ":" character
string.Join(":",
// Map all the characters in the string
s.Select(a =>
// Is the char less than 33, aka a space?
a < 33 ?
// If so, it's a "00"
"00"
// Else, is this an 'A'?
: a < 66 ?
// If so, convert it to "AM"
"AM" :
// If it's not 'A' or a space, could it be a 'Z'?
a > 89 ?
// If it is, turn the character into "PM"
"PM" :
// If it fails all of the checks above, get the characters position in the alphabet and subtract one from that.
a % 65 + ""))
$endgroup$
add a comment |
$begingroup$
Ruby, 49 bytes
->aa.map["00",:AM,*1..24,:PM][c.ord%32]*?:
Try it online!
Port of Jo King's Perl answer.
Takes input as an array of chars, returns a string with AM/PM in uppercase.
$endgroup$
add a comment |
$begingroup$
Red, 124 121 110 109 bytes
func[s][replace/all form collect[forall s[keep switch/default
c: -97 + s/1[0['AM]25['PM]-65["00"]][c]]]sp":"]
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 100 bytes
proc C s join [lmap c [split $s ""] scan $c %c v
expr $v==65?"AM":$v==90?"PM":$v==32?00:$v-65] :
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 20 bytes
':ýð00:A24L„AMš„PMª‡
Greatly inspired by @Mr.Xcoder's 22-byter in the comment of the existing 05AB1E answer by @Emigna.
Takes the input as a list of lowercase characters (would be 21 bytes with a leading S
if I take the input as a string).
Try it online or verify all test cases.
Explanation:
':ý '# Join the (implicit) input list of characters by ":"
# i.e. ["e","a","s","y"," ","p","e","a","z","y"] → "e:a:s:y: :p:e:a:z:y"
ð00: # Replace all spaces " " with "00"
# i.e. "e:a:s:y: :p:e:a:z:y" → "e:a:s:y:00:p:e:a:z:y"
A # Push the lowercase alphabet
24L # Push a list in the range [1,24]
„AMš # Prepend "AM" at the start of this list
„PMª # And append "PM" at the end of the list
‡ # Transliterate; mapping letters to the list-items at the same indices
# (and output the result implicitly)
# i.e. "e:a:s:y:00:p:e:a:z:y" → "4:AM:18:24:00:15:4:AM:PM:24"
$endgroup$
1
$begingroup$
Ah yes. Replacing the space separately saves a byte. I should have tried that. Nice :)
$endgroup$
– Emigna
Jan 4 at 14:41
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 98 bytes
s=>string.Join(':',s.Select(c=>"az ".Contains(c)?new"AM","PM","00"["az ".IndexOf(c)]:c-97+""))
Takes input as a (lowercase) char array. Try it online!
$endgroup$
$begingroup$
82 bytes:s=>string.Join(':',s.Select(c=>newc-97+"","AM","PM","00"["az ".IndexOf(c)+1]))
.
$endgroup$
– dana
Jan 5 at 12:45
add a comment |
$begingroup$
Charcoal, 26 bytes
UB:Fθ«→≡ι ×0²a¦AM¦z¦PMI⌕βι
Try it online! Link is to verbose version of code. Takes input in lower case (can trivially be changed to upper case). Explanation:
UB:
Set the background character to :
. This fills in the gaps between the output values created by the right movement.
Fθ«→
Loop over each character, leaving a gap each time. (The first move has no effect as the canvas is still empty at this point.)
≡ι ×0²a¦AM¦z¦PM
Switch on the character and if it's space, a
or z
then output the appropriate code. I use ×0²
instead of 00
here as the latter would cost two bytes in additional separators.
I⌕βι
Otherwise output the letter's 0-indexed position in the lower case alphabet as a string.
$endgroup$
add a comment |
$begingroup$
Jelly, 24 bytes
«"⁾PMµØAḊiȯ⁾00µe?€⁾AZj”:
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
);
);
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%2f178356%2fclock-transliterate-cipher%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 74 72 bytes
lambda s:':'.join(['AM','PM','00',`ord(c)-97`]['az '.find(c)]for c in s)
Try it online!
Takes input as all lowercase
$endgroup$
add a comment |
$begingroup$
Python 2, 74 72 bytes
lambda s:':'.join(['AM','PM','00',`ord(c)-97`]['az '.find(c)]for c in s)
Try it online!
Takes input as all lowercase
$endgroup$
add a comment |
$begingroup$
Python 2, 74 72 bytes
lambda s:':'.join(['AM','PM','00',`ord(c)-97`]['az '.find(c)]for c in s)
Try it online!
Takes input as all lowercase
$endgroup$
Python 2, 74 72 bytes
lambda s:':'.join(['AM','PM','00',`ord(c)-97`]['az '.find(c)]for c in s)
Try it online!
Takes input as all lowercase
answered Jan 4 at 8:08
TFeldTFeld
14.5k21241
14.5k21241
add a comment |
add a comment |
$begingroup$
05AB1E, 22 21 bytes
„AM24L„PM00)˜Að«s‡':ý
Try it online!
or as a Test Suite
Some alternate 21 byte solutions:
':ýAð«24L„AMš„PMª00ª‡
00„AM24L„PM)˜AIk>è':ý
$endgroup$
$begingroup$
Nice answer, I managed to get 23 bytes through multiple approaches (one of which was my currently deleted answer). That's a neat way to arrange your stack to save a byte!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:41
1
$begingroup$
An alternate 22 byter combining our answers: Try it Online!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:43
$begingroup$
@Mr.Xcoder: My first idea actually looked like that, but 2 bytes worse because I didn't remember thatª
had changed :)
$endgroup$
– Emigna
Jan 4 at 9:48
$begingroup$
I've found a 20 byter using a portion of @Mr.Xcoder's approach, but I'll let you figure it out yourself before I reveil it. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 10:57
1
$begingroup$
@KevinCruijssen: I'll let you know after I've looked some more ;)
$endgroup$
– Emigna
Jan 4 at 13:39
|
show 6 more comments
$begingroup$
05AB1E, 22 21 bytes
„AM24L„PM00)˜Að«s‡':ý
Try it online!
or as a Test Suite
Some alternate 21 byte solutions:
':ýAð«24L„AMš„PMª00ª‡
00„AM24L„PM)˜AIk>è':ý
$endgroup$
$begingroup$
Nice answer, I managed to get 23 bytes through multiple approaches (one of which was my currently deleted answer). That's a neat way to arrange your stack to save a byte!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:41
1
$begingroup$
An alternate 22 byter combining our answers: Try it Online!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:43
$begingroup$
@Mr.Xcoder: My first idea actually looked like that, but 2 bytes worse because I didn't remember thatª
had changed :)
$endgroup$
– Emigna
Jan 4 at 9:48
$begingroup$
I've found a 20 byter using a portion of @Mr.Xcoder's approach, but I'll let you figure it out yourself before I reveil it. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 10:57
1
$begingroup$
@KevinCruijssen: I'll let you know after I've looked some more ;)
$endgroup$
– Emigna
Jan 4 at 13:39
|
show 6 more comments
$begingroup$
05AB1E, 22 21 bytes
„AM24L„PM00)˜Að«s‡':ý
Try it online!
or as a Test Suite
Some alternate 21 byte solutions:
':ýAð«24L„AMš„PMª00ª‡
00„AM24L„PM)˜AIk>è':ý
$endgroup$
05AB1E, 22 21 bytes
„AM24L„PM00)˜Að«s‡':ý
Try it online!
or as a Test Suite
Some alternate 21 byte solutions:
':ýAð«24L„AMš„PMª00ª‡
00„AM24L„PM)˜AIk>è':ý
edited Jan 4 at 14:36
answered Jan 4 at 8:58
EmignaEmigna
45.7k432139
45.7k432139
$begingroup$
Nice answer, I managed to get 23 bytes through multiple approaches (one of which was my currently deleted answer). That's a neat way to arrange your stack to save a byte!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:41
1
$begingroup$
An alternate 22 byter combining our answers: Try it Online!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:43
$begingroup$
@Mr.Xcoder: My first idea actually looked like that, but 2 bytes worse because I didn't remember thatª
had changed :)
$endgroup$
– Emigna
Jan 4 at 9:48
$begingroup$
I've found a 20 byter using a portion of @Mr.Xcoder's approach, but I'll let you figure it out yourself before I reveil it. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 10:57
1
$begingroup$
@KevinCruijssen: I'll let you know after I've looked some more ;)
$endgroup$
– Emigna
Jan 4 at 13:39
|
show 6 more comments
$begingroup$
Nice answer, I managed to get 23 bytes through multiple approaches (one of which was my currently deleted answer). That's a neat way to arrange your stack to save a byte!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:41
1
$begingroup$
An alternate 22 byter combining our answers: Try it Online!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:43
$begingroup$
@Mr.Xcoder: My first idea actually looked like that, but 2 bytes worse because I didn't remember thatª
had changed :)
$endgroup$
– Emigna
Jan 4 at 9:48
$begingroup$
I've found a 20 byter using a portion of @Mr.Xcoder's approach, but I'll let you figure it out yourself before I reveil it. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 10:57
1
$begingroup$
@KevinCruijssen: I'll let you know after I've looked some more ;)
$endgroup$
– Emigna
Jan 4 at 13:39
$begingroup$
Nice answer, I managed to get 23 bytes through multiple approaches (one of which was my currently deleted answer). That's a neat way to arrange your stack to save a byte!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:41
$begingroup$
Nice answer, I managed to get 23 bytes through multiple approaches (one of which was my currently deleted answer). That's a neat way to arrange your stack to save a byte!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:41
1
1
$begingroup$
An alternate 22 byter combining our answers: Try it Online!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:43
$begingroup$
An alternate 22 byter combining our answers: Try it Online!
$endgroup$
– Mr. Xcoder
Jan 4 at 9:43
$begingroup$
@Mr.Xcoder: My first idea actually looked like that, but 2 bytes worse because I didn't remember that
ª
had changed :)$endgroup$
– Emigna
Jan 4 at 9:48
$begingroup$
@Mr.Xcoder: My first idea actually looked like that, but 2 bytes worse because I didn't remember that
ª
had changed :)$endgroup$
– Emigna
Jan 4 at 9:48
$begingroup$
I've found a 20 byter using a portion of @Mr.Xcoder's approach, but I'll let you figure it out yourself before I reveil it. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 10:57
$begingroup$
I've found a 20 byter using a portion of @Mr.Xcoder's approach, but I'll let you figure it out yourself before I reveil it. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 10:57
1
1
$begingroup$
@KevinCruijssen: I'll let you know after I've looked some more ;)
$endgroup$
– Emigna
Jan 4 at 13:39
$begingroup$
@KevinCruijssen: I'll let you know after I've looked some more ;)
$endgroup$
– Emigna
Jan 4 at 13:39
|
show 6 more comments
$begingroup$
Perl 6, 47 bytes
*.ords>>.&<<00 AM1..24PM>>[$_%32].join(":")
Try it online!
Anonymous Whatever lambda that takes a string of either case and returns the encrypted string.
Explanation:
*.ords>>.& # Map the ordinal values to
<< >>[$_%32] # The index in the list
00 AM1..24PM # 00, AM, the numbers 1 to 24 and PM
.join(":") # And join with colons
$endgroup$
add a comment |
$begingroup$
Perl 6, 47 bytes
*.ords>>.&<<00 AM1..24PM>>[$_%32].join(":")
Try it online!
Anonymous Whatever lambda that takes a string of either case and returns the encrypted string.
Explanation:
*.ords>>.& # Map the ordinal values to
<< >>[$_%32] # The index in the list
00 AM1..24PM # 00, AM, the numbers 1 to 24 and PM
.join(":") # And join with colons
$endgroup$
add a comment |
$begingroup$
Perl 6, 47 bytes
*.ords>>.&<<00 AM1..24PM>>[$_%32].join(":")
Try it online!
Anonymous Whatever lambda that takes a string of either case and returns the encrypted string.
Explanation:
*.ords>>.& # Map the ordinal values to
<< >>[$_%32] # The index in the list
00 AM1..24PM # 00, AM, the numbers 1 to 24 and PM
.join(":") # And join with colons
$endgroup$
Perl 6, 47 bytes
*.ords>>.&<<00 AM1..24PM>>[$_%32].join(":")
Try it online!
Anonymous Whatever lambda that takes a string of either case and returns the encrypted string.
Explanation:
*.ords>>.& # Map the ordinal values to
<< >>[$_%32] # The index in the list
00 AM1..24PM # 00, AM, the numbers 1 to 24 and PM
.join(":") # And join with colons
edited Jan 4 at 12:36
answered Jan 4 at 8:53
Jo KingJo King
21.3k248110
21.3k248110
add a comment |
add a comment |
$begingroup$
Pyth, 25 bytes
j:m@+++"AM"S24"PM""00"xG
Try it online here, or verify all the test cases at once here.
j:m@+++"AM"S24"PM""00"xGdQ Implicit: Q=eval(input()), G=lowercase alphabet
Trailing dQ inferred
S24 [1-24]
+"AM" Prepend "AM"
+ "PM" Append "PM"
+ "00" Append "00" - this is the dictionary
m Q Map each element of Q, as d, using:
xGd Get the index of d in G, -1 if not present (i.e. space)
@ Get the element from the dictionary at the above index
j: Join the result on ":", implicit print
$endgroup$
add a comment |
$begingroup$
Pyth, 25 bytes
j:m@+++"AM"S24"PM""00"xG
Try it online here, or verify all the test cases at once here.
j:m@+++"AM"S24"PM""00"xGdQ Implicit: Q=eval(input()), G=lowercase alphabet
Trailing dQ inferred
S24 [1-24]
+"AM" Prepend "AM"
+ "PM" Append "PM"
+ "00" Append "00" - this is the dictionary
m Q Map each element of Q, as d, using:
xGd Get the index of d in G, -1 if not present (i.e. space)
@ Get the element from the dictionary at the above index
j: Join the result on ":", implicit print
$endgroup$
add a comment |
$begingroup$
Pyth, 25 bytes
j:m@+++"AM"S24"PM""00"xG
Try it online here, or verify all the test cases at once here.
j:m@+++"AM"S24"PM""00"xGdQ Implicit: Q=eval(input()), G=lowercase alphabet
Trailing dQ inferred
S24 [1-24]
+"AM" Prepend "AM"
+ "PM" Append "PM"
+ "00" Append "00" - this is the dictionary
m Q Map each element of Q, as d, using:
xGd Get the index of d in G, -1 if not present (i.e. space)
@ Get the element from the dictionary at the above index
j: Join the result on ":", implicit print
$endgroup$
Pyth, 25 bytes
j:m@+++"AM"S24"PM""00"xG
Try it online here, or verify all the test cases at once here.
j:m@+++"AM"S24"PM""00"xGdQ Implicit: Q=eval(input()), G=lowercase alphabet
Trailing dQ inferred
S24 [1-24]
+"AM" Prepend "AM"
+ "PM" Append "PM"
+ "00" Append "00" - this is the dictionary
m Q Map each element of Q, as d, using:
xGd Get the index of d in G, -1 if not present (i.e. space)
@ Get the element from the dictionary at the above index
j: Join the result on ":", implicit print
answered Jan 4 at 10:21
SokSok
3,607723
3,607723
add a comment |
add a comment |
$begingroup$
JavaScript (Node.js), 72 bytes
Takes input in lowercase.
s=>[...s].map(c=>c<1?'00':(x=Buffer(c)[0]-1&31)>24?'PM':x||'AM').join`:`
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 72 bytes
Takes input in lowercase.
s=>[...s].map(c=>c<1?'00':(x=Buffer(c)[0]-1&31)>24?'PM':x||'AM').join`:`
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (Node.js), 72 bytes
Takes input in lowercase.
s=>[...s].map(c=>c<1?'00':(x=Buffer(c)[0]-1&31)>24?'PM':x||'AM').join`:`
Try it online!
$endgroup$
JavaScript (Node.js), 72 bytes
Takes input in lowercase.
s=>[...s].map(c=>c<1?'00':(x=Buffer(c)[0]-1&31)>24?'PM':x||'AM').join`:`
Try it online!
answered Jan 4 at 10:38
ArnauldArnauld
73.5k689308
73.5k689308
add a comment |
add a comment |
$begingroup$
Java (JDK), 95 bytes
s->int a=0;for(var c:s)System.out.print((a++<1?"":":")+(c<33?"00":c<66?"AM":c>89?"PM":c-65));
Try it online!
Credits
- -1 byte thanks to Kevin Cruijssen
$endgroup$
$begingroup$
One easy golf:char
tovar
. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 11:00
$begingroup$
Thanks! So obvious now that you show it to me...
$endgroup$
– Olivier Grégoire
Jan 4 at 11:02
add a comment |
$begingroup$
Java (JDK), 95 bytes
s->int a=0;for(var c:s)System.out.print((a++<1?"":":")+(c<33?"00":c<66?"AM":c>89?"PM":c-65));
Try it online!
Credits
- -1 byte thanks to Kevin Cruijssen
$endgroup$
$begingroup$
One easy golf:char
tovar
. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 11:00
$begingroup$
Thanks! So obvious now that you show it to me...
$endgroup$
– Olivier Grégoire
Jan 4 at 11:02
add a comment |
$begingroup$
Java (JDK), 95 bytes
s->int a=0;for(var c:s)System.out.print((a++<1?"":":")+(c<33?"00":c<66?"AM":c>89?"PM":c-65));
Try it online!
Credits
- -1 byte thanks to Kevin Cruijssen
$endgroup$
Java (JDK), 95 bytes
s->int a=0;for(var c:s)System.out.print((a++<1?"":":")+(c<33?"00":c<66?"AM":c>89?"PM":c-65));
Try it online!
Credits
- -1 byte thanks to Kevin Cruijssen
edited Jan 4 at 17:48
answered Jan 4 at 10:59
Olivier GrégoireOlivier Grégoire
8,92511843
8,92511843
$begingroup$
One easy golf:char
tovar
. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 11:00
$begingroup$
Thanks! So obvious now that you show it to me...
$endgroup$
– Olivier Grégoire
Jan 4 at 11:02
add a comment |
$begingroup$
One easy golf:char
tovar
. :)
$endgroup$
– Kevin Cruijssen
Jan 4 at 11:00
$begingroup$
Thanks! So obvious now that you show it to me...
$endgroup$
– Olivier Grégoire
Jan 4 at 11:02
$begingroup$
One easy golf:
char
to var
. :)$endgroup$
– Kevin Cruijssen
Jan 4 at 11:00
$begingroup$
One easy golf:
char
to var
. :)$endgroup$
– Kevin Cruijssen
Jan 4 at 11:00
$begingroup$
Thanks! So obvious now that you show it to me...
$endgroup$
– Olivier Grégoire
Jan 4 at 11:02
$begingroup$
Thanks! So obvious now that you show it to me...
$endgroup$
– Olivier Grégoire
Jan 4 at 11:02
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 70 bytes
s=>string.Join(":",s.Select(a=>a<33?"00":a<66?"AM":a>89?"PM":a%65+""))
Takes input as a string of lowercase letters. First checks if the char is a space, and if it is, converts it to 00
. Next, it checks for if the char is an A, and converts it to AM
. It checks again for Z and converts it to PM
if it is. Lastly, if the char passes all the checks, it gets converted to its alphabetic order-1.
-2 bytes thanks to @dana
Try it online!
// Input taking a string
s =>
// Join the following IEnumerable<char> with a ":" character
string.Join(":",
// Map all the characters in the string
s.Select(a =>
// Is the char less than 33, aka a space?
a < 33 ?
// If so, it's a "00"
"00"
// Else, is this an 'A'?
: a < 66 ?
// If so, convert it to "AM"
"AM" :
// If it's not 'A' or a space, could it be a 'Z'?
a > 89 ?
// If it is, turn the character into "PM"
"PM" :
// If it fails all of the checks above, get the characters position in the alphabet and subtract one from that.
a % 65 + ""))
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 70 bytes
s=>string.Join(":",s.Select(a=>a<33?"00":a<66?"AM":a>89?"PM":a%65+""))
Takes input as a string of lowercase letters. First checks if the char is a space, and if it is, converts it to 00
. Next, it checks for if the char is an A, and converts it to AM
. It checks again for Z and converts it to PM
if it is. Lastly, if the char passes all the checks, it gets converted to its alphabetic order-1.
-2 bytes thanks to @dana
Try it online!
// Input taking a string
s =>
// Join the following IEnumerable<char> with a ":" character
string.Join(":",
// Map all the characters in the string
s.Select(a =>
// Is the char less than 33, aka a space?
a < 33 ?
// If so, it's a "00"
"00"
// Else, is this an 'A'?
: a < 66 ?
// If so, convert it to "AM"
"AM" :
// If it's not 'A' or a space, could it be a 'Z'?
a > 89 ?
// If it is, turn the character into "PM"
"PM" :
// If it fails all of the checks above, get the characters position in the alphabet and subtract one from that.
a % 65 + ""))
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 70 bytes
s=>string.Join(":",s.Select(a=>a<33?"00":a<66?"AM":a>89?"PM":a%65+""))
Takes input as a string of lowercase letters. First checks if the char is a space, and if it is, converts it to 00
. Next, it checks for if the char is an A, and converts it to AM
. It checks again for Z and converts it to PM
if it is. Lastly, if the char passes all the checks, it gets converted to its alphabetic order-1.
-2 bytes thanks to @dana
Try it online!
// Input taking a string
s =>
// Join the following IEnumerable<char> with a ":" character
string.Join(":",
// Map all the characters in the string
s.Select(a =>
// Is the char less than 33, aka a space?
a < 33 ?
// If so, it's a "00"
"00"
// Else, is this an 'A'?
: a < 66 ?
// If so, convert it to "AM"
"AM" :
// If it's not 'A' or a space, could it be a 'Z'?
a > 89 ?
// If it is, turn the character into "PM"
"PM" :
// If it fails all of the checks above, get the characters position in the alphabet and subtract one from that.
a % 65 + ""))
$endgroup$
C# (Visual C# Interactive Compiler), 70 bytes
s=>string.Join(":",s.Select(a=>a<33?"00":a<66?"AM":a>89?"PM":a%65+""))
Takes input as a string of lowercase letters. First checks if the char is a space, and if it is, converts it to 00
. Next, it checks for if the char is an A, and converts it to AM
. It checks again for Z and converts it to PM
if it is. Lastly, if the char passes all the checks, it gets converted to its alphabetic order-1.
-2 bytes thanks to @dana
Try it online!
// Input taking a string
s =>
// Join the following IEnumerable<char> with a ":" character
string.Join(":",
// Map all the characters in the string
s.Select(a =>
// Is the char less than 33, aka a space?
a < 33 ?
// If so, it's a "00"
"00"
// Else, is this an 'A'?
: a < 66 ?
// If so, convert it to "AM"
"AM" :
// If it's not 'A' or a space, could it be a 'Z'?
a > 89 ?
// If it is, turn the character into "PM"
"PM" :
// If it fails all of the checks above, get the characters position in the alphabet and subtract one from that.
a % 65 + ""))
edited Jan 5 at 22:41
answered Jan 4 at 17:00
Embodiment of IgnoranceEmbodiment of Ignorance
631115
631115
add a comment |
add a comment |
$begingroup$
Ruby, 49 bytes
->aa.map["00",:AM,*1..24,:PM][c.ord%32]*?:
Try it online!
Port of Jo King's Perl answer.
Takes input as an array of chars, returns a string with AM/PM in uppercase.
$endgroup$
add a comment |
$begingroup$
Ruby, 49 bytes
->aa.map["00",:AM,*1..24,:PM][c.ord%32]*?:
Try it online!
Port of Jo King's Perl answer.
Takes input as an array of chars, returns a string with AM/PM in uppercase.
$endgroup$
add a comment |
$begingroup$
Ruby, 49 bytes
->aa.map["00",:AM,*1..24,:PM][c.ord%32]*?:
Try it online!
Port of Jo King's Perl answer.
Takes input as an array of chars, returns a string with AM/PM in uppercase.
$endgroup$
Ruby, 49 bytes
->aa.map["00",:AM,*1..24,:PM][c.ord%32]*?:
Try it online!
Port of Jo King's Perl answer.
Takes input as an array of chars, returns a string with AM/PM in uppercase.
answered Jan 4 at 10:20
Kirill L.Kirill L.
3,8051319
3,8051319
add a comment |
add a comment |
$begingroup$
Red, 124 121 110 109 bytes
func[s][replace/all form collect[forall s[keep switch/default
c: -97 + s/1[0['AM]25['PM]-65["00"]][c]]]sp":"]
Try it online!
$endgroup$
add a comment |
$begingroup$
Red, 124 121 110 109 bytes
func[s][replace/all form collect[forall s[keep switch/default
c: -97 + s/1[0['AM]25['PM]-65["00"]][c]]]sp":"]
Try it online!
$endgroup$
add a comment |
$begingroup$
Red, 124 121 110 109 bytes
func[s][replace/all form collect[forall s[keep switch/default
c: -97 + s/1[0['AM]25['PM]-65["00"]][c]]]sp":"]
Try it online!
$endgroup$
Red, 124 121 110 109 bytes
func[s][replace/all form collect[forall s[keep switch/default
c: -97 + s/1[0['AM]25['PM]-65["00"]][c]]]sp":"]
Try it online!
edited Jan 4 at 11:31
answered Jan 4 at 9:29
Galen IvanovGalen Ivanov
6,49711032
6,49711032
add a comment |
add a comment |
$begingroup$
Tcl, 100 bytes
proc C s join [lmap c [split $s ""] scan $c %c v
expr $v==65?"AM":$v==90?"PM":$v==32?00:$v-65] :
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 100 bytes
proc C s join [lmap c [split $s ""] scan $c %c v
expr $v==65?"AM":$v==90?"PM":$v==32?00:$v-65] :
Try it online!
$endgroup$
add a comment |
$begingroup$
Tcl, 100 bytes
proc C s join [lmap c [split $s ""] scan $c %c v
expr $v==65?"AM":$v==90?"PM":$v==32?00:$v-65] :
Try it online!
$endgroup$
Tcl, 100 bytes
proc C s join [lmap c [split $s ""] scan $c %c v
expr $v==65?"AM":$v==90?"PM":$v==32?00:$v-65] :
Try it online!
edited Jan 4 at 14:11
answered Jan 4 at 13:15
sergiolsergiol
2,5271925
2,5271925
add a comment |
add a comment |
$begingroup$
05AB1E, 20 bytes
':ýð00:A24L„AMš„PMª‡
Greatly inspired by @Mr.Xcoder's 22-byter in the comment of the existing 05AB1E answer by @Emigna.
Takes the input as a list of lowercase characters (would be 21 bytes with a leading S
if I take the input as a string).
Try it online or verify all test cases.
Explanation:
':ý '# Join the (implicit) input list of characters by ":"
# i.e. ["e","a","s","y"," ","p","e","a","z","y"] → "e:a:s:y: :p:e:a:z:y"
ð00: # Replace all spaces " " with "00"
# i.e. "e:a:s:y: :p:e:a:z:y" → "e:a:s:y:00:p:e:a:z:y"
A # Push the lowercase alphabet
24L # Push a list in the range [1,24]
„AMš # Prepend "AM" at the start of this list
„PMª # And append "PM" at the end of the list
‡ # Transliterate; mapping letters to the list-items at the same indices
# (and output the result implicitly)
# i.e. "e:a:s:y:00:p:e:a:z:y" → "4:AM:18:24:00:15:4:AM:PM:24"
$endgroup$
1
$begingroup$
Ah yes. Replacing the space separately saves a byte. I should have tried that. Nice :)
$endgroup$
– Emigna
Jan 4 at 14:41
add a comment |
$begingroup$
05AB1E, 20 bytes
':ýð00:A24L„AMš„PMª‡
Greatly inspired by @Mr.Xcoder's 22-byter in the comment of the existing 05AB1E answer by @Emigna.
Takes the input as a list of lowercase characters (would be 21 bytes with a leading S
if I take the input as a string).
Try it online or verify all test cases.
Explanation:
':ý '# Join the (implicit) input list of characters by ":"
# i.e. ["e","a","s","y"," ","p","e","a","z","y"] → "e:a:s:y: :p:e:a:z:y"
ð00: # Replace all spaces " " with "00"
# i.e. "e:a:s:y: :p:e:a:z:y" → "e:a:s:y:00:p:e:a:z:y"
A # Push the lowercase alphabet
24L # Push a list in the range [1,24]
„AMš # Prepend "AM" at the start of this list
„PMª # And append "PM" at the end of the list
‡ # Transliterate; mapping letters to the list-items at the same indices
# (and output the result implicitly)
# i.e. "e:a:s:y:00:p:e:a:z:y" → "4:AM:18:24:00:15:4:AM:PM:24"
$endgroup$
1
$begingroup$
Ah yes. Replacing the space separately saves a byte. I should have tried that. Nice :)
$endgroup$
– Emigna
Jan 4 at 14:41
add a comment |
$begingroup$
05AB1E, 20 bytes
':ýð00:A24L„AMš„PMª‡
Greatly inspired by @Mr.Xcoder's 22-byter in the comment of the existing 05AB1E answer by @Emigna.
Takes the input as a list of lowercase characters (would be 21 bytes with a leading S
if I take the input as a string).
Try it online or verify all test cases.
Explanation:
':ý '# Join the (implicit) input list of characters by ":"
# i.e. ["e","a","s","y"," ","p","e","a","z","y"] → "e:a:s:y: :p:e:a:z:y"
ð00: # Replace all spaces " " with "00"
# i.e. "e:a:s:y: :p:e:a:z:y" → "e:a:s:y:00:p:e:a:z:y"
A # Push the lowercase alphabet
24L # Push a list in the range [1,24]
„AMš # Prepend "AM" at the start of this list
„PMª # And append "PM" at the end of the list
‡ # Transliterate; mapping letters to the list-items at the same indices
# (and output the result implicitly)
# i.e. "e:a:s:y:00:p:e:a:z:y" → "4:AM:18:24:00:15:4:AM:PM:24"
$endgroup$
05AB1E, 20 bytes
':ýð00:A24L„AMš„PMª‡
Greatly inspired by @Mr.Xcoder's 22-byter in the comment of the existing 05AB1E answer by @Emigna.
Takes the input as a list of lowercase characters (would be 21 bytes with a leading S
if I take the input as a string).
Try it online or verify all test cases.
Explanation:
':ý '# Join the (implicit) input list of characters by ":"
# i.e. ["e","a","s","y"," ","p","e","a","z","y"] → "e:a:s:y: :p:e:a:z:y"
ð00: # Replace all spaces " " with "00"
# i.e. "e:a:s:y: :p:e:a:z:y" → "e:a:s:y:00:p:e:a:z:y"
A # Push the lowercase alphabet
24L # Push a list in the range [1,24]
„AMš # Prepend "AM" at the start of this list
„PMª # And append "PM" at the end of the list
‡ # Transliterate; mapping letters to the list-items at the same indices
# (and output the result implicitly)
# i.e. "e:a:s:y:00:p:e:a:z:y" → "4:AM:18:24:00:15:4:AM:PM:24"
answered Jan 4 at 14:34
Kevin CruijssenKevin Cruijssen
36.4k555192
36.4k555192
1
$begingroup$
Ah yes. Replacing the space separately saves a byte. I should have tried that. Nice :)
$endgroup$
– Emigna
Jan 4 at 14:41
add a comment |
1
$begingroup$
Ah yes. Replacing the space separately saves a byte. I should have tried that. Nice :)
$endgroup$
– Emigna
Jan 4 at 14:41
1
1
$begingroup$
Ah yes. Replacing the space separately saves a byte. I should have tried that. Nice :)
$endgroup$
– Emigna
Jan 4 at 14:41
$begingroup$
Ah yes. Replacing the space separately saves a byte. I should have tried that. Nice :)
$endgroup$
– Emigna
Jan 4 at 14:41
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 98 bytes
s=>string.Join(':',s.Select(c=>"az ".Contains(c)?new"AM","PM","00"["az ".IndexOf(c)]:c-97+""))
Takes input as a (lowercase) char array. Try it online!
$endgroup$
$begingroup$
82 bytes:s=>string.Join(':',s.Select(c=>newc-97+"","AM","PM","00"["az ".IndexOf(c)+1]))
.
$endgroup$
– dana
Jan 5 at 12:45
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 98 bytes
s=>string.Join(':',s.Select(c=>"az ".Contains(c)?new"AM","PM","00"["az ".IndexOf(c)]:c-97+""))
Takes input as a (lowercase) char array. Try it online!
$endgroup$
$begingroup$
82 bytes:s=>string.Join(':',s.Select(c=>newc-97+"","AM","PM","00"["az ".IndexOf(c)+1]))
.
$endgroup$
– dana
Jan 5 at 12:45
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 98 bytes
s=>string.Join(':',s.Select(c=>"az ".Contains(c)?new"AM","PM","00"["az ".IndexOf(c)]:c-97+""))
Takes input as a (lowercase) char array. Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 98 bytes
s=>string.Join(':',s.Select(c=>"az ".Contains(c)?new"AM","PM","00"["az ".IndexOf(c)]:c-97+""))
Takes input as a (lowercase) char array. Try it online!
answered Jan 4 at 15:46
someonesomeone
472416
472416
$begingroup$
82 bytes:s=>string.Join(':',s.Select(c=>newc-97+"","AM","PM","00"["az ".IndexOf(c)+1]))
.
$endgroup$
– dana
Jan 5 at 12:45
add a comment |
$begingroup$
82 bytes:s=>string.Join(':',s.Select(c=>newc-97+"","AM","PM","00"["az ".IndexOf(c)+1]))
.
$endgroup$
– dana
Jan 5 at 12:45
$begingroup$
82 bytes:
s=>string.Join(':',s.Select(c=>newc-97+"","AM","PM","00"["az ".IndexOf(c)+1]))
.$endgroup$
– dana
Jan 5 at 12:45
$begingroup$
82 bytes:
s=>string.Join(':',s.Select(c=>newc-97+"","AM","PM","00"["az ".IndexOf(c)+1]))
.$endgroup$
– dana
Jan 5 at 12:45
add a comment |
$begingroup$
Charcoal, 26 bytes
UB:Fθ«→≡ι ×0²a¦AM¦z¦PMI⌕βι
Try it online! Link is to verbose version of code. Takes input in lower case (can trivially be changed to upper case). Explanation:
UB:
Set the background character to :
. This fills in the gaps between the output values created by the right movement.
Fθ«→
Loop over each character, leaving a gap each time. (The first move has no effect as the canvas is still empty at this point.)
≡ι ×0²a¦AM¦z¦PM
Switch on the character and if it's space, a
or z
then output the appropriate code. I use ×0²
instead of 00
here as the latter would cost two bytes in additional separators.
I⌕βι
Otherwise output the letter's 0-indexed position in the lower case alphabet as a string.
$endgroup$
add a comment |
$begingroup$
Charcoal, 26 bytes
UB:Fθ«→≡ι ×0²a¦AM¦z¦PMI⌕βι
Try it online! Link is to verbose version of code. Takes input in lower case (can trivially be changed to upper case). Explanation:
UB:
Set the background character to :
. This fills in the gaps between the output values created by the right movement.
Fθ«→
Loop over each character, leaving a gap each time. (The first move has no effect as the canvas is still empty at this point.)
≡ι ×0²a¦AM¦z¦PM
Switch on the character and if it's space, a
or z
then output the appropriate code. I use ×0²
instead of 00
here as the latter would cost two bytes in additional separators.
I⌕βι
Otherwise output the letter's 0-indexed position in the lower case alphabet as a string.
$endgroup$
add a comment |
$begingroup$
Charcoal, 26 bytes
UB:Fθ«→≡ι ×0²a¦AM¦z¦PMI⌕βι
Try it online! Link is to verbose version of code. Takes input in lower case (can trivially be changed to upper case). Explanation:
UB:
Set the background character to :
. This fills in the gaps between the output values created by the right movement.
Fθ«→
Loop over each character, leaving a gap each time. (The first move has no effect as the canvas is still empty at this point.)
≡ι ×0²a¦AM¦z¦PM
Switch on the character and if it's space, a
or z
then output the appropriate code. I use ×0²
instead of 00
here as the latter would cost two bytes in additional separators.
I⌕βι
Otherwise output the letter's 0-indexed position in the lower case alphabet as a string.
$endgroup$
Charcoal, 26 bytes
UB:Fθ«→≡ι ×0²a¦AM¦z¦PMI⌕βι
Try it online! Link is to verbose version of code. Takes input in lower case (can trivially be changed to upper case). Explanation:
UB:
Set the background character to :
. This fills in the gaps between the output values created by the right movement.
Fθ«→
Loop over each character, leaving a gap each time. (The first move has no effect as the canvas is still empty at this point.)
≡ι ×0²a¦AM¦z¦PM
Switch on the character and if it's space, a
or z
then output the appropriate code. I use ×0²
instead of 00
here as the latter would cost two bytes in additional separators.
I⌕βι
Otherwise output the letter's 0-indexed position in the lower case alphabet as a string.
answered Jan 4 at 18:16
NeilNeil
79.9k744177
79.9k744177
add a comment |
add a comment |
$begingroup$
Jelly, 24 bytes
«"⁾PMµØAḊiȯ⁾00µe?€⁾AZj”:
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 24 bytes
«"⁾PMµØAḊiȯ⁾00µe?€⁾AZj”:
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 24 bytes
«"⁾PMµØAḊiȯ⁾00µe?€⁾AZj”:
Try it online!
$endgroup$
Jelly, 24 bytes
«"⁾PMµØAḊiȯ⁾00µe?€⁾AZj”:
Try it online!
answered Jan 5 at 20:12
Erik the OutgolferErik the Outgolfer
31.5k429103
31.5k429103
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%2f178356%2fclock-transliterate-cipher%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Related
$endgroup$
– Kevin Cruijssen
Jan 4 at 7:40
$begingroup$
Is it allowed to output
[7, ":", 8, ":", "00", ":", 1, ":", 14, ":", 1]
forhi bob
, or must one join the result? By the way, neat cipher!$endgroup$
– Mr. Xcoder
Jan 4 at 9:27
$begingroup$
@Mr.Xcoder Sorry, for the sake of the cipher theme I'd say it should be joined to a single string (or the entire thing as a list of characters like
['7', ':', '8', ':', '0', '0', ':', '1', ':', '1', '4', ':', '1']
).$endgroup$
– Kevin Cruijssen
Jan 4 at 9:32