Count number of ways to cover a distance | Returns count of ways to cover ' dist ' ; Base cases ; Recur for all previous 3 and add the results ; driver program
function printCountRec ( dist ) { if ( dist < 0 ) return 0 ; if ( dist == 0 ) return 1 ; return printCountRec ( dist - 1 ) + printCountRec ( dist - 2 ) + printCountRec ( dist - 3 ) ; } var dist = 4 ; document . write ( printCountRec ( dist ) ) ;