Al wanted to use my computer to do some simple calculations, so I lent him the use of my R terminal for a bit. He complained though, saying it wasn't set up how he liked it. I said "No problem Al, set it up how you like and I'll just revert it later." This suited Al, and I left him to it. Al isn't a big fan of online R implementations like TIO, they don't seem to support his preferred way of coding.
After a few minutes, I came back and asked how it went. "everything fine", he said. I glanced at his session and it didn't look fine to me — only one of the four results looked correct! But Al knows R inside out, he must have been telling the truth.
Here is a transcript of Al's R session, as it appeared on the screen (Al uses RStudio 1.1.463 and R 3.6.3 if it matters, but I don't think it does here). The question is, how did Al "set up" his session to produce this output?
## what did Al type here?32+55[1] 8714*21[1] 29491/7[1] 1312-21[1] -9rules:
- Al only typed one function call which is somewhere in the standard R libraries.
- the function didn't import any code or refer to any external files (no
source,install.packages,libraryetc..). - Al didn't type
cat("55+23\n[1]......-9"), it is something that could reasonably be interpreted as "setting up an R session"
scoring:
- the primary scoring criterion is the number of bytes in the answer. Ties will be broken in ASCII-order, that is, if two valid answers are the same length the winner is the one which is first "alphabetically" (according to ASCII ordering).
- 3\$\begingroup\$I think it belongs topuzzling.stackexchange.com rather than here, where whe are supposed to answer with code with a winning criterion?\$\endgroup\$Kaddath– Kaddath2021-09-17 13:53:40 +00:00CommentedSep 17, 2021 at 13:53
- \$\begingroup\$Fair enough --- this works as a code-golf, so have changed to that. There are multiple possible answers, I think.\$\endgroup\$JDL– JDL2021-09-17 14:03:04 +00:00CommentedSep 17, 2021 at 14:03
- \$\begingroup\$Before I spoil the answer to other people that know R, does what you have in mind work in TIO? I have tried something but it seems they disabled the support for this in TIO..\$\endgroup\$Kaddath– Kaddath2021-09-17 14:37:09 +00:00CommentedSep 17, 2021 at 14:37
- 1\$\begingroup\$@Kaddath my intended solution doesn't work in TIO, which disables many of the functions you might use to customise your R session. I will add that to the question, though so thanks for trying TIO!\$\endgroup\$JDL– JDL2021-09-17 14:40:13 +00:00CommentedSep 17, 2021 at 14:40
- 3\$\begingroup\$@Kaddathprogramming-puzzle is on-topic here.\$\endgroup\$qwr– qwr2021-09-17 18:20:56 +00:00CommentedSep 17, 2021 at 18:20
2 Answers2
options(prompt="\U202E")UsesRTL Override at the end to make all following input appear reversed. I tried entering the raw character in a string but it turns into a period for some reason. Tested with RStudio 1.2.1335 and R 3.6.3 on Ubuntu 20.04, but does not work in my terminal GNOME Terminal 3.36.2 which appears to do some kind of character stripping unless the character is printable. Note that default R prompt is "> " which works in GNOME Terminal and can be replicated to make it less suspicious.
Also Al and R sound like "L" and "R".
- \$\begingroup\$This was the answer I had intended! Well done!\$\endgroup\$JDL– JDL2021-09-19 10:14:13 +00:00CommentedSep 19, 2021 at 10:14
R, 28 bytes
Sys.setlocale("LC_ALL","ja")I give it a try even if I don't know R and cannot test it on my computer.. If this doesn't work, please tell me and I will delete the answer, because it spoils the trick Al used
- \$\begingroup\$I don't think this would work; it is an attempt to set the locale to Japanese, which could definitely be interpreted as "setting up your R session", but wouldn't explain why the numeric output was the way it was.\$\endgroup\$JDL– JDL2021-09-17 15:04:30 +00:00CommentedSep 17, 2021 at 15:04
- \$\begingroup\$@JDL because it's a right to left language, as I told, I suspected it wouldn't work like this\$\endgroup\$Kaddath– Kaddath2021-09-17 15:06:57 +00:00CommentedSep 17, 2021 at 15:06
- \$\begingroup\$I see --- it might work, my own computer refused to change the locale ("Warning message:In Sys.setlocale("LC_ALL", "ja") : OS reports request to set locale to "ja" cannot be honored") so I can't really test it. will see if any other users are able to verify (or otherwise). I hadn't realised Japanese was right-to-left; I thought it was top-to-bottom.\$\endgroup\$JDL– JDL2021-09-17 15:10:33 +00:00CommentedSep 17, 2021 at 15:10
- \$\begingroup\$Don't worry too much that this spoils the "trick" of the question --- it's the more interesting part of the challenge how to achieve this with R's base library anyway (though you could use spoiler tags if you wanted to)\$\endgroup\$JDL– JDL2021-09-17 15:12:45 +00:00CommentedSep 17, 2021 at 15:12
- \$\begingroup\$@JDL yes it's top to bottom, then right to left for the columns. Used this because I found on a SO answer saying that it worked for hebrew (while hebrew locale didn't)\$\endgroup\$Kaddath– Kaddath2021-09-17 15:14:18 +00:00CommentedSep 17, 2021 at 15:14
Explore related questions
See similar questions with these tags.

