Since no one posted a 05AB1E answer yet, I figured I'd post my own solution. I see now it's very similar to @Dennis♦' Jelly answer , even though I came up with it independently before I posted the challenge.
g3Ö # Check if the length of the (implicit) input is divisible by 3
# (results in 1 for truthy or 0 for falsey)
# i.e. "out" → 1
# i.e. "test" → 0
×ばつ # Repeat a space that many times
# i.e. 1 → " "
# i.e. 0 → ""
« # And append it to the (implicit) input
# i.e. "out" and " " → "out "
# i.e. "test" and "" → "test"
S # Then make the string a list of characters
# i.e. "out " → ["o","u","t"," "]
# i.e. "test" → ["t","e","s","t"]
A # Push the lowercase alphabet
ð« # Appended with a space ("abcdefghijklmnopqrstuvwxyz ")
3L # Push list [1,2,3]
3ã # Cartesian repeated 3 times: [[1,1,1],[1,1,2],...,[3,3,2],[3,3,3]]
© # Save that list of triplets in the registry (without popping)
‡ # Transliterate, mapping the letters or space to the triplet at the same index
# i.e. ["o","u","t"," "] → [[2,2,3],[3,1,3],[3,1,2],[3,3,3]]
# i.e. ["t","e","s","t"] → [[3,1,2],[1,2,2],[3,1,1],[3,1,2]]
ø # Zip, swapping all rows/columns
# i.e. [[2,2,3],[3,1,3],[3,1,2],[3,3,3]] → [[2,3,3,3],[2,1,1,3],[3,3,2,3]]
# i.e. [[3,1,2],[1,2,2],[3,1,1],[3,1,2]] → [[3,1,3,3],[1,2,1,1],[2,2,1,2]]
̃ # Flatten the list
# i.e. [[2,3,3,3],[2,1,1,3],[3,3,2,3]] → [2,3,3,3,2,1,1,3,3,3,2,3]
# i.e. [[3,1,3,3],[1,2,1,1],[2,2,1,2]] → [3,1,3,3,1,2,1,1,2,2,1,2]
3ô # Split it into parts of size 3
# i.e. [2,3,3,3,2,1,1,3,3,3,2,3] → [[2,3,3],[3,2,1],[1,3,3],[3,2,3]]
# i.e. [3,1,3,3,1,2,1,1,2,2,1,2] → [[3,1,3],[3,1,2],[1,1,2],[2,1,2]]
® # Push the triplets from the registry again
Að« # Push the lowercase alphabet appended with a space again
‡ # Transliterate again, mapping the triplets back to letters (or a space)
# (and output the result implicitly)
# i.e. [[2,3,3],[3,2,1],[1,3,3],[3,2,3]] → ["r","v","i","x"]
# i.e. [[3,1,3],[3,1,2],[1,1,2],[2,1,2]] → ["u","t","b","k"]
Since no one posted a 05AB1E answer yet, I figured I'd post my own solution.
g3Ö # Check if the length of the (implicit) input is divisible by 3
# (results in 1 for truthy or 0 for falsey)
×ばつ # Repeat a space that many times
« # And append it to the (implicit) input
S # Then make the string a list of characters
A # Push the lowercase alphabet
ð« # Appended with a space
3L # Push list [1,2,3]
3ã # Cartesian repeated 3 times: [[1,1,1],[1,1,2],...,[3,3,2],[3,3,3]]
© # Save that list of triplets in the registry (without popping)
‡ # Transliterate, mapping the letters or space to the triplet at the same index
ø # Zip, swapping all rows/columns
̃ # Flatten the list
3ô # Split it into parts of size 3
® # Push the triplets from the registry again
Að« # Push the lowercase alphabet appended with a space again
‡ # Transliterate again, mapping the triplets back to letters (or a space)
# (and output the result implicitly)
Since no one posted a 05AB1E answer yet, I figured I'd post my own solution. I see now it's very similar to @Dennis♦' Jelly answer , even though I came up with it independently before I posted the challenge.
g3Ö # Check if the length of the (implicit) input is divisible by 3
# (results in 1 for truthy or 0 for falsey)
# i.e. "out" → 1
# i.e. "test" → 0
×ばつ # Repeat a space that many times
# i.e. 1 → " "
# i.e. 0 → ""
« # And append it to the (implicit) input
# i.e. "out" and " " → "out "
# i.e. "test" and "" → "test"
S # Then make the string a list of characters
# i.e. "out " → ["o","u","t"," "]
# i.e. "test" → ["t","e","s","t"]
A # Push the lowercase alphabet
ð« # Appended with a space ("abcdefghijklmnopqrstuvwxyz ")
3L # Push list [1,2,3]
3ã # Cartesian repeated 3 times: [[1,1,1],[1,1,2],...,[3,3,2],[3,3,3]]
© # Save that list of triplets in the registry (without popping)
‡ # Transliterate, mapping the letters or space to the triplet at the same index
# i.e. ["o","u","t"," "] → [[2,2,3],[3,1,3],[3,1,2],[3,3,3]]
# i.e. ["t","e","s","t"] → [[3,1,2],[1,2,2],[3,1,1],[3,1,2]]
ø # Zip, swapping all rows/columns
# i.e. [[2,2,3],[3,1,3],[3,1,2],[3,3,3]] → [[2,3,3,3],[2,1,1,3],[3,3,2,3]]
# i.e. [[3,1,2],[1,2,2],[3,1,1],[3,1,2]] → [[3,1,3,3],[1,2,1,1],[2,2,1,2]]
̃ # Flatten the list
# i.e. [[2,3,3,3],[2,1,1,3],[3,3,2,3]] → [2,3,3,3,2,1,1,3,3,3,2,3]
# i.e. [[3,1,3,3],[1,2,1,1],[2,2,1,2]] → [3,1,3,3,1,2,1,1,2,2,1,2]
3ô # Split it into parts of size 3
# i.e. [2,3,3,3,2,1,1,3,3,3,2,3] → [[2,3,3],[3,2,1],[1,3,3],[3,2,3]]
# i.e. [3,1,3,3,1,2,1,1,2,2,1,2] → [[3,1,3],[3,1,2],[1,1,2],[2,1,2]]
® # Push the triplets from the registry again
Að« # Push the lowercase alphabet appended with a space again
‡ # Transliterate again, mapping the triplets back to letters (or a space)
# (and output the result implicitly)
# i.e. [[2,3,3],[3,2,1],[1,3,3],[3,2,3]] → ["r","v","i","x"]
# i.e. [[3,1,3],[3,1,2],[1,1,2],[2,1,2]] → ["u","t","b","k"]
g×ばつ«SAð«3L3㩇ø ̃3ô®Að«‡
Since no one posted a 05AB1E answer yet, I figured I'd post my own solution.
Input as string, output as a list of characters. Adds one space if the length is divisible by 3.
Try it online or verify all test cases.
Explanation:
g3Ö # Check if the length of the (implicit) input is divisible by 3
# (results in 1 for truthy or 0 for falsey)
×ばつ # Repeat a space that many times
« # And append it to the (implicit) input
S # Then make the string a list of characters
A # Push the lowercase alphabet
ð« # Appended with a space
3L # Push list [1,2,3]
3ã # Cartesian repeated 3 times: [[1,1,1],[1,1,2],...,[3,3,2],[3,3,3]]
© # Save that list of triplets in the registry (without popping)
‡ # Transliterate, mapping the letters or space to the triplet at the same index
ø # Zip, swapping all rows/columns
̃ # Flatten the list
3ô # Split it into parts of size 3
® # Push the triplets from the registry again
Að« # Push the lowercase alphabet appended with a space again
‡ # Transliterate again, mapping the triplets back to letters (or a space)
# (and output the result implicitly)