<flux__>
(an interview/demo video involving directx)
unfo- has joined #ocaml
Sweetshark has joined #ocaml
fab_ has quit [Remote closed the connection]
bmiller has joined #ocaml
Aradorn has joined #ocaml
Sweetsha1k has quit [Read error: 110 (Connection timed out)]
<unfo->
I would appreciate if someone could take a look at this pastie: http://pastie.caboo.se/21027 and give me some pointers. Pointers I'm looking for: how to get it working and what to read up on next so I could've figured it out myself.
<pango>
unfo-: compiles fine for me
<unfo->
errrh. what the hell then
<unfo->
The Objective Caml toplevel, version 3.09.1
<unfo->
pango, which ver do you have?
<pango>
same here
* unfo-
blinks
<unfo->
normally this is the place where I would use an internet acronym to display my dismay towards not understanding the situation
<pango>
$ ocamlc -i paste-21027.ml
<pango>
type position = { x : int; y : int; }
<pango>
val num_routes : position -> position -> int
<pango>
val start : position
<pango>
val stop : position
<unfo->
errrh
<unfo->
I downloaded that paste and it works
<unfo->
aslkdhaskjdhas!!!!!!
<unfo->
What the hell! I pasted that code directly from my editor
<unfo->
now it works
<unfo->
pango, thanks for your time :)
<pango>
np ;)
<unfo->
lessee how long traversing the entire 20x20 grid takes
<pango>
most of the parenthesis are actually useless, but it's no biggie
<unfo->
oh? like the ones between if ... then ?
<pango>
actually num_routes compiles without any parenthesis
<unfo->
oh cool :)
<pango>
I'd left the ones in (num_routes bottom max_pos) + (num_routes right max_pos) for readability, however
<unfo->
okay. thanks for the input :)
<unfo->
but yeah... my code definitely fails... Project Euler <http://www.mathschallenge.net/index.php?section=project> from where I get these small maths quizzes has a strict One Minute Rule... and this has gone for quite a while now ;)
<unfo->
=> I'm not doing the right thing
<unfo->
well usually brute force is not the answer
<pango>
you could also have one_right : position -> position and one_down : position -> position function to factorize all those records manipulations
bohanlon_ has quit [Read error: 60 (Operation timed out)]
<unfo->
right. lemme do that :)
<pango>
then have (num_routes (one_down start_pos) max_pos) + (num_routes (one_right start_pos) max_pos), etc.
<unfo->
should I define 'let one_right..' within num_routes or outside it?
<pango>
as you wish... I you think it could be handy later, you can define it outside the function
<unfo->
okay
<unfo->
it's cleaner now, but still it's a brute force attack, when prolly a much simpler algorithm will do :)
<pango>
well, there's obviously better solutions that plain brute force ;)
<unfo->
aye
<pango>
you'll can num_routes many times with the same parameters... and since it's a function (in the mathematical sense) you'll just get the same result...
dbueno has quit [Remote closed the connection]
<unfo->
I don't follow your point
<pango>
you'll call num_routes { 3, 4 } { 20, 20 } as many times as there's different paths from { 0, 0 } to { 20, 20 }
<pango>
you'll call num_routes { 3, 4 } { 20, 20 } as many times as there's different paths from { 0, 0 } to { 3, 4 } sorry
<unfo->
so you're getting at that I am re-calculating complex things in vain
<unfo->
oh and I just realized, that at the start, I need to only go from 0,0 to 1,0 or 0,1 and continue from there, since the path's are mirrored
<pango>
yes... So, as a "stop gap" measure, you could store all values of num_routes already computed, and skip recomputing the same value if the same parameters are used again... That's called "memoizing" the function
<pango>
yes, you can also take advantage of symetries
<unfo->
okay, so I should start from the end and move backwards sort of
<unfo->
Yeah!
<unfo->
I just modelled that approach on a piece of paper with 2x2 and a 3x3 grid
<unfo->
it works like a charm, thanks pango!
<pango>
indeed that's a good way to avoid duplicate efforts
<unfo->
does a Hash table take any kind of 'type' as its key?
<pango>
by default it uses a "universal" hashing function privided by OCaml... I don't think there's much restrictions on what it can hash
<unfo->
so I can do: Hashtbl.replace routes {19,20} 1;;
<pango>
that should work fine
<unfo->
okay :)
<unfo->
thanks mate
<pango>
np
<unfo->
and now I figured out how to do the algo, coz I know that on if x=20 then with all y num_routes = 1 and vice versa with y=20
chessguy has joined #ocaml
<pango>
last step is to find the mathematical formula for the result ;)