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.

  • 9
    \$\begingroup\$ so just echo $@>x and cat x is valid? \$\endgroup\$ – Adám Jul 5 '18 at 23:30
  • 1
    \$\begingroup\$ Your spec doesn't mention the ability to store multiple times, but you do have an example case that does so. May we assume a clean environment for each invocation of Store? \$\endgroup\$ – Adám Jul 5 '18 at 23:40
  • 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 Jul 5 '18 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 Jul 6 '18 at 0:18
  • 3
    \$\begingroup\$ Somebody needs to write an answer for a computer with magnetic-core memory. \$\endgroup\$ – Mark Jul 6 '18 at 23:30

40 Answers 40


Sed, 2+2 bytes:

Stores to file f:


Reads from file f:


Try a demo online!


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 Jul 6 '18 at 11:38
  • \$\begingroup\$ @Ferrybig How's that \$\endgroup\$ – SomeShinyMonica Jul 6 '18 at 12:48
  • \$\begingroup\$ Wouldn't Read-Host >t and gc t be sufficient? \$\endgroup\$ – whatever Jul 6 '18 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 Jul 6 '18 at 14:05
  • \$\begingroup\$ @JaredK So now that I have revised, this is correct now right? \$\endgroup\$ – SomeShinyMonica Jul 6 '18 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.


JavaScript (Node.js), 129 bytes

Store, 78 bytes


Retrieve, 51 bytes



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!


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.