in reply to Re^2: PLEADE HELP ME!![NEWBIE]
in thread PLEADE HELP ME!![NEWBIE]
First, as I hinted at originally, this not intended to be production-quality. In fact, it is just how I would start a golf problem - get it working, then trim away.
runrig explained the how. The why (why add comma-space at end) is to make the whole string uniform (digit-comma-space, digit-comma-space, digit-comma-space, etc.) for easy matching.
The fun hasn't worn off yet, so here's some uglier code:
map{ $m=!s/$/, /; $x=y/,//; for$n(1..$x){/^((?:\d+, ){$n})\1+$/&&{$m=$n,last}} print$/,($m>0?$x/$m:0); }<DATA> __DATA__ 1, 2, 5, 1, 2, 5, 1, 2, 5 3, 6, 3, 6, 3, 6, 3, 6 4, 1, 28, 0, 4, 1, 28, 0 3, 5, 17, 3, 17, 5 4, 1, 28, 0, 4, 1, 28
|
|---|