-1
\$\begingroup\$

Given a string of text that contains lowercase letters, encode it as follows: (I will be using abcdef)

  • First, encode the alphabet cipher, but this time, 0-indexed. 000102030405
  • Reverse it. 504030201000
  • Loop through the string.
    • If the next two digits together are 25 or smaller, encode those two numbers. 5 04 03 02 01 00 0
    • Otherwise, encode one number. f e d c b a a
  • Join. fedcbaa

Test cases

abcdef                          fedcbaa
abcdefghijklmnopqrstuvwxyz      fyxwvucjsrqponmlktihgfedcbaa
helloworld                      dbromylloha
ppcg                            gcfpb
codegolf                        fboqedema
programmingpuzzlesandcodegolf   fboqedemddkiobpzuzqdscmkhqerpb

Encoder (not golfed)

Remember, this is , so the code with the fewest bytes wins.

\$\endgroup\$
  • 1
    \$\begingroup\$ I get different answers for some of the test cases. For example, codegolf becomes 0214030406141105, reversing to 5011416040304120, split as 5,01,14,16,04,03,04,12,0 turning into fboqedema instead of fbobgedema as you have. \$\endgroup\$ – Gabriel Benamy Nov 6 '16 at 23:50
  • \$\begingroup\$ @GabrielBenamy Fixed. Thank you for telling me. \$\endgroup\$ – Oliver Ni Nov 7 '16 at 1:39
1
\$\begingroup\$

Perl, 73 + 2 = 75 bytes

Run with the -lp flag

s/./sprintf"%02d",-97+ord$&/eg;$_=reverse;s/2[0-5]|[01]?[0-9]/chr$&+97/eg
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.