From 8ceeec19fdcf662f3ac02593944308cce33a15ac Mon Sep 17 00:00:00 2001 From: Nicholas Georgescu <36280690+NGeorgescu@users.noreply.github.com> Date: Tue, 14 May 2024 18:47:58 -0400 Subject: [golfscript/en-en] Add some nifty string tricks (#4945) --- golfscript.html.markdown | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/golfscript.html.markdown b/golfscript.html.markdown index 8ea985e8..f4b88a9f 100644 --- a/golfscript.html.markdown +++ b/golfscript.html.markdown @@ -242,7 +242,18 @@ I drive a stick, BTW. [] > '22222'{+}* # note that if you fold-sum a string not in an array, you'll # get the sum of the ascii values. '2' is 50, so five times that is: -250 +[250] +> ]; # this actually is a clever trick to get ascii values into an array. +[] +> "aabc" [{""+~}*] # if you fold over addition and drop it into a string: +[[97 97 98 99]] +> {[.]""^}%""+ # which can be returned to a string as such using a ""^ map. +# and an empty string join. +["aabc"] +> {32-}% # note that most mapping operations work on the ascii values as +# you would expect, for instance with the difference between A and a being +# 32, you can just subtract that from the ascii value to get: +["AABC"] > ]; ################################################################### # blocks ######################################################################## -- cgit v1.2.3