Sunday, 11 March 2018

One line NHS Number checker

I didn't know this until recently, but the UK's NHS number is a rather smart device, and I ended up spending a few minutes looking at this page and then generating this checker:

const chechNhsNum = num => {
  let multiplier = 10;
  return num.split("").reduce((a, c) => {
    if(multiplier > 1){
      const semiTotal = ~~c * multiplier;
      return a + semiTotal;
      return 11 - a % 11 > 9 ? false : ~~c === 11 - a % 11
  }, 0);

Then I got to thinking how small I could make the checker and worked this up:

const validNHSnum=num=>num.split("").reduce((a,c)=>a.m>1?{a:a.a+~~c*a.m,m:a.m-1}:11-a.a%11>9?false:~~c===11-a.a%11,{a:0,m:10});

Which is sort of like the puzzles Mr Monks and I used to beat ourselves up with when we played Empire of Code. Running it through Babel produces this, which I guess is more readable:

var validNHSnum = function validNHSnum(num) {
  return num.split("").reduce(function (a, c) {
    return a.m > 1 ? { a: a.a + ~~c * a.m, m: a.m - 1 } : 11 - a.a % 11 > 9 ? false : ~~c === 11 - a.a % 11;
  }, { a: 0, m: 10 });

Thursday, 8 March 2018

Contagious nausea

A friend and I were discussing the most humorous bodily functions, and we got into a disagreement over whether farting of vomiting was the funniest.

I'm pretty sure that farting is the one most likely to make me guffaw, but she told a rather good story about sick that made me chortle.

The main reason why I think vomit is no laughing matter is that for me at least, it's contagious. I see someone being sick and I automatically get the gag reflex as well. And it doesn't even have to be a person.

Once-upon-a-time, when we lived afloat, I was quietly sitting working on my laptop in the galley when the cat went mental! Eddie was a bruiser of a cat with a face that only his mother, god rest her diseased soul, could love. He looked and acted like a thug, and I'm pretty sure he thought he was a dog.

He'd found a moth you see, and not just any old moth but one the size of Mothra. It was huge! He thought it was immense fun to chase around after the poor bugger dragging considerable tears in its wings. To such an extent that it was no longer able to keep itself aloft and fell to the floor, still waving it's enormous wings - though to no avail. It just lay there waving it's broken wings until, that is, Eddie pounced.

He batted it around a wee bit until he got bored and then chomp, down it went.

His table manners were as brutish as everything else about him, and he didn't bother to chew so down the poor moth went, still flapping.

The flapping must've tickled something in his withered innards as, not 10 seconds after he'd swallowed dear old Mothra, he threw it back up.

"Ah, bloody cat", says I and I gentle step over it to grab some kitchen roll to wipe up the mess. Crouching down after gently moving the cat out of the way (he was cleaning his claws and looking disinterested now that he's murdered his plaything) I bent to my task. But, looking down at the forlorn once-giant, I noticed that s/he was still vainly trying to escape and was gently waving those tattered wings while being slightly crushed and covered with Eddie's digestive juices and the odd semi-digested cat biscuit.

That was it! Thankfully I was close to the oven, so I grabbed the largest pan I could and threw up in it while, through streaming eyes, I cleaned up the mess before putting the whole sorry lot into the fire for a decent cremation.