functional programming - Haskell Time Issue -


it second question haskell , thought algorhythm not bad , gives faster results in c++ , python , there problem @ haskell cant give me 10^25 (maybe gives dont wait much) , question ask me value ,please guide me fix guy now.

##euler 169## giveres 0 _= 1 giveres 1 _= 1 giveres x = if search x                 send x                 else let res = if rem 2 == 0                                   (giveres (quot 2) x)                                         +                                        (giveres (quot 2-1) x)                                   else giveres (quot 2) x                      in snd (head ((a,res):x)) search _ [] = false search (x:xs) = if == fst x true else search xs send (x:xs) = if == fst x snd x else send xs 

code long because remembering system shortening time in haskell not efficient

f 0 _ = 1 f = if rem 2 == 0          giveres (quot 2) + giveres (quot 2-1)          else giveres (quot 2) 

is first form of code

  1. for goodness sakes, clean code people can read it. example, rewrite snd (head ((a,res):x)) --> res. suggestion: add type signatures.
  2. extract common subexpressions (quot) named let bindings reduce work.
  3. memoize calls giveres. give largest benefit. if search [haskell] memo should lots of results.
  4. don't use list set test membership (search) followed partial function lookup (send). instead consider using map or hashmap containers or unordered-containers libraries.

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -