Hi Doug,

thank you very much, I'll remember this for future use. I see the
implementation is using locals as well, I guess there's just too much
variables to shuffle. IIUC this is actually more powerful than
partition-by because this has 2 values at each cycle to decide what to
do whereas partition-by has only 1.

FYI I'm still solving each day, learning a bit more of factor along the
way.

Thank you for your help

On 2019-12-04 23:37, Doug Coleman wrote:
> Here's the first example from the clojure docs for partition-by:
> 
> { 1 2 3 4 5 } [ [ 3 = not ] bi@ and ] monotonic-split
> 
> { { 1 2 } { 3 } { 4 5 } }
> 
> Also you could do this if the function is expensive so you only apply
> it once:
> { 1 2 3 4 5 } [ 3 = ] map-zip [ [ second ] bi@ = ] monotonic-split [
> keys ] map .
> 
> { { 1 2 } { 3 } { 4 5 } }
> 
> The second example is 
> { 1 1 1 2 2 3 3 } [ nip odd? ] monotonic-split .
> 
> { { 1 1 1 } { 2 2 } { 3 3 } }
> 
> Cheers,
> Doug
> 
> On Wed, Dec 4, 2019 at 3:07 PM <pet...@riseup.net> wrote:
> 
>> Just like last year I'm working through Advent of Code challenges.
>> Jus
>> like last year I'm probably going to fall out in the next day or two
>> :)
>> Nevertheless, I'm still holding up, and have a question.
>>
>> The 4th day part 2 quest has a test, semi-quoting: two adjacent
>> matching
>> digits that are not part of a larger group of matching digits. So
>> 112 is
>> fine (two 1's) but 111 is not. Also 11122 is fine, we're just
>> looking
>> for any occurrence of two adjacent matching digits.
>>
>> I write some clojure in my day job and there's this function
>> partition-by[1]. With a word like that the check could simply be
>>
>> digits [ ] partition-by [ length 2 = ] any?
>>
>> where digits explodes the number into a vector of its digits.
>>
>> Alas, I couldn't find such a word and after a lot of looking around
>> nothing similar. Grouping and clumping and such didn't lead me to
>> any
>> simple solution, so I just rolled something dirty:
>>
>> : -reset ( cnt curr next -- one next ) [ 2drop 1 ] dip ;
>> : -inc ( cnt curr next -- cnt+1 curr ) drop [ 1 + ] dip ;
>> : -init ( seq -- cnt curr seq ) [ 1 ] dip unclip-slice swap ;
>> : has-2? ( seq -- ? ) -init [ 2dup = not [ pick 2 = [ ] [ -reset
>> f ]
>> if ] [ -inc f ] if ] find [ 2drop 2 = ] dip or ;
>>
>> I was thinking about writing partition-by myself but I don't like
>> using
>> locals and I just wasn't able to come up with a simple solution on
>> the
>> stack.
>>
>> Thoughts/pointers welcome!
>>
>> P.S.: if anyone wants to see/compare/review my solutions so far I
>> can
>> post it somewhere, just let me know.
>>
>> [1] https://clojuredocs.org/clojure.core/partition-by
>>
>> --
>> ------------
>> Peter Nagy
>> ------------
>>
>> _______________________________________________
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

-- 
------------
  Peter Nagy
------------


_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to