Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With nothing more than a really mindless wrapping of your lists into Vectors I get 2.5 seconds when the input list is <code>[1..10000]</code>.</p> <pre><code>import qualified Data.Vector as V import Data.Vector (Vector, (!)) main = print $ liss [0..10000] liss :: [Int] -&gt; Int liss seqL = V.maximum dp where dp = V.fromList $ 1 : [val n | n &lt;- [1..length seqL - 1]] seq = V.fromList seqL val n = (1 +) . filter'and'get'max ((&lt;= top) . (seq!)) $ [0..pred n] where top = seq!n ----- filter'and'get'max :: (Int -&gt; Bool) -&gt; [Int] -&gt; Int filter'and'get'max f [] = 0 filter'and'get'max f [x] = if f x then dp!x else 0 filter'and'get'max f (x:xs) = if f x then ( if vx &gt; vxs then vx else vxs ) else vxs where vx = dp!x vxs = filter'and'get'max f xs </code></pre> <p>The compilation and execution:</p> <pre><code>tommd@Mavlo:Test$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.0.3 tommd@Mavlo:Test$ ghc -O2 so.hs [1 of 1] Compiling Main ( so.hs, so.o ) Linking so ... tommd@Mavlo:Test$ time ./so 10001 real 0m2.536s user 0m2.528s </code></pre> <p>A worker-wrapper transformation on <code>filter'and'get'max</code> seems to shave off another second. </p> <p>Also, I don't understand why you need that middle case (<code>filter'and'get'max f [x]</code>), shouldn't it work fine without that? I guess this changes the result if <code>dp!x &lt; 0</code>. Note eliminating that saves 0.3 seconds right there.</p> <p>And the python code you provided takes ~ 10.7 seconds (added a call of <code>longest(range(1,10000));</code>).</p> <pre><code>tommd@Mavlo:Test$ time python so.py real 0m10.745s user 0m10.729s </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload