schamberg

Untitled

Aug 8th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //relies on .txt file, so check this GitHub repo:
  2. //https://github.com/schamberg97/redditBadCodeChallenges/tree/BadCodeCodingChallenge42
  3.  
  4. var alphabet = ['A', "B", "C", 'D', "E", "F", "G", "H", "I", "J", 'K', 'L', 'M', "N", "O", "P", `Q`, `R`, `S`, "T", "U", "V", "W", "X", "Y", "Z"] // the best solution. Truly.
  5. var randomPossiblyFakeQuoteIGoogledJustForThis = "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe."
  6. var fs = require('fs')
  7. const readline = require('readline');
  8.  
  9. function askQuestion(query) { // Yeah, I've just straight copied it from StackOverflow
  10.     return new Promise(resolve => {
  11.     const niceties = "[email protected] ~>  question"
  12.     console.log()
  13.     console.log(niceties)
  14.     console.log('Process PID: ' + process.pid) // So i know which bad boy to kill later, when I am bored from endless stream pausing and unpausing
  15.     console.log('Loading...')
  16.     setTimeout(() => {
  17.         console.log()
  18.         const rl = readline.createInterface({
  19.             input: process.stdin,
  20.             output: process.stdout,
  21.         });
  22.         rl.question(query, ans => {
  23.             rl.close();
  24.             resolve(ans);
  25.         })
  26.     }, 500)
  27.     })
  28. }
  29.  
  30. function wordCorrecter(str, num) { // stole from stack, 12 liines are way too much for me
  31.     str = str.toLowerCase();
  32.     var result = '';
  33.     var charcode = 0;
  34.     for (var i = 0; i < str.length; i++) {
  35.         charcode = (str[i].charCodeAt()) + num;
  36.         result += String.fromCharCode(charcode);
  37.     }
  38.     return result;
  39. }
  40.  
  41. async function THE_SHIT() {  // Yeah, i do not follow camelCase convention here
  42.     var callback = function(result) {console.log(result)}
  43.     const ans = await askQuestion("Please enter the parameters for the calculation: ");
  44.     life_universe_everything(ans, callback);
  45. }
  46.  
  47. function life_universe_everything(inp, callback) { //i do not follow camelCase convention here either
  48.            
  49.         var path = require('path') // Maybe I should have declared it elsewhere? Who knows....
  50.         var book = ''
  51.        
  52.         // Hitchhiker's Guide to The Galaxy is not in Public Domain. So let's pretend Leo Tolstoy's War And Peace IS the Hitchhiker's Guide to The Galaxy. I know it's hard, but you have to cooperate.
  53.         var bookStream = fs.createReadStream(path.resolve('./book.txt'), { highWaterMark: 1024 }) // only 1024 bytes at a time, see line 10. Original 128 bytes were considered to be too evil
  54.        
  55.         //Don't worry, Deep Thought ALSO needed some time to think ;)
  56.         // Seriously, though, change highWaterMark to something bigger or it will REALLY take a long time. Especially since War and Peace is big.
  57.  
  58.         bookStream.on('data', (chunk) => {
  59.             console.log(`Received ${chunk.length} bytes of data.`);
  60.             let data = chunk.toString()
  61.             book = book + data
  62.             bookStream.pause() // I AM REALLY SCARED OF OVERWHELMING MY CAMPUUUTAH, OKEY? MY COOLER IS FAILING, MY CPU MAY OVERHEAT
  63.             setTimeout(() => {
  64.                 bookStream.resume()
  65.             }, 1200)
  66.         });
  67.         bookStream.on('end', async () => {
  68.             book = book.toString() // I am confused, streams, buffers, etc.. Do i need to do .toString() ???
  69.             callback(doFurtherEvilStuff(book, randomPossiblyFakeQuoteIGoogledJustForThis))
  70.         });
  71.  
  72.         function l2n(l) {
  73.             let r = l.charCodeAt('boogey-wonderland') // entered nonsense. Just because I can.
  74.             if (r < 97 && l.length === 1) { // maybe the letter is even something beyond 'z'. I don't know. Do you?
  75.                 r = r - 64 // accounted for human-friendly counting of alphabet letters. I am evil, but I have standards. I can't be evil to myself
  76.             }
  77.             else if (l.length === 1) {
  78.                 r = r - 96
  79.             }
  80.             return r
  81.         }
  82.  
  83.         function doFurtherEvilStuff(book, randomPossiblyFakeQuoteIGoogledJustForThis) {
  84.             console.log('The computer finally got here and did not explode!')
  85.             var goodLetterNumberOne
  86.             var goodLetterNumberTwo
  87.             for (let n = book.length; n > 0; n--) {
  88.                 if (book[n] == "D" || book == 'd') {
  89.                     goodLetterNumberOne = book[n]
  90.                 }
  91.                 if (book[n] == "B" || book == 'b') {
  92.                     goodLetterNumberTwo = book[n]
  93.                 }
  94.             }
  95.             if (!(goodLetterNumberOne && goodLetterNumberTwo)) { // I am not sure there is no error here, was lazy to test
  96.                
  97.                 for (let n = randomPossiblyFakeQuoteIGoogledJustForThis.length; n > 0; n--) {
  98.                     if (randomPossiblyFakeQuoteIGoogledJustForThis[n] == "D" || randomPossiblyFakeQuoteIGoogledJustForThis == 'd') {
  99.                         goodLetterNumberOne = randomPossiblyFakeQuoteIGoogledJustForThis[n]
  100.                     }
  101.                     if (randomPossiblyFakeQuoteIGoogledJustForThis[n] == "B" || randomPossiblyFakeQuoteIGoogledJustForThis == 'b') {
  102.                         goodLetterNumberTwo = randomPossiblyFakeQuoteIGoogledJustForThis[n]
  103.                     }
  104.                 }
  105.             }
  106.             else {
  107.                 goodLetterNumberOne = alphabet[l2n('F')-3]; goodLetterNumberTwo = alphabet[l2n('x') - 23]
  108.             }
  109.             var numBears = [l2n(goodLetterNumberOne), l2n(goodLetterNumberTwo)]
  110.             numbers = numBears.join() // thanks God I don't 'use strict' mode. Otherwise the code would error out. Well, I am evil, this should not matter in any case
  111.             numbers = numbers.replace(',', '') // the first argument kind of looks like a smile doesn't it?
  112.             numbers = parseInt(numbers)
  113.             if (wordCorrecter(inp.toUpperCase(), 2) == 'uvctavtgm') {  // inflation stuff
  114.                 numbers = Math.ceil(numbers * 1.119)
  115.             }
  116.             return numbers
  117.         }
  118.  
  119. }
  120.  
  121. THE_SHIT()
Add Comment
Please, Sign In to add comment