This file contains hidden or 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 | |
/** | |
* 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. | |
* |
This file contains hidden or 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 | |
/** | |
* 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) { |
This file contains hidden or 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 | |
/** | |
* 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--) { |
This file contains hidden or 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 | |
/** | |
* 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; |
This file contains hidden or 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 | |
/** | |
* 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) { |
This file contains hidden or 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 | |
$n1 = 1; | |
$n2 = 1; | |
$n3 = $n1 + $n2; | |
$sum = 0; | |
while($n3 < 4000000) { | |
$sum += $n3; | |
$n1 = $n2 + $n3; | |
$n2 = $n1 + $n3; | |
$n3 = $n1 + $n2; |
This file contains hidden or 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 | |
$sum = 0; | |
for ($i = 0; $i < 1000; $i++) { | |
if (!($i % 3) || !($i % 5)) { | |
$sum += $i; | |
} | |
} | |
echo $sum; | |
?> |
This file contains hidden or 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
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 |
This file contains hidden or 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
# 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 |