in reply to checking a set of numbers for consistency mod p
Maybe others will profit from the explanation:
let's take p=3 and so any input which is a 32-range will be cut out from this circular array (with X >= 4)
0010010020010010020010010030010010020010010020010010030010010020010010 +0200100100X (repeat from start)
plus any entry can be undef="?"
If we arrange the input in p columns we see, that no matter were our sub-range starts
a) p-1 columns MUST only be 0 (or undef)
b) exactly 1 column MUST only have values >0 (or undef)
for instance
Level=0
??? 01? 0?0 0?0 010 ??0 010 01? 050
if we take the non-zero column ...
?1??1?115
and decrement all defined entries ...
?0??0?004
we get the input for the next recursion which must hold the same criteria
Level=1
?0? ?0? 004
and so on
Level=2
??3
Level=3
2
You already (almost) implemented it, and now I understand it too. The way you use those hashes irritated me a lot.
If you wanna speed it up you could
01? ?0?
obviously is the middle column wrong having both 0 and 1, but AFAIS will your implementation accept that and recurs to the next level. (Or am I misreading?)
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 a second pass make sure that - for defined parts - this column has only non-zeros and all other columns are always zero. Like that you don't need any hashes or other flags and you can bail out immediately on fail.
HTH! :)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
°) in the pathological case that there is no entry >0 you'll need to find the column consisting of only "?"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: checking a set of numbers for consistency mod p
by hv (Prior) on Apr 16, 2022 at 01:39 UTC | |
by LanX (Saint) on Apr 16, 2022 at 19:46 UTC | |
|
Re^2: checking a set of numbers for consistency mod p
by vr (Curate) on Apr 16, 2022 at 07:36 UTC | |
by hv (Prior) on Apr 16, 2022 at 21:14 UTC | |
by LanX (Saint) on Apr 16, 2022 at 21:30 UTC | |
by hv (Prior) on Apr 17, 2022 at 03:03 UTC | |
by LanX (Saint) on Apr 17, 2022 at 08:57 UTC | |
by LanX (Saint) on Apr 16, 2022 at 19:52 UTC |