Here's a neat test of programming language expressiveness: Can you write a function PrintXY taking an integer n>=0 that prints all strings of length n containing only the characters 'X' and 'Y'? Can you do it without recursion, and without assuming n<=64? Is it readable?
-
-
There are many interesting solutions in this thread. The C and JavaScript solutions seen akin to mechanical devices that crank out solutions. One is an astonishingly short Haskell composition of library functions:https://twitter.com/tikhonjelvis/status/1265453175219183616?s=20 …
Show this thread -
There is generally a barrier to reading these solutions. In one case you have to run through the behavior of imperative code in your head to understand what it does. In another you have to understand the near magical incantation of pointfree function compositions.
Show this thread -
The more a solution can resemble a simple recitation of the problem to be solved, and rely on the compiler to generate the code, the better for ease of reading and writing code.
Show this thread
End of conversation
New conversation -
-
-
Bash brace expansion and printf let you do this in one line, but the intuition definitely doesn't come as naturally :P Echo and evaluate something like $(printf "%s" '{x..y}'{(n commas)} ) and you're good.
-
Ah yes, and regular expressions provide a miniature functional logic language themselves!
End of conversation
New conversation -
-
-
Mathematica feels almost designed for these obscure problems. Zero import statements required here: printXY[n_] := StringJoin /@ Tuples[{"X", "Y"}, n] Output is prettier as printXY[n_] := StringJoin /@ Tuples[{"X", "Y"}, n] // ColumnForm
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I don’t know why I was insane enough to read all that. Maybe it sparked my interest in coding to come back.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
And this long thread of weird tweets is sponsored by Apple
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.