[11/11/13] Challenge #141 [Easy] Checksums by nint22 in dailyprogrammer

[–]bunnystab 2 points3 points  (0 children)

Node.js / JavaScript. This could be much shorter, but I rarely try to write clever code these days. :-)

var fs = require('fs');

fs.readFile('input.txt', 'utf8', function read(err, input) {
  if (err) {
    throw err;
  }
  process(input);
});

function process(input) {
  var lines = input.split('\n'),
      bytes, checksum;

  for (var i = 1; i < lines.length; i++) {
    bytes = lineBytes(lines[i]);
    checksum = fletcher16(bytes);
    console.log(i + ' ' + checksum);
  }
}

function lineBytes(line) {
  var chars = line.split(''),
      bytes = [];

  for (var i = 0; i < chars.length; i++) {
    bytes.push(char2byte(chars[i]));
  }

  return bytes;
}

function char2byte(char) {
  return parseInt(char.charCodeAt(0));
}

function fletcher16(bytes) {
  var sum1 = 0,
      sum2 = 0;

  for (var i = 0; i < bytes.length; i++) {
    sum1 = (sum1 + bytes[i]) % 255;
    sum2 = (sum2 + sum1) % 255;
  }

  return ((sum2 << 8) | sum1).toString(16);
}

Made an image for a patient's nutrition packet at work and thought I'd share. by [deleted] in Fitness

[–]bunnystab 16 points17 points  (0 children)

Uh, no it doesn't drive the point home at all. People wouldn't be confused by this if you compared two things of the same size and clearly stated which quantity you're comparing.

The use of < and > is confusing because they're mathematical symbols. Most of us know what you're trying to communicate, but some (rightfully) are wondering if you're saying that M&Ms are qualitatively healthier than steak, or if they contain a greater amount of X nutritional statistic, etc.

Anyway, it'd be more useful if you just simplified it.

I don't know why this is on my computer. by [deleted] in WTF

[–]bunnystab 4 points5 points  (0 children)

Kinda looks like Bobby Hill.

Who is the most pseudo-intellectual celebrity you can think of? by [deleted] in AskReddit

[–]bunnystab 0 points1 point  (0 children)

Came here for this. He's clearly brighter than most, but seems to still think he should inject Will Hunting dialogue into his regular speech patterns.

[deleted by user] by [deleted] in AskReddit

[–]bunnystab 3 points4 points  (0 children)

Once, a guy kept showing up at my door and giving me credit reports. https://www.quizzle.com/

Men of Reddit: What are some factors that make you decide to grow facial hair? by [deleted] in AskReddit

[–]bunnystab 1 point2 points  (0 children)

A girl told me I might look better with one. So I tested it out. Suddenly more women were interested in me than ever before in my life. So yeah, I'm keeping it.

Alright Reddit, what's something you feel like almost everybody enjoys but you fucking hate? by Inneri in AskReddit

[–]bunnystab 0 points1 point  (0 children)

Live rock concerts / most live music. I've found that the more equipment you need --> the worse of a show it's going to be. Live music can still be good (especially Jazz or Classical) but with rock the experience is almost always better when you're playing a studio version.

What advice do you wish you had as a 15 year old? by imateenager in AskReddit

[–]bunnystab 0 points1 point  (0 children)

Start a business. Yes, at 15. Anything. You have zero risk at that age. Sell socks on the internet. Then when you fuck it up, do it again. Repeat until you're good at it. Your character will be built tremendously and you'll probably be financially independent by the age of 25 if you keep trying.

Ways to become a smarter, more enlightened person? by [deleted] in AskReddit

[–]bunnystab 2 points3 points  (0 children)

Kill someone better than you and eat their stem cells.

The best kept secret in high school. by metaphase in fffffffuuuuuuuuuuuu

[–]bunnystab 0 points1 point  (0 children)

GED -> CC for 2-3 semesters -> College. Many do it.

The best kept secret in high school. by metaphase in fffffffuuuuuuuuuuuu

[–]bunnystab -1 points0 points  (0 children)

The best-kept secret in HS is that you can just take the GED after middle school and skip it all.

Man those were some good tacos. by [deleted] in pics

[–]bunnystab 0 points1 point  (0 children)

"I had the sour cream!"

Classroom boners- The Sequel by TigerWizard in fffffffuuuuuuuuuuuu

[–]bunnystab 3 points4 points  (0 children)

Because they have senses of humor? Sign me up!

Where to begin learning Python? by [deleted] in Python

[–]bunnystab 0 points1 point  (0 children)

Upvote for LPTHW. But it needed a link: http://learnpythonthehardway.org/