Björn's can be sped up by not using assoc-map! and replacing
``refine-index`` with this:

:: refine-index ( max-i index prev-index -- )
    index keys [ [ prev-index at ] [ index set-at ] bi ] each
    index [ nip max-i >= ] assoc-filter! drop ;

That takes it from 2.0 seconds to 1.3 seconds on my laptop.


On Thu, Mar 17, 2016 at 11:11 AM, Alexander Ilin <ajs...@yandex.ru> wrote:

> Hello!
>
>   I've finally finished my solution:
>   http://paste.factorcode.org/paste?id=3852
>
>   I took a different approach. Instead of manipulating the source input
> string I create a hash table of all character positions, then remove and
> add items to it as I go until it's empty. Output is collected as a
> side-effect of that process in a global variable. This approach combines
> sub-par performance with difficult-to-read code.
>
>   On my machine the solve2 word runs in 28.5 seconds, compared to
> Sankaranarayan's 2.6 seconds, and Bjoern's 3.28 seconds. (Jon's solution
> never completes: Factor terminates without an error message after about 20
> minutes of work.)
>
>   I think the approach is interesting, but the performance seems to suffer
> due to the many searches, sorts and hash table manipulations. Apparently,
> working directly over the one input string is faster.
>
>   After initially implementing a solution with 6 global variables, I
> managed to reduce the number to 1 by moving stuff around and using locals.
> This was fun, and quite easy, although this one time I got the order of
> arguments wrong and had a hard time finding the cause. Apparently, it's not
> so easy to simulate code runs when locals are used: you can't just populate
> stack in the Listener and paste pieces of code into it.
>
>   Overall, this was a useful excersise in learning Factor. Thank you,
> Sankaranarayan!
>
> ---=====---
>  Александр
>
>
> ------------------------------------------------------------------------------
> Transform Data into Opportunity.
> Accelerate data analysis in your applications with
> Intel Data Analytics Acceleration Library.
> Click to learn more.
> http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to