in reply to Re: checking a set of numbers for consistency mod p
in thread checking a set of numbers for consistency mod p
I came up with a "new" idea, but just realized it's very similar to your original algorithm
I think it's the same as my original algorithm. :)
don't use hashes they are slow and the logic is glitchy
I guess the main reason to use a hash was that the number of entries gets counted for me: I suspect iterating over an array to count the entries could easily cost all the time saved in assignment. Not sure what you mean by "the logic is glitchy", unless you're referring to the bug you describe later (which I contend is a simple logic error, and not related to the choice of container).
I agree bitstrings could be faster for seenzero (though a lot more fiddly, especially if I want a fast bit count) - I'm sure that's what I'd have chosen if writing this in C or assembler. For %seenmore it would probably make sense just to record $mod and $seen (the count) directly.
Similarly I agree that the recursion could be avoided. These are all micro-optimizations though, and the question was about a different algorithm - which I think you've given me, piece by piece, in your other posts, I just need to get around to putting together an implementation.
Talking about glitchy, consider [the] input 3, [0, 1, undef, undef, 0, undef]
Ooh yes, pretty sure that's a bug in the implementation of my OP: it should return false if any modular value shows up in both %seenzero and %seenmore. I've updated the OP with a simple but inefficient fix for that, thanks!
Anyway depending on the distribution of your input, it might be easier to search in a first pass for the first entry > 0 to calculate the "right" column. [...] in the pathological case that there is no entry >0 you'll need to find the column consisting of only "?"
My original algorithm copes well with that pathological case, by counting the number of distinct modular values seen for the zeroes. I don't see how you'd find the correct answer for, say, 3, [0, 0, 0] without counting, using anything like this algorithm.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: checking a set of numbers for consistency mod p
by LanX (Saint) on Apr 16, 2022 at 19:46 UTC |