1

(376 replies, posted in Computers/programming/software)

Pretty sure I have everything right but there's some floating point imprecision fuckup going on >:/

 // Take the janky ass CID thing and turn it into
 // a fucking usable object >:|
 function transformersRobotsInDisguise(cid){
   let retObj = {};
   for (let i = 0; i < cid.length; i++){
     retObj[cid[i][0]] = cid[i][1];
   }
   return retObj;
 }
 function checkCashRegister(price, cash, cid) {
   let cidRef = transformersRobotsInDisguise(cid);
   let retObj = {};
   let status = "";
   let change = [];
   let totalChangeDue = cash - price;
   let totalCid = 0;
   let countValues = [];
   let cashValues = [100, 20, 10, 5, 1, .25, .10, .05, .01]; 
   let names = ["ONE HUNDRED", "TWENTY", "TEN", "FIVE", "ONE", "QUARTER",
                "DIME", "NICKEL", "PENNY"];
   let counterObj = {
     "ONE HUNDRED": 0, "TWENTY": 0, "TEN": 0, 
     "FIVE": 0, "ONE": 0, "QUARTER": 0, 
     "DIME": 0, "NICKEL": 0, "PENNY": 0
   }
   for (let i = 0; i < Object.keys(cid).length; i++){
     totalCid += Object.values(cid)[i][1];
     countValues.push(Object.values(cid)[i][1]);
   }
   countValues.reverse();
   if (totalCid < totalChangeDue){
     return {status: "INSUFFICIENT_FUNDS", change: []};
   }
   else if (totalCid == totalChangeDue){
     return  {status: "CLOSED", change: cid};
   }
   let currChangeDue = totalChangeDue;
   while(currChangeDue > 0){
     for (let i = 0; i < cashValues.length; i++){
       if ((cashValues[i] - currChangeDue) < 0){
         if (cidRef[names[i]] > 0){
           counterObj[names[i]] = counterObj[names[i]] + 1;
           cidRef[names[i]] = cidRef[names[i]] - cashValues[i];
           currChangeDue = currChangeDue - cashValues[i];
         }
       }
      }
   }
   for (let i = 0; i < names.length; i++){
      let store = counterObj[names[i]] * cashValues[i];
      //console.log(JSON.stringify(counterObj));
      if (store > 0){
        let arr = [names[i], store];
        change.push(arr);
      }
   }
      retObj.status = "OPEN";
      retObj.change = change;
   return retObj;
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

//let obj = checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

//let obj = checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

let obj = checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);// should return {status: "OPEN", change: [["QUARTER", 0.5]]};

console.log(JSON.stringify(obj));


REEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeee


what the fuck is this

// Take the janky ass CID thing and turn it into
 // a fucking usable object >:|
 function transformersRobotsInDisguise(cid){
   let retObj = {};
   for (let i = 0; i < cid.length; i++){
     retObj[cid[i][0]] = cid[i][1];
   }
   return retObj;
 }
 function checkCashRegister(price, cash, cid) {
   let cidRef = transformersRobotsInDisguise(cid);
   let retObj = {};
   let status = "";
   let change = [];
   let totalChangeDue = cash - price;
   let totalCid = 0;
   let countValues = [];
   let cashValues = [100, 20, 10, 5, 1, .25, .1, .05, .01]; 
   let names = ["ONE HUNDRED", "TWENTY", "TEN", "FIVE", "ONE", "QUARTER",
                "DIME", "NICKEL", "PENNY"];
   let counterObj = {
     "ONE HUNDRED": 0, "TWENTY": 0, "TEN": 0, 
     "FIVE": 0, "ONE": 0, "QUARTER": 0, 
     "DIME": 0, "NICKEL": 0, "PENNY": 0
   }
   for (let i = 0; i < Object.keys(cid).length; i++){
     totalCid += Object.values(cid)[i][1];
     countValues.push(Object.values(cid)[i][1]);
   }
   countValues.reverse();
   if (totalCid < totalChangeDue){
     return {status: "INSUFFICIENT_FUNDS", change: []};
   }
   else if (totalCid == totalChangeDue){
     return  {status: "CLOSED", change: cid};
   }
   let currChangeDue = totalChangeDue;
   while(currChangeDue > 0){
     for (let i = 0; i < cashValues.length; i++){
       // if bill amount - change due is negative
       if ((cashValues[i] - currChangeDue) < 0){
         // If we have enough of the given value in CID
         if (cidRef[names[i]] > 0){
           // increment number of a given bill / unit
           counterObj[names[i]] = counterObj[names[i]] + 1;
           let val = cidRef[names[i]] - cashValues[i];
           cidRef[names[i]] = Math.round(val * 100) / 100;
           let val2 = currChangeDue - cashValues[i];
           currChangeDue = Math.round(val2 * 100) / 100;
           console.log(currChangeDue);
         }
       }
      }
   }
   for (let i = 0; i < names.length; i++){
      let store = counterObj[names[i]] * cashValues[i];
      //console.log(JSON.stringify(counterObj));
      if (store > 0){
        let arr = [names[i], store];
        change.push(arr);
      }
   }
      retObj.status = "OPEN";
      retObj.change = change;
   return retObj;
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

//let obj = checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

//let obj = checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

let obj = checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);// should return {status: "OPEN", change: [["QUARTER", 0.5]]};

console.log(JSON.stringify(obj));
 function checkCashRegister(price, cash, cid) {
   let retObj = {};
   let status = "";
   let change = [];
   let totalChangeDue = cash - price;
   let totalCid = 0;
   let countValues = [];
   let cashValues = [100, 20, 10, 5, 1, .25, .10, .05, .01]; 
   let names = ["ONE HUNDRED", "TWENTY", "TEN", "FIVE", "ONE", "QUARTER",
                "DIME", "NICKEL", "PENNY"];
   for (let i = 0; i < Object.keys(cid).length; i++){
     totalCid += Object.values(cid)[i][1];
     countValues.push(Object.values(cid)[i][1]);
   }
   countValues.reverse();
   if (totalCid < totalChangeDue){
     return {status: "INSUFFICIENT_FUNDS", change: []};
   }
   else if (totalCid == totalChangeDue){
     return  {status: "CLOSED", change: cid};
   }
   let currChangeDue = totalChangeDue;
   while(currChangeDue > 0){
     for (let i = 0; i < cashValues.length; i++){
       if (currChangeDue <= cashValues[i] && currChangeDue > cashValues[i +         1]){
         console.log(currChangeDue);
         if (currChangeDue < 1 && currChangeDue >= .25){
           change.push(names[i + 1]);
           change.push(currChangeDue);
           retObj.status = "OPEN";
           retObj.change = [change];
           currChangeDue -= cashValues[i];
         }
         else{
           change.push(names[i]);
           change.push(currChangeDue);
           retObj.status = "OPEN";
           retObj.change = [change];
           currChangeDue -= cashValues[i];
         }
       }
     }
   }
   console.log(JSON.stringify(retObj));
   return retObj;
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

//checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

//checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

//checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

//checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);

I'm not even close to doing this correctly lmfao

3

(146 replies, posted in Advice)

find a seat and chill, if it's so packed there's nowhere to sit it's pretty awkward unless you have a group of people to hang out with and even then it's a bit awkward


i always try to find somewhere to sit down and stare at girls and chat


when I go to bars alone I just sit at the bar and hang out until someone eventually starts chatting me up, ordering drinks, maybe smalltalk with the bartender

Clusterfuck, but it works:

function telephoneCheck(str) {
  let ret = true;
  if (str.length > 16){
    return false;
  }
  let numCount = 0;
  let trimStr = str.replace(/ /g, '');
  let strArr = trimStr.split('');
  strArr.forEach(x => {
    if(isNaN(x) == true && x != "-" && x != "(" && x != ")"){
      console.log(x);
      ret = false;
    }
    if (!isNaN(x)){
      numCount++;
    }
    if (strArr.includes(")") && !strArr.includes("(")) ret = false;
    if (strArr.includes("(") && !strArr.includes(")")) ret = false;
    if (strArr[strArr.length - 1] == ")") ret = false;
  });
  console.log(numCount);
  if (numCount < 10 || numCount > 11) return false;
  if (numCount == 11){
    if (strArr[0] != 1) return false;
  }
  return ret;
}

//telephoneCheck("555-555-5555");
//console.log(telephoneCheck("123**&!!asdf#"));
//telephoneCheck("1 555-555-5555");
telephoneCheck("1 555)555-5555");

ONE MORE ALGORITHM TO GO BEFORE I FINISH UP MY FUCKING 300 HOUR DATA STRUCTURE AND ALGO CERTIFICATION ayy

Welp, that helped my confidence.

function rot13(str) { 
  let strArr = str.split('');
  let retMe = [];
  strArr.forEach(x => {
    let code = String.charCodeAt(x);
    if (code >= 65 && code <= 90){
      if (code <= 77){
        retMe.push(String.fromCharCode(code + 13));
      }
      else if(code >= 78){
        retMe.push(String.fromCharCode(code + 13 - 26));
      }
    }
    else retMe.push(x);
  });
  return retMe.join('');
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

Implemented Rot 13 in like 10 minutes, or less probably.

function convertToRoman(num) {
  let decimalCount = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 
                      5, 4, 1];
  let romanNumerals = ["M", "CM", "D", "CD", "C", "XC", "L", 
                      "XL", "X", "IX", "V", "IV", "I"]

  let shit = [];
  let count = num;
  for(let i = 0; i < decimalCount.length; i++){
    while (decimalCount[i] <= count){
      shit.push(romanNumerals[i]);
      count -= decimalCount[i];
    }
  }
  return shit.join('');
}

console.log(convertToRoman(798));

This one fucked me up. I did not get it on my own at all. I was writing a version that would have taken FOREVER to finish writing, like every 10 I had to write another if statement or something. Then I was trying to think of a way to do it by the 100 or something, but it changes too much per thing. I couldn't even really understand the solution until I read the solution and tested it and "debugged" it because it doesn't work in a way that was intuitive to me. Kind of disappointed in my brain but okay. Whatever. Plus I was trying to use an object instead of these two arrays, but objects are apparently unordered (and it's up to the browser how to order them), and you kind of have to interpret shit backwards.


Idk. I think if I spent many frustrating days on this I would have gotten it eventually but... Fuck that.

7

(1,970 replies, posted in Music & Art)

8

(13 replies, posted in General Talk)

Neuroticism apparently:

Sample items

    I get irritated easily.
    I get stressed out easily.
    I get upset easily.
    I have frequent mood swings.
    I worry about things.
    I am much more anxious than most people.[56]
    I am relaxed most of the time. (reversed)
    I seldom feel blue. (reversed)[40]

It's supposed to correlate with things like depression, anxiety, anger, low tolerance for stress, and that sort of thing... I assume anyone with an actual mental disorder like anxiety or depression would score high on this, though.

9

(1,970 replies, posted in Music & Art)

10

(1,970 replies, posted in Music & Art)

god I can't wait for summer

11

(1,970 replies, posted in Music & Art)

12

(376 replies, posted in Computers/programming/software)

Hey I'm getting pretty okay at this.

function palindrome(strorig) {
  let str = strorig.toLowerCase().replace(/[^a-z0-9]/g, "");
  let thing = str.split('');
  let thingReverse = str.split('').reverse().join('').split('');
  let j = str.length; 
  let x = false;
  let truthArray = [];
  for(let i = 0; i < str.length; i++){
    j--;
    if (thing[i] == thing[j]){
      truthArray.push(true);
    }
    else truthArray.push(false); 
  }
  if(truthArray.includes(false)) return false;
  else return true;
}


palindrome("_eye");

Not saying that's a great implementation but I'm tired as fuck and it only took me a little while to do. I think I'd fuck it up trying to white board it because I couldn't remember all the names of methods they build in but still.

13

(376 replies, posted in Computers/programming/software)

function orbitalPeriod(arr) {
  let realManArr = [];
  let realHumanArr = [];
  let retArray = [];
  arr.forEach(x => {
    realManArr.push(x.avgAlt);
    realHumanArr.push(x.name);
  }); 
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
  let twoPi = 2 * Math.PI;
  for (let i = 0; i < arr.length; i++){
    let a3 = Math.pow((earthRadius + realManArr[i]),3);
    let term = a3 / GM;
    let orbitalPeriod = Math.round(twoPi * Math.sqrt(term));
    retArray.push({"name": realHumanArr[i], "orbitalPeriod": orbitalPeriod});
  }
  return retArray;
}

orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]);

real man

14

(376 replies, posted in Computers/programming/software)

var Person = function(firstAndLast) {
  let arr = firstAndLast.split(' ');
  this.getFirstName = function() {
    return arr[0];
  };
  this.getLastName = function(){
    return arr[1];
  };
  this.getFullName = function(){
    return arr[0] + " " + arr[1];
  };
    this.setFirstName = function(newFirst){
    arr.splice(0, 1, newFirst);
  };
  this.setLastName = function(newLast){
    arr.splice(1, 1, newLast);
  };
  this.setFullName = function(newFirstAndLast){
    arr = newFirstAndLast.split(' ');
  };
  
  return firstAndLast;
};

var bob = new Person('Bob Ross');

15

(376 replies, posted in Computers/programming/software)

function addTogether(){
  let shit = [];
  if(arguments.length == 1){
    let first = arguments[0];
    if (typeof(first) == 'number'){
      return function(newArg){
        if (typeof(newArg) != 'number')
          return undefined;
        else {return newArg + first;}
      }
    }
    else{
      return undefined;
    }
  }
  for(let i = 0; i < arguments.length; i++){
    shit.push(arguments[i]);
  }
  let checkMe = 1;
  shit.forEach(x => {
    if (typeof(x) != 'number'){
      checkMe = -1;
    }
  });
  if(checkMe == -1) return undefined;
  else return shit.reduce((acc, newstuff) => (acc + newstuff));
}

addTogether(2)([3]);
addTogether(2, "3");
addTogether(2,3);

That was painful.

16

(376 replies, posted in Computers/programming/software)

function truthCheck(collection, pre) {
  let shit = [];
  collection.filter(x => shit.push(x[pre] != undefined && x[pre] != 0 
  && x[pre] != "" && !Number.isNaN(x[pre])));
  let thing = 0;
  shit.forEach(y => {
    if(y == true)
      thing++;
  });
  return thing == shit.length;
}

truthCheck([{"single": "double"}, {"single": NaN}], "single");

bloop

17

(376 replies, posted in Computers/programming/software)

loop city bitch

function binaryAgent(str) {
  let binaryArray = str.split(' ');
  let hexArray = [];
  let retArray = [];
  binaryArray.forEach(x => {
    let i = 0;
    let hexCount = 0;
    while (i < 8){
      if(x.split('').reverse()[i] == 1){
        hexCount += Math.pow(2,i);
      }
      i++;
    }
    hexArray.push(hexCount);
  });
  hexArray.forEach(hexStr => {
    retArray.push(String.fromCharCode(hexStr));
  });
  return retArray.join('');
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");

I did this with zero help which is cool. Just had to remember how to convert to binary from Uni and then think of a way to implement. Not particularly hard or anything but still.

https://www.bbc.com/news/av/technology- … -your-face

it's like a makeup printer for aging spots for people lmao

19

(376 replies, posted in Computers/programming/software)

Idk if I 100% grasp how the spread operator is working here:

function steamrollArray(arr) {
  // I'm a steamroller, baby
  let retMe = [];
  arr.forEach(e => {
    if (Array.isArray(e)){
      retMe.push(...steamrollArray(e));
    }
    else{
      retMe.push(e);
    }
  });
  return retMe;
}

steamrollArray([[["a"]], [["b"]]]);

And why it doesn't work when applying it to (...e) instead of ...steamrollArray

20

(376 replies, posted in Computers/programming/software)

function dropElements(arr, func) {
  let newArr = [...arr];
  for (let i = 0; i < arr.length; i++){
    if (func(arr[i])){
      return newArr;
    }
    else{
      newArr.splice(newArr.indexOf(arr[i]), 1);
    }
  }
  return newArr;
}

console.log(dropElements([1, 2, 3, 4], function(n) {return n >= 3;}));

Fairly certain there's no break you can use in a filter / map / reduce.

21

(13 replies, posted in General Talk)

Wikipedia

A rank-order change refers to a change in an individual's personality trait relative to other individuals; such changes do not occur very often.[13] A mean-level change refers to an absolute change in the individual's level of a certain trait over time. Longitudinal research shows that mean-level change does occur.[13] However, some traits tend to change while some traits tend to stay stable.


They change. Probably more so if you try to change them, too. Probably most people aren't actively trying to change. Idk.

22

(376 replies, posted in Computers/programming/software)

Things to know: Euclidian algorithm, Sieve of Eratosthenes, Euclid's algorithm + GCD.


Anyway:

// Euclidean algorithm 
function gcd(a, b){
  let big = 0, smol = 0, k = 0;
  if (a > b){big = a; smol = b;}
  else{big = b; smol = a;}
  while (smol != 0){
    let r = big % smol;
    big = smol; smol = r;
  }
  return big;
}
// lcm(a, b) = ab/gcd(a,b))
const lcm = (a, b) => {return a * b / gcd(a,b)};

function smallestCommons(arr) {
  let newArr = [];
  let largest = 0, smallest = 0;
  if (arr[0] > arr[1]){largest = arr[0]; smallest = arr[1];}
  else{largest = arr[1]; smallest = arr[0];}
  for (let i = smallest; i < largest + 1; i++){
    newArr.push(i);
  }
  let retMe = smallest;
  newArr.forEach(e => {
    retMe = lcm(retMe, e);
  });
  return retMe;
}
smallestCommons([18, 23]);

23

(376 replies, posted in Computers/programming/software)

Weird. Will keep that in mind, though. Thanks.

24

(376 replies, posted in Computers/programming/software)

function sumPrimes(num) {
  // Sieve of eratosthenes
  let arr = [];
  let newArr = [];
  for (let i = 2; i <= num + 2; i++){
    arr.push(true);
  }
  for (let i = 2; i <= Math.sqrt(num); i++){
    if (arr[i]){
      for (let j = i * i; j <= num; j += i){
        arr[j] = false;
      }
    }
  }
  console.log(arr[977]);
  for(let i = 2; i <= num; i++)
  {
    if(arr[i]){
      newArr.push(i);
    }
  }
  console.log(newArr);
  let reducer = (acc, num) => acc + num;
  return newArr.reduce(reducer);
}

sumPrimes(977);

That took an excessive amount of debugging. Ended up having to change the initial for loop to start from index of 0 and add <= instead of < for all instances of < because I needed to make sure it included the 977 in the reducer method because the problem asked to include the num element in the addition. Fuck.

25

(13 replies, posted in General Talk)

Big 5 is easily the most empirically supported test to date for personality. Idk about this implementation of it, and I'm sure there's still huge problems with the big 5, but it's fairly repeatable and mostly based on statistics instead of theory. It's not quite as good as IQ but it's pretty good, as far as social science goes. This implementation draws it's questions from IPIP, which is the International Personality Item Pool. This is a pretty standard pool for psychological testing.


I bet it depends on your mood when taking it and shit though. I retook it twice and my scores were a little different. Nothing too crazy though. Plus the answers don't really tell you that much unless you have correlation data in other research. It's just kinda fun to take.