I came up with a "new" idea, but just realized it's very similar to your original algorithm

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

Talking about glitchy, consider this input

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 "?"


In reply to Re: checking a set of numbers for consistency mod p by LanX
in thread checking a set of numbers for consistency mod p by hv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.