Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. yuriythebest2

    recursion question

    yeah I am too inexperienced for that- can you explain the simpler one first printN(N) :- N > 0, M is N - 1, printN(M), writeln(N). why is it 1 2 3 and not 3 2 1 I don't understand
  2. yuriythebest2

    recursion question

    no sir I do not. Ok, in my attempt to understand prolog recursion I picked up a nice pdf book about prolog, which had this example printN(0). printN(N) :- N > 0, M is N - 1, printN(M), writeln(N). ?- printN(3). 1 2 3 Yes What I don't understand is, if initially M is N, and then we begin to...
  3. yuriythebest2

    recursion question

    sorry I don't quite understand that expression (I think it's only in french)- do you mean did I try to change it in some way to make it work? yeah. I've tried changing the code like so sum(N, D, Res) :- D<N, N1 is N - D,Res is Res1+N1, sum(N1, D, Res1). but that only made it worse
  4. yuriythebest2

    recursion question

    yeah I know I've been staring at it for quite a while now :)
  5. yuriythebest2

    recursion question

    well, the assigment said that if the inputs where D>=N then Res should equal N so my full code looks like so sum(N, D, Res) :- D<N, N1 is N - D, sum(N1, D, Res1), Res is Res1+N1. sum(N, D, Res) :- D >= N, Res = N.
  6. yuriythebest2

    recursion question

    hi! I need to find the sum of all positive numbers up to N, with the step of D, for instance id D=3 and N=11 then 11+8+5+2=26. Currently my way is like so: sum(N, D, Res) :- D<N, N1 is N - D, sum(N1, D, Res1), Res is Res1+N1. however this yields the answer 17 which is incorrect please help!

Part and Inventory Search

Back
Top