#301·rockstar

How to compare/distinguish " ", "0", 0 and mysterious...

Author: weshinsleyCreated Jan 7, 2022Updated Mar 20, 2024
LabelsvNext

I've run into some trouble trying to parse this string (AoC 2021 day 4...)

74 50 26  0 24

So, I want to make this into an array of exactly 5 ints, but I have two challenges (1) there is double-spacing before the 0 (as this input comes as a nicely laid out grid), so a simple split will also include some empties which I don't want - and are difficult to remove, because... (2) one of the integers is zero - and spotting what's a zero, and what's an empty is defeating me.

In essence... I've tried a number of elaborate methods of splitting and/or burning, but I end up failing because...

  1. ("0" is " ") is TRUE. So I am struggling to detect zero vs space, if I split and parse by single characters, or if I split by "space" then try and remove the erroneous empty.
  2. 0 is mysterious, as is " " and "0", so again, I can't distinguish that way.
  3. If I burn the characters, then I can end up with NaN for a space, and 0 for a zero, which looks promising. But then I'm not sure what comparison I can do to detect tha NaN, which I think is not mystious, but checking whether "x is NaN" doesn't seem valid synax, and if I have x and y, which are both NaN, then (x is y) returns FALSE (not surprisingly).

Sorry for slightly rambling description, but hope that makes the problem clear...! Any suggestions on how I can parse that wretched string and get this crucially important squid bingo game solved (in rock style)?

Many thanks - this language is great fun.