14
1
Now, we all know most languages have very simple ways to "self-modify" code. However, what if you were to actually modify the code and edit parts of it...on disk?
Your goal is to make code that prints a number, then edits its own file to replace the number with the next one in the Fibonacci sequence like so:
$ ./program
1
$ ./program
1
$ ./program
2
$ ./program
3
$ ./program
5
[etc...]
Rules
- You may not store the number(s) "outside" of the code. No comments, no telling the script to exit, no EOF, etc.
- If your code works with any filename, subtract 2 from your byte amount and write
$BYTESNOW ($ORIGINALBYTES - 2)
in your title. (Filenames are assumed to be within the range of any alphanumeric file path.) - Your code must write the output to the file on it's own, without any external piping assistance.
- Your code can start from one or zero. It doesn't matter.
8
Next time, please post your idea in the Sandbox instead and leave the post there for a few days to receive feedback.
– JungHwan Min – 2017-01-22T01:50:27.6632Is it allowed to call the program by invoking the interpreter of the programming language (e.g.
perl6 program
), or does it have to include the shebang line so that it can be called as./program
? – smls – 2017-01-22T11:37:52.4731Also, if we don't want to go for the -2 bytes bonus, can we choose a single-byte filename or does it have to be
program
, and can we assume it's located in the current working directory? – smls – 2017-01-22T11:44:33.970Can it be allowed to fail when large numbers begin implicitly converting to exponential notation? – Patrick Roberts – 2017-01-22T18:40:58.633
Why only 2 bytes bonus? Most languages, Eg. Lua, have it easier just to do
"a"
instead ofarg[0]
. It doesn't seem worth it. – ATaco – 2017-01-22T22:20:10.757@ATaco I just used the bonus even though not using it would be shorter. It seems less "cheaty" that way, because you're not assuming anything. – Patrick Roberts – 2017-01-22T22:42:07.790