This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package recfun | |
import common._ | |
object Main { | |
def main(args: Array[String]) { | |
println("Pascal's Triangle") | |
for (row <- 0 to 10) { | |
for (col <- 0 to row) | |
print(pascal(col, row) + " ") | |
println() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Regular recursion | |
function factorial ($n) | |
{ | |
if ($n == 1 ) { | |
return 1; | |
} | |
return $n * factorial($n-1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pascal_triangle($c, $r) | |
{ | |
if ($c == 0 || $c == $r) { | |
return 1; | |
} else { | |
return pascal_triangle($c-1, $r-1) + pascal_triangle($c, $r - 1); | |
} | |
} | |
echo pascal_triangle(1,3), "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// (if (zero? x) max (/ 1 x)) | |
function balance($str) | |
{ | |
function loop($str, $acc) | |
{ | |
if (empty($str)) { | |
return $acc == 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$n = 236; | |
function reverse($n){ | |
if (strlen($n)==0) { | |
return ''; | |
} | |
return substr($n, -1) . reverse(substr($n, 0, -1)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isPalindrome(String $n) | |
{ | |
if (strlen($n) == 1) { | |
return $n; | |
} else { | |
$res = $n[0] + isPalindrome(substr($n, 1)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sumDigits($n) | |
{ | |
return ($n == 0) ? 0 : $n%10 + sumDigits($n/10); | |
} | |
// Driver Code | |
$n = 687; | |
$res = sumDigits($n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// A recursive PHP program to | |
// check whether a given number | |
// is palindrome or not | |
// A function that reurns true | |
// only if num contains one digit | |
function oneDigit($num) | |
{ | |
// comparison operation is faster |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer