NaNoGenMo / 2019

National Novel Generation Month, 2019 edition.
97 stars 5 forks source link

Ladder (#NNGM) #130

Open everestpipkin opened 4 years ago

everestpipkin commented 4 years ago

Ladder

fs=require('fs');fs.readFile('t','utf8',(e,t)=>{fs.readFile('i',(e,i)=>{a=[];e=t.match(/(\w+)/gm);u=w=0;for(x of i.values()){if(x>31){w=w+x}else{a.push(w);w=0}}for(;u<a.length;u++){for(k=0;k<e.length;k++){g=y=0;for(;y<e[k].length;y++){g=g+e[k][y].charCodeAt(0)}if(a[u]==g){a[u]=e[k];break}}}console.log(a.join(" "))})})

To run, this code needs two files in the same directory - any plaintext file named "t" and any other data format named "i". (I'd suggest a big file "t" (the more words the better), a small file "i" (it gets slow at about 1.5 mb, but you can always wait it out), and I think file "i" is interesting as an image, personally, but anything'll do).

Ladder is written in node.js.

Screen Shot 2019-11-29 at 2 32 56 AM

This was an attempt at a nanonanogenmo, but at 321 bytes I overshot the character limit by 65. I probably could go back through in something a bit more terse, but I'm! not! feeling it! :)

The program reads in file 'i' as a data buffer, then goes through and extracts byte values, adding them into larger numbers (which are delineated by the ascii control characters, 0-31). It then does the same to the individual words in file "t", separated on word boundaries. Finally, it attempts to match the two arrays of values, showing you the content of your file "i" as a poem made of words from "t".

Ladder is a little exercise in exposing the mushy insides of file encoding (and perhaps imaging some alternative encoding formats that lean into their own forms of poeticism). Try running different types of files through it, or files exported from different programs!

Screen Shot 2019-11-29 at 2 08 05 AM

Here is a longer version that outputs to a .txt file and adds a little title, clocking in at an extravagant 453 bytes:

fs=require('fs');fs.readFile('t','utf8',(e,t)=>{fs.readFile('i',(e,i)=>{a=[];e=t.match(/(\w+)/gm);u=w=0;for(x of i.values()){if(x>31){w=w+x}else{a.push(w);w=0}} for(;u<a.length;u++){for(k=0;k<e.length;k++){g=y=0;for(;y<e[k].length;y++){g=g+e[k][y].charCodeAt(0)}if(a[u]==g){a[u]=e[k];break}}}fs.writeFile('o.txt',"running ladder on "+t.split(".")[0]+"\n\n on a file with a buffer length of "+i.length+"\n\n\n\n\n\n\n\n\n\n"+a.join(" "),(e)=>{});});});

Sample output: o.txt Which is running this Project Gutenberg book On this image from the Miracle of the Sun. i

hugovk commented 4 years ago

Please could you share an example of a full "novel"?

everestpipkin commented 4 years ago

done, thanks!