Your Programs:

You'll write two programs (both in the same language). The storage program takes a string from STDIN and stores it somewhere persistent (see below) and then exits without error. The retrieval program takes no input, retrieves the string that was stored, and prints it to STDOUT.

Objective test of Persistence:

You should be able to run the storage program on your local machine, then power-cycle your local machine, then call the retrieval program on your local machine. You can stash the string however you want (even on the web) as long as you pass this reboot test.

Test Cases:

Storage then retrieval:

echo foo | Store

Repeated Stores should overwrite (like a set() method):

echo foo | Store
echo bar | Store

Repeated Retrieval is non-destructive (like a get() method):

echo foo | Store

Retrieval before any invocation of Storage:

You don't need to worry about this. Your retrieval program can assume that the storage program has been run at some point in the past.

Input/Output flexibility.

People have asked me to expand this from strict STDIN/STDOUT to the standard IO rules. I can't because it would introduce too many loopholes. Some standard IO options already have the input stored in a persistent way, eg "programs may take input from a file". I'd like to be more flexible than just strict STDIN and STDOUT, but without opening the floodgates.

From the standard IO rules thread I'm cherry-picking the ones that don't break the challenge:

If you use an alternate it must be user-interactive. The user shouldn't have to do any other work besides piping their input to your program, typing it into a prompt your program provides, or typing input as a command-line-arg of your program. The user shouldn't have to do anything other than running your retrieve program to see the output displayed on screen or sent to STDOUT or STDERR.

Allowed assumptions:

  • Your two programs will be run in the same directory
  • Your programs have read-write permissions for that directory
  • Files you create will survive the reboot (not in a temp dir)
  • One trailing newline that wasn't part of the string is allowed. No other trailing whitespace

This is code-golf, and your score is the sum of bytes from both programs.

  • 1
    \$\begingroup\$ You can stash the string however you want (even on the web) I'm not pretty sure that this should be valid. \$\endgroup\$ Commented Jul 5, 2018 at 23:26
  • 9
    \$\begingroup\$ so just echo $@>x and cat x is valid? \$\endgroup\$
    – Adám
    Commented Jul 5, 2018 at 23:30
  • 4
    \$\begingroup\$ @EriktheOutgolfer Why would it not be valid? Even if there is a loophole discussed on meta that doesn't prevent a challenge from specifically allowing it. \$\endgroup\$
    – dylnan
    Commented Jul 5, 2018 at 23:45
  • 6
    \$\begingroup\$ Web restrictions are usually about pulling stuff from the web as a loophole to get out of doing the work of creating that stuff. In this case, if it's on the web it's because you did the work of putting it there. \$\endgroup\$
    – Jared K
    Commented Jul 6, 2018 at 0:18
  • 3
    \$\begingroup\$ Somebody needs to write an answer for a computer with magnetic-core memory. \$\endgroup\$
    – Mark
    Commented Jul 6, 2018 at 23:30

41 Answers 41


JavaScript (Node.js), 129 bytes

Store, 78 bytes


Retrieve, 51 bytes



Batch - 11 Bytes

type f

The input is received as a command-line argument and persists (with the error message created upon execution attempt, since CMD attempts to execute the parameter) in f.

Batch - 7 Bytes (non-competitive)


There are a plethora of invalid characters in a file name, so this wouldn't work for some strings, but this essentially saves an arbitrary character to the filename given by the parameter. To read it, it just lists all files in the directory, including our string.

  • 1
    \$\begingroup\$ Your solution appears to output on STDOUT, which is valid. STDERR is just another option, not required. The quotes around the input don't stop it from competing. The only question is whether they should be counted in your byte count. I think not, since they aren't specific to the question. They seem like standard boilerplate for Batch to take a command line arg, which isn't so different from languages that need standard command line flags. Maybe someone else with Batch knowledge will chime in. For now leave them out of the byte count. Welcome to Code Golf! :) \$\endgroup\$
    – Jared K
    Commented Jul 24, 2018 at 16:41

SmileBASIC (v3+), 23 + 14 = 37 bytes

Simple filesystem-based answer. Works in all known SmileBASIC environments v3.x or above. Be careful, in case you happen to have an important text file named A!

Store, 23 bytes


Retrieve, 14 bytes


SmileBASIC (v2), 21 + 16 = 37 bytes

Adjusted to work on old SmileBASIC (Petit Computer/mkII for DSi).

Store, 21 bytes


Retrieve, 16 bytes


I'm honestly kinda amazed both versions work out to the same total byte count.


Cgam, 7 bytes

Store, 4 bytes


Retrieve, 3 bytes


Unfortunately, there is not yet a web interpreter, all you can do is download the code, build it, and run it yourself...


Powershell | 26 bytes

Store (store.ps1 | 24 bytes)


Retrieve (retrieve.ps1 | 2 bytes)




# close powershell, reboot
# open new Powershell

  • 1
    \$\begingroup\$ The question asks for storing input from STDIN, not the arguments \$\endgroup\$
    – Ferrybig
    Commented Jul 6, 2018 at 11:38
  • \$\begingroup\$ @Ferrybig How's that \$\endgroup\$ Commented Jul 6, 2018 at 12:48
  • \$\begingroup\$ Wouldn't Read-Host >t and gc t be sufficient? \$\endgroup\$
    – whatever
    Commented Jul 6, 2018 at 13:29
  • \$\begingroup\$ my bad about arguments vs STDIN. I said STDIN in the challenge description but then showed arguments in the example cases. It's fixed now. \$\endgroup\$
    – Jared K
    Commented Jul 6, 2018 at 14:05
  • \$\begingroup\$ @JaredK So now that I have revised, this is correct now right? \$\endgroup\$ Commented Jul 6, 2018 at 14:09

Java 8, 156 bytes

Both solutions are lambdas taking empty input and throwing java.io.IOException.

Store (93 bytes)

import java.nio.file.*;


Retrieve (63 bytes)

import java.nio.file.*;


NodeJS (REPL) v10.0.0, 57 bytes

Store: fs.writeFileSync("a",process.args)

Read: fs.readFileSync("a")+[]


Mathematica, 23 bytes


Put[], abbreviated >> as an infix operator, receives an expression as its left operand, then writes that expression to the filespec given in its right operand, here the file a. InputString[] interactively (graphically or textually, depending on how the kernel is being accessed) receives a string and returns that expression. This store program is 18 bytes.


Get[], abbreviated << as a prefix operator, reads the file specified by its right argument, evaluating each expression in it, then returns the last such expression. This retrieval program is 5 bytes.

You can use Directory[] to find out where the file is stored. The representation stored in the file is quoted, so is equivalent to an expression representing a string.


Pascal (95+92=187)


program i;var f:Text; s:string;begin Assign(f,'i');Rewrite(f);Read(s);Write(f,s);Close(f);end.


program o;var f:Text;s:string;begin Assign(f,'i');Reset(f);Read(f,s);Write(s);Close(f);end.

You can omit Close(f); in retrive and shorten it a little bit, but, not in a spirit of pascal!


Yabasic, 36+38=74 bytes

Two scripts that write to the file t in the current directory. TIO Link provided both the getter and setter in both cases





Try it online!


HP‑41C series, 16 B

The alpha‑register (α‑register) can store up to 24 alphabetic characters. The contents of the α‑register are persistent. You can turn the calculator off and on again, they remain there until overwritten.

01♦LBL "S"         5 Bytes    global label requires 4 + (length of string) Bytes
02 CLA             1 Byte     clear contents of α‑register
03 AON             1 Byte     activate alpha‑keyboard
04 PROMPT          1 Byte     display α‑register and stop program execution
05 RTN             1 Byte     `RTN` does not affect local label search

The CLA (clear alpha) command clears the contents of the α‑register. This is necessary in case of empty input. The subsequent PROMPT command does not change the α‑register in case there is no input at all.

The PROMPT displays the contents of the alpha‑register, and stops the program. The user can enter a string now. Once the R/S (run/stop) key is pressed (≘ end‑of‑file indicator), program execution resumes with the command following the PROMPT command.

01♦LBL "R"         5 Bytes    "S" like "store", "R" like "retrieve"
02 AVIEW           1 Byte     select the α‑register as the current display
03 RTN             1 Byte     this is cheaper than an `END` (3 Bytes)

Keep in mind, if in your program further calculations follow, the AVIEW (alpha view) command by itself does not stop program execution and allow the user to read the display. The AVIEW command is therefore usually paired with other commands such as STOP.

Note, if flag 21 (printer enable) is set, but there is no printer or the printer is off, AVIEW does in fact stop program execution (so the user has a chance to manually record display contents). To resume operations press R/S (run/stop).

Note, leading NULL Bytes cannot be stored and retrieved to and from the α‑register. Moreover, another implementation could use text files. Text files permit storing records of up to 254 alphabetic characters each.
See also HP‑49G RPL submission, a different pocket calculator by the Hewlett‐Packard Company.


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.