Skip to content

Instantly share code, notes, and snippets.

View pmgupte's full-sized avatar
🤠
busy! I may be slow to respond.

Prabhas Gupte pmgupte

🤠
busy! I may be slow to respond.
View GitHub Profile
@pmgupte
pmgupte / project-euler-06.php
Last active December 28, 2015 18:09
PHP solution to Project Euler problem # 6.
<?php
/**
* Problem 6: Sum square difference
*
* The sum of the squares of the first ten natural numbers is,
* 1^2 + 2^2 + ... + 10^2 = 385
* The square of the sum of the first ten natural numbers is,
* (1 + 2 + ... + 10)^2 = 552 = 3025
* Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
*
@pmgupte
pmgupte / project-euler-05.php
Created November 19, 2013 07:01
PHP solution to Project Euler problem # 5.
<?php
/**
* Problem 5: Smallest multiple
*
* 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
* What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
*/
$evenlyDivisible = false;
$limit = 20;
for($i=$limit; !$evenlyDivisible; $i+=$limit) {
@pmgupte
pmgupte / project-euler-04.php
Created November 19, 2013 07:00
PHP solution to Project Euler problem # 4.
<?php
/**
* Problem 4: Largest palindrome product
*
* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
* Find the largest palindrome made from the product of two 3-digit numbers.
*/
$largest=101;
$l1 = $l2 = 999;
for ($i=999; $i>=100; $i--) {
@pmgupte
pmgupte / project-euler-03.php
Created November 19, 2013 06:59
PHP solution to Project Euler problem # 3.
<?php
/**
* Problem 3: Largest prime factor
*
* The prime factors of 13195 are 5, 7, 13 and 29.
* What is the largest prime factor of the number 600851475143 ?
*/
$n = 600851475143;
$factor = 2;
$lastFactor = 1;
@pmgupte
pmgupte / array_in_array.php
Last active December 27, 2015 15:59
PHP function to check whether all elements from one array are present in another array.
<?php
/**
* Check whether all elements from $needle array are present in $haystack array.
* Works for single-dimentional arrays only.
* If you use multi-dimentional arrays, result could be misterious.
* @param array $needle
* @param array $haystack
* @return boolean true if all elements in $needle are found in $haystack. false otherwise.
*/
function array_in_array($needle, $haystack) {
@pmgupte
pmgupte / project-euler-02-sol-2.php
Last active December 22, 2015 03:29
My PHP solution to Project Euler problem # 2 - http://projecteuler.net/problem=2 - Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four m…
<?php
$n1 = 1;
$n2 = 1;
$n3 = $n1 + $n2;
$sum = 0;
while($n3 < 4000000) {
$sum += $n3;
$n1 = $n2 + $n3;
$n2 = $n1 + $n3;
$n3 = $n1 + $n2;
@pmgupte
pmgupte / project-euler-01.php
Last active December 22, 2015 03:19
My PHP solution to Project Euler problem # 1 http://projecteuler.net/problem=1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
<?php
$sum = 0;
for ($i = 0; $i < 1000; $i++) {
if (!($i % 3) || !($i % 5)) {
$sum += $i;
}
}
echo $sum;
?>
Programming Laguages
PHP - currenly my bread and butter is earned with this language only
Javascript
Ruby
Editors
Eclipse, with PDT - on ubuntu as well as windows. This is my preferred editor
vim - only when working on terminal
nodepad++ - only when working on windows
Sublime Text 2 - trying this editor on linux as well as windows
Source Code Control
# to get matching line and 5 lines before that
grep -B 5 "pattern" file
# to get matching line and 5 lines after that
grep -A 5 "pattern" file
# of course, you can combine -A and -B options together in single command. That's obvious.
# if your -A and -B values are same, you need not specify both the options. use -C instead.
grep -C 5 "pattern" file