There's more than one way to do things PerlMonks

### Re: LFSR golf

 on May 08, 2001 at 12:31 UTC ( #78776=note: print w/replies, xml ) Need Help??

```sub l{my(\$s,\$t)=@_;sub {(\$s=(\$s.(((my \$x=\$s+\$t)=~y/1/1/d)%9%2)))=~s/5.
+/5/;\$s}}
\$x=l("50101","0022");print (\$x->(),\$x->(),\$x->(),\$x->());
The first line is the generating sub (containing 79 chars) and the second one is an usage example.

Replies are listed 'Best First'.
73 chars, called on a foul (Re: LFSR golf)
by tye (Sage) on May 08, 2001 at 18:32 UTC

I don't mind the departure in how you call the generating function but I'm going to disqualify this one for having the closure return "50101" instead of 0 and "51100" instead of 1.

If you were shifting the other direction, then a simple &1 at the end of the closure would solve the problem and give you a 73-character solution (not counting the "sub l{" and "}", as usual).

I'm sure this general approach can be modified such that I'd accept it but I'll leave that to you or whoever beats you to it. (:

- tye (but my friends call me "Tye")
Didn't know you wanted that. OK. New version (72 chars)
```sub l{
my(\$s,\$t)=@_;sub{(\$s=(\$s.(((my\$x=\$s+\$t)=~y/1/1/d)%9%2)))=~s/5(.)/5/;\$1
+}
}
\$x=l("50101","0022");print (\$x->(),\$x->(),\$x->(),\$x->());

Create A New User
Node Status?
node history
Node Type: note [id://78776]
help
Chatterbox?
 [LanX]: Oh, you spread measles in your saliva? [LanX]: ... and why did you bite hos daughter? [LanX]: *his [holli]: And this guy was also Anti-Vaxx and I just snapped. I shoed him all over the yard [james28909]: biting between the legs? now thats my kind of religion. [holli]: and back into the building, saw him later peeking out of the window looking scared. It was hilarious. [james28909]: wish i could stay and chat. i have an unsuspecting client to give an estimate to. muhhahaha

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-12-13 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What programming language do you hate the most?

Results (373 votes). Check out past polls.

Notices?