Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ladder (#NNGM) #130

Open
everestpipkin opened this issue Nov 29, 2019 · 2 comments
Open

Ladder (#NNGM) #130

everestpipkin opened this issue Nov 29, 2019 · 2 comments

Comments

@everestpipkin
Copy link

everestpipkin commented Nov 29, 2019

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
Copy link
Member

hugovk commented Nov 29, 2019

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

@hugovk hugovk added the preview label Nov 29, 2019
@everestpipkin
Copy link
Author

done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants