-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to compare/distinguish " ", "0", 0 and mysterious... #301
Comments
OK - I think I can skirt around the comparison issues (for now) with
but I might run into problems comparing the 0 with things later... |
And
with a leading space is tricky (although we know in this case the leading space is not a zero...) |
Here's a possible solution for this issue:
|
That's clever - I wouldn't have thought of the split Y into Z line... |
Here's another possible solution: use the "with" keyword. Twice.
After those lines, different values of Input will result in different values of Test: Input Test ...at which point it's fairly trivial to tell them apart by looking at the value of 'test'. |
So... the crux of the matter for me is this... suppose you have 3 lines of input that goes:-
If you've coded in other languages, you might expect
which stops reading early, because the character/string
Or, to put it another way,
But this all feels a little bit clumsy, and I wonder if |
The point about I'm starting to pull together issues for the next iteration of Rockstar, and this one is definitely one to include. |
Great :-) Related: To solve the AoC puzzle, I flattened my 5x5 grid of numbers into an array of 25 numbers, indexes 0..24 inclusive. I then wanted to have a lookup table - a sparse associative array that lets me ask: where (if at all) does this number occur in this array. The intention is that numbers not present return "mysterious", as no entry is found in my lookup. So unless I work around it, I have a problem distinguishing between "mysterious" meaning undefined (the number is not in my 0..24 array at all), or that it is present at position zero. As a suggestion on how it could improve in a reasonably backward-compatible way - what about an additional term "meaningless", meaning something that really is a null/undefined. Brief (but very deep) poetic support for this suggestion:- Everything that's meaningless is mysterious |
One simple workaround is to have your array return 1-25 for items in your array (subtract 1 to get the actual position) and mysterious for anything not in the array. |
Yeah, and that's what I do, and the occasional build up and knock down doesn't hurt. There may be other times though where you'd want to distinguish between zero and missing more immediately. |
Actually, it's rather a bug. The Spec says:
0 is non-mysteriuos, so 0 must not be equal to mysterious. Also, the tests do not comply with this rule (equality/mysterious.rock): |
All of these succeed at present (on the TRY IT page) :-
|
This also succeeds:-
but this (which is genuinely undefined) locks up - that's probably a different issue.
|
@dylanbeattie To incorporate the EOF-as-mysterous feature, we need to clear the mystery around It will cause a breaking change, though. Maybe worth to think on versioning as well. |
My thought was that an additional |
@weshinsley True - and also, it makes Dylan once said he is not afraid of breaking changes - and we can provide a proper compiler for each version (once there's a breaking change, I will save a version of Rocky to support the old version). So, old codes will be able to run on old versions. We only need to distinguish them. |
You can check if a value is NaN by comparing it to itself. Let my motto be "74 50 26 0 24" shout nothing |
I've run into some trouble trying to parse this string (AoC 2021 day 4...)
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...
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.
The text was updated successfully, but these errors were encountered: