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.
perl6 program
), or does it have to include the shebang line so that it can be called as./program
? \$\endgroup\$program
, and can we assume it's located in the current working directory? \$\endgroup\$"a"
instead ofarg[0]
. It doesn't seem worth it. \$\endgroup\$