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?
[1] 87
[1] 294
[1] 13
[1] -9


  • 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, library etc..).
  • Al didn't type cat("55+23\n[1]......-9"), it is something that could reasonably be interpreted as "setting up an R session"


  • 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 to puzzling.stackexchange.com rather than here, where whe are supposed to answer with code with a winning criterion? \$\endgroup\$
    – Kaddath
    Commented Sep 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
    Commented Sep 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
    Commented Sep 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
    Commented Sep 17, 2021 at 14:40
  • 3
    \$\begingroup\$ @Kaddath programming-puzzle is on-topic here. \$\endgroup\$
    – qwr
    Commented Sep 17, 2021 at 18:20

2 Answers 2


Uses RTL 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
    Commented Sep 19, 2021 at 10:14

R, 28 bytes


Try it online! (doesn't work)

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
    Commented Sep 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
    Commented Sep 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
    Commented Sep 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
    Commented Sep 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
    Commented Sep 17, 2021 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.