Re: Linus sequence
[email protected] (Rick Klement) Thu, 18 Dec 2003 19:54:28 -0800
| Newsgroups | perl.golf |
|---|---|
| Message-ID | <[email protected]> |
Phil Carmody wrote:
>
> Embarassment time -
> perl -e
> '"${s}1_${s}2"=~/(.*)\1_.*?(.*)\2$/,print$s.=1+(length$1>length$2),$/for(0..98)'
>
> The task was to produce the "Linus sequence" where either a 1 or a 2 is added
> to the seed "1", such that the contiguous repeat at end of the string is
> minimised at each stage.
>
> The code's therefore pretty self explanatory, but more explanation
> can be found at google groups:
> Message-ID: <[email protected]>
>
> I'm slaughtered by my double "length", but can't see a way round it,
> and on the keyhole front, my initial "${s}"s aren't very elegant.
>
> Anyone got a few pointers for improving it?
double length? what double length?
perl -le 'print$@.=1+($-["$@1"=~/(.*)\1$/]<$-["$@2"=~//])for 0..98'
(some golf tricks applied :)
--
Rick Klement