scheme - Number in Sequence that a pair falls in -


i want find number in sequence pair falls in. trying write procedure verifies f(1, n) = 2n - 2 , f(m+1, n+1) = 2f(m, n). works when call (number 99, 100), doesn't work when call (number 100, 100). why doesn't work? sequence number (100, 100)?

here procedure:

(define (number m n)    (if (= m 1)        (- (* 2 n) 2)        (* 2 (number (- m 1) (- n 1))))) 

why believe procedure "doesn't work"? function, defined, correctly implementing desired formula - , lead base case when both m , n equal:

(- (* 2 1) 2) ; if m equals 1 n equals 1 

the above return 0 of course, , multiplications in recursion cancel, because you'll multiplying 0 on , on again:

(* 2 (* 2 ... (* 2 0))) => 0 

so problem not in procedure itself, in formula it's implementing. make sure it's correct.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -