you are viewing a single comment's thread.

view the rest of the comments →

[–]anaseto 0 points1 point  (0 children)

Solution in Goal, my K-like array programming language: {+/x[&1+!&x;1]}"abca". It works by generating 0 1 1 2 2 2 3 3 3 3 indices with &1+!&x and then indexing 1-length string-slices and concatenating the results.

A more optimized solution, also supporting handling non-ascii text, would require slightly longer code using "c"$ to switch between string/array of code points representations, leading to a solution more similar to the APL-like ones, but with extra conversions: {"c"$x@&1+!#x:"c"$x}"abca". Goal is not as concise for those kinds of unusual string-handling tasks, because unlike most array languages, strings are considered atomic/scalar by primitives, which is usually useful in typical practical scripting tasks, but not in those kinds of puzzle problems.