7
\$\begingroup\$

Your task is to convert non-empty strings - between strings using the 26 letters, and programs, which are strings of bytes, where each byte has 256 possible values. You should use the same codepage your answer is written in for the possible values of bytes.

You need to do the following to do the conversion:

  • Convert the letters to numbers 1-26.
  • Treat it as a base 26 bijective numeration number to convert it to a positive integer.
  • Convert it to base 256 using 1-256, again using bijective numeration.
  • Turn it to bytes, where i turns to the byte with value i-1.

For example, for the string hello, you start with converting it to [8, 5, 12, 12, 15], then you evaluate \$15 + 12\cdot26 + 12\cdot26^2 + 5\cdot26^3 + 8\cdot26^4 = 3752127\$. Then you convert \$3752127 = 191 + 64\cdot256 + 57\cdot256^2\$, so the answer is [56, 63, 190].

However, you dislike gibberish. You want your code to be a concatenation of English words. You can't do that directly in your code, so instead you'll do that in its base26 representation.

Rules

  • Your code, when converted to base 26 using bijective numeration, has to be a concatenation of English words from this wordlist, with 1 or 2 letter words removed, except for a, i, of, to, in, is, on, by, it, or, be, at, as, an, we, us, if, my, do, no, he, up, so, pm, am, me, go, ok, hi.
  • You can choose whether you want your input to have lowercase or uppercase letters, but it has to be consistent.
  • Your input has to be a string, an array of characters or an array of bytes - you can't take an array of numbers from 1 to 26, for example.
  • Your output has to be a string, an array of characters, an array of bytes, or an array of numbers from 0 to 255.
  • Standard loopholes are disallowed.
  • If your language uses a base which isn't 256 then use that base, as long as it isn't a power of 26. If it is that language can't compete.

Test cases

input string -> array of bytes
hi -> [216]
iw -> [0, 0]
sr -> [0, 255]
cat -> [7, 25]
crxq -> [255, 0]
cshl -> [255, 255]
cshm -> [0, 0, 0]
hello -> [56, 63, 190]
helloworld -> [39, 138, 176, 111, 2, 107]
apple -> [10, 110, 12]
loremipsumdolorsitamet -> [81, 108, 15, 236, 169, 234, 61, 72, 24, 166, 102, 147, 49]

Scoring

Your score is the length of your program, encoded in base 26. This is , so the shortest answer in each language wins.

\$\endgroup\$
10
  • 2
    \$\begingroup\$ Please show an example of how to apply the first rule: some code and what the code looks like converted to base 26 using bijective numeration. \$\endgroup\$ Nov 12 at 16:58
  • 1
    \$\begingroup\$ Please also explain why \$57\cdot256^2 + 64\cdot256 + 191\$ yields [56, 63, 190] rather than [57, 64, 191]. Does that imply that byte 255 becomes 254? \$\endgroup\$ Nov 12 at 17:40
  • 1
    \$\begingroup\$ Have you solved this yourself yet? From an initial attempt, this seems hard. Writing a program that meets the spec is relatively easy; modifying it to have a ‘literate’ reverse translation seems really hard. \$\endgroup\$ Nov 12 at 19:22
  • \$\begingroup\$ If my programs contains non-letters, how do I represent them using base 26? \$\endgroup\$
    – corvus_192
    Nov 12 at 20:32
  • 2
    \$\begingroup\$ @doubleunary without using a bijective system a program would have the same value as itself with any or all leading zero-bytes removed, but these are clearly different programs. \$\endgroup\$ Nov 13 at 0:11

1 Answer 1

7
\$\begingroup\$

Jelly, score 23

The bijective base \$26\$ program as words:

yrs seo dts i am a be in cpu sap

The Jelly code:

ÑÞ²¶O_96ḅ26ḃ⁹’

Try it online!

Raw bytes as integers \$[1,256]\$:

[17, 21, 131, 128, 80, 96, 58, 55, 213, 51, 55, 232, 138, 254]

Converted from base \$256\$:

346505452333233856289746614520574

Converted to bijective base 26:

[25, 18, 19, 19, 5, 15, 4, 20, 19, 9, 1, 13, 1, 2, 5, 9, 14, 3, 16, 21, 19, 1, 16]

As characters, and then with spaces added to show the dictionary words used:

yrsseodtsiamabeincpusap
yrs seo dts i am a be in cpu sap

See this process starting with the Jelly code.

How?

The first part, up to the is filler to ensure we get a valid intermediate string, the is equivalent to a newline and separates Links, and execution of Jelly programs start at the final Link. Since the final Link (O_96ḅ26ḃ⁹’) is not calling the previous one (ÑÞ²) and the full program parses without error, the final Link is called with an input of the input string as a list of characters:

O_96ḅ26ḃ⁹’ - Link: list of characters
O          - ordinals
 _96       - subtract 96 from each
    ḅ26    - convert from base 26
       ḃ⁹  - convert to bijective base 256
         ’ - decrement each

I also tried these suffixes (some will only work with upper case input):

¶O%32ḅ26ḃ⁹’
¶O%48ḅ26ḃ⁹’
¶O%64ḅ26ḃ⁹’
¶O_64ḅ26ḃ⁹’
¶Oạ64ḅ26ḃ⁹’
¶Oạ96ḅ26ḃ⁹’

There are many more that could be tried (like using unused code-page entires like q to create a new Link, or making a single Link that has some sort of no-op at the start etc.), so there may be terser out there.

\$\endgroup\$
4
  • \$\begingroup\$ Very nice. Did you brute force this or was there another way? I tried using four letter words working from the right but found I was exponentially increasing the length of the code and was never going to have a completely literate answer. \$\endgroup\$ Nov 12 at 22:29
  • 3
    \$\begingroup\$ Brute force, effectively adding bytes in front of ¶O_96ḅ26ḃ⁹’ by starting with \$155122069311789175973382910\$ and adding \$256^{11}\$ until the bijective base \$26\$ string was valid (by recursively removing words). \$\endgroup\$ Nov 12 at 22:33
  • \$\begingroup\$ In the explanation it's supposed to be "convert to bijective base 256", not 26, right? \$\endgroup\$ Nov 13 at 0:45
  • \$\begingroup\$ @CommandMaster yes, thanks! \$\endgroup\$ Nov 13 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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