7
\$\begingroup\$

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] 87
‮14*21
[1] 294
‮91/7
[1] 13
‮12-21
[1] -9

rules:

  • 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"

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).
\$\endgroup\$
5
  • 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
    Sep 17 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
    Sep 17 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
    Sep 17 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
    Sep 17 at 14:40
  • 2
    \$\begingroup\$ @Kaddath programming-puzzle is on-topic here. \$\endgroup\$
    – qwr
    Sep 17 at 18:20
7
\$\begingroup\$
options(prompt="\U202E")

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".

\$\endgroup\$
1
  • \$\begingroup\$ This was the answer I had intended! Well done! \$\endgroup\$
    – JDL
    Sep 19 at 10:14
2
\$\begingroup\$

R, 28 bytes

Sys.setlocale("LC_ALL","ja")

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

\$\endgroup\$
9
  • \$\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
    Sep 17 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
    Sep 17 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
    Sep 17 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
    Sep 17 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
    Sep 17 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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