Re: [Factor-talk] How would I solve this better in Factor?

2016-02-25 Thread Jon Harper
"Hi,
I wrote a basic o(n^4) solution to see how simple it could get. The
code looks nice to me, but it's sllw :) like 1 hour on the 3200
chars string.. http://paste.factorcode.org/paste?id=3843

I noticed we have 1 function in common : remove-after-underscore. You
can can see how head and when* make my implementation shorter (and
more readable?)

Cheers,
Jon


On Wed, Feb 24, 2016 at 5:50 AM, Sankaranarayanan Viswanathan
 wrote:
> Hi,
>
> It had been awhile since I wrote any Factor code, so I was trying to
> solve the following problem from reddit's dailyprogrammer subreddit:
> http://bit.ly/1OtP8Qj
>
> The solution I came up with in Factor looks like this:
> http://bit.ly/1PY8j98
>
> I struggled quite a lot coming up with this. Mainly in keeping things in
> my head and figuring out what I needed to do to bring the stack in order
> for the operations I was attempting..
>
> Coming from an iterative programming background (with a little bit of
> exposure to functional programming), I find it quite hard to formulate
> solutions in Factor. Can someone help me with tips on how they approach
> writing code in Factor? What is your though process to turn a given
> pseudo code into a factor program?
>
> For example, my pseudo code for the main portion of this problem (the
> find-match function) was as follows:
>
> let buff = ""
> let match = (indx=0, length=-1)
> for each char c in input:
> find count(c) in buff
> if count == 2
> append c to buff
> check if str(first c to end) is longest and update match
> remove chars in buff before second c occurrence
> else if count == 1
> append c to buff
> check if str(first c to end) is longest and update match
> remove chars in buff before first c occurrence
> else
> append c to buff
> discard buff and return match
>
> Any pointers is greatly appreciated.
>
> Thanks,
> Sankar
>
>
> --
> Site24x7 APM Insight: Get Deep Visibility into Application Performance
> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
> Monitor end-to-end web transactions and take corrective actions now
> Troubleshoot faster and improve end-user experience. Signup Now!
> http://pubads.g.doubleclick.net/gampad/clk?id=272487151=/4140
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

--
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151=/4140
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] How would I solve this better in Factor?

2016-02-25 Thread Alexander Ilin
Hello, Jon!

25.02.2016, 20:02, "Jon Harper" :
> I wrote a basic o(n^4) solution to see how simple it could get. The
> code looks nice to me, but it's sllw :) like 1 hour on the 3200
> chars string.. http://paste.factorcode.org/paste?id=3843

  Wow, your code looks very nice!
  I didn't know about collect-index-by, so I had to invent it yesterday.
  Today I was also about to invent all-combinations : ))

> I noticed we have 1 function in common : remove-after-underscore. You
> can can see how head and when* make my implementation shorter (and
> more readable?)

  Here's another version of that same function, I hope you like it:

USE: splitting

: remove-after-underscore ( seq -- seq' )
{ CHAR: _ } split1 drop ;

  : )

PS: Can someone approve two of my messages that are stuck in the mailing list's 
moderation queue?

---=---
 Александр

--
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151=/4140
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] How would I solve this better in Factor?

2016-02-25 Thread Alexander Ilin
PPS: even shorter:

: remove-after-underscore ( seq -- seq' )
"_" split1 drop ;

---=---
 Александр

--
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151=/4140
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk