mostyfriedman's Contributions
Below are the tutorials, code snippets, and resources mostyfriedman has submitted to dream.in.code. For more information on Kudos and contributing to dream.in.code visit: http://home.dreamincode.net/?p=about#kudos.
Tutorials
Code Snippets
 Binary Search in Java Submitted: November 11, 2008        Views: 1215
 Deleted: Calculating the number of permutations P(n, r) in Java Submitted: July 4, 2009        Views: 365 given n and r, the sippets calculates the number of different permutations to choose r elements from n. The formula for P(n, r) = n!/(n-r)! but of course if n is large it will be very inefficient to compute the factorial first then plug it in the formula, instead we can use this property that P(n, r) = P(n, r-1)*n-(r-1) and that P(n, 0) = 1 and P(n, 1) = n. it can be done using an array and on each iteration we look at the previous cell which holds the value for p(n,k-1) or to save memory we can instead accumulate the result in a variable.
 Submitted: July 5, 2009        Views: 2053 given n and r, the snippet calculates the number of different permutations to choose r elements from n elements. The formula for P(n, r) = n!/(n-r)! but of course if n is large it will be very inefficient to compute the factorial first then plug it in the formula, instead we can use this property that P(n, r) = P(n, r-1)*n-(r-1) and that P(n, 0) = 1 and P(n, 1) = n. it can be done using an array of size r and on each iteration we look at the previous cell which holds the value for p(n,i-1) or to save memory we can instead accumulate the result in a variable.
 Checks if a number is prime or not in PROLOG in Other Languages Submitted: March 29, 2009        Views: 9375 a snippet in PROLOG that checks if a number is prime or not
 Submitted: July 1, 2009        Views: 4217 just a small snippet to compute the binomial Coefficient nCk.. mathematically to compute the binomial coefficient ncK = n!/k!(n-k)! but if n is too large, computing it will be very inefficient, instead there's a recursive formula nCk = (n-1)C(k-1)+(n-1)Ck, so this can be used in a dynamic programming approach...also to speed things up, binomial Coefficients have this identity that nCk = nC(n-k), so we can use this to minimize the number of terms computed
 Factorial in prolog in Other Languages Submitted: March 27, 2009        Views: 6416 the predicate returns true if Y is the factorial of X
 Fibonacci even sum in Java Submitted: November 15, 2008        Views: 2499 my solution to a problem that i solved on www.projecteuler.net...this method sums the even terms in the fibonacci series that aren't greater than n
 Fibonacci in prolog in Other Languages Submitted: March 25, 2009        Views: 14600 an example of the fibonacci series in prolog, the function will return true, if Y is the fibonacci value of X
 Finding all permutations of a list(PROLOG) in Other Languages Submitted: April 9, 2009        Views: 9775 a snippet that lists all the possible permutations of a list
 GCD in prolog in Other Languages Submitted: March 25, 2009        Views: 5712 a simple snippet in prolog to find the greatest common divisor of 2 numbers
 Insertion sort of a list (PROLOG) in Other Languages Submitted: April 20, 2009        Views: 5525 the predicate insertionsort returns true if R is the sorted list of [H|T]
 Logical expressions in Other Languages Submitted: August 8, 2009        Views: 623 a snippet that evaluates and simplifies logical expressions
 Submitted: August 23, 2010        Views: 1421 This snippet finds the maximum non-negative sum of contiguous elements in an array, using Kadane's algorithm. This algorithm is an example of a greedy algorithm, the running time is O(n)
 Palindrome checker in Java Submitted: November 29, 2008        Views: 2175 checks whether a string is a palindrome or not..a palindrome is a string that could be read backwards the same way it could be read forward example: mom dad
 Submitted: January 3, 2009        Views: 22639 checks if the given string is a palindrome using recursion.
 Prime Factorisation in Java Submitted: December 29, 2008        Views: 2360 a small algorithm to find the prime factors of a number
 Prime number tester (HASKELL) in Other Languages Submitted: April 21, 2009        Views: 4267 the function isprime finds if the number is prime or not
 Reversing a list (PROLOG) in Other Languages Submitted: April 9, 2009        Views: 6902 a simple snippet to reverse a list in prolog
 Selection Sort in java in Java Submitted: February 18, 2009        Views: 6810
 Selection sort of a list (PROLOG) in Other Languages Submitted: April 20, 2009        Views: 3662 the predicate returns true if [X|Z] is the ordered representation of list R
 String Permutations in Java Submitted: September 15, 2009        Views: 1057 finding all permutations of a string recursively
 Submitted: November 19, 2008        Views: 12657 this method takes an integer as an argument and returns the sum of digits in that integer. Example: if the integer is 123, the method will return 1+2+3 = 6.
 Sum of digits of a number (in PROLOG) in Other Languages Submitted: March 29, 2009        Views: 4084 a simple snippet to find the sum of digits of a given number in PROLOG