Skip to content

Instantly share code, notes, and snippets.

View belushkin's full-sized avatar
🎉
Hi there!

Maksym Bielushkin belushkin

🎉
Hi there!
View GitHub Profile
@belushkin
belushkin / Main.scala
Created April 22, 2015 19:33
Recursion scala exercises
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()
<?php
// Regular recursion
function factorial ($n)
{
if ($n == 1 ) {
return 1;
}
return $n * factorial($n-1);
}
@belushkin
belushkin / gist:beb83b94f6e5b438e86f00ac46e53f98
Last active September 26, 2018 16:25
Pascal's triangle in PHP
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";
@belushkin
belushkin / gist:07cabb5b56320e0e687afce64c643b9c
Last active September 26, 2018 16:24
Balanced unbalanced string
<?php
// (if (zero? x) max (/ 1 x))
function balance($str)
{
function loop($str, $acc)
{
if (empty($str)) {
return $acc == 0;
}
@belushkin
belushkin / gist:6f0b0085777e05ec21e816ddeb5c227a
Last active September 26, 2018 16:24
Google preparation
<?php
$n = 236;
function reverse($n){
if (strlen($n)==0) {
return '';
}
return substr($n, -1) . reverse(substr($n, 0, -1));
}
@belushkin
belushkin / gist:b1d49ab482413780cf9682ccdda610e5
Last active September 26, 2018 16:24
Sum of Digit is Pallindrome or not
<?php
function isPalindrome(String $n)
{
if (strlen($n) == 1) {
return $n;
} else {
$res = $n[0] + isPalindrome(substr($n, 1));
}
<?php
function sumDigits($n)
{
return ($n == 0) ? 0 : $n%10 + sumDigits($n/10);
}
// Driver Code
$n = 687;
$res = sumDigits($n);
@belushkin
belushkin / gist:51db91e185129ac8a17d41d7e372d699
Created September 26, 2018 16:22
Check if a number is Palindrome, fixed GeeksForGeeks version
<?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.