## Coding solutions

Problems and solutions explained and implemented with multiple programming languages

## Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same element twice.Example:Given nums = [2, 7, 11, 15], target = 9,Because nums + nums = 2 + 7 = 9,re... [...]

## Mutliples of 3 and 5

The problem: 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.It appears on Project Euler and the solution seems very easy. Maybe it hides some trick or trap but we want to keep the solution and the related... [...]

## Singleton: pattern or anti-pattern?

Many people consider the singleton an anti-pattern. Many others think it's part of the creational patterns family. I don't care about its definition and I think a singleton can be useful sometimes in the real world! Singleton design pattern is used when you want to have only one instance of a given class. Let's... [...]

## Prime Number

Let's find if a number is prime. A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. The first few prime numbers are {2, 3, 5, 7, 11, ….}.Here we have some solutions:PHP: using bcmod and a for loopfunction isPrimeNumber(int \$num){ for (\$i... [...]

## Leap Year

Let's check if a year is a leap year.Rules for determining a Leap YearMost years that can be divided evenly by 4 are leap years. (For example, 2016 divided by 4 = 504: Leap year!)Exception: Century years are NOT leap years UNLESS they can be evenly divided by 400. (For example, 1700, 1800, and 1900 were not leap years, b... [...]

## Fibonacci numbers

Let's see how to print the Fibonacci numbers. The formula expects we will have big numbers so we will be ready to print big numbers without any overflow error. Before showing some code, I want to leave some useful links:Fibonacci on WikipediaFibonacci Number      [...]

## Prime Factors

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pulvinar pharetra vestibulum. Proin aliquet justo sit amet mauris volutpat pellentesque. Proin facilisis consectetur tellus. In porttitor quis turpis vitae tempus. Aenean eget volutpat purus, vel cursus odio. Maecenas tempus, elit ac feugiat finibus, quam lectus pretium ex, ut pharetr... [...]

## Factorial

The factorial function (symbol: !) says to multiply all whole numbers from our chosen number down to 1.Examples:4! = 4 × 3 × 2 × 1 = 247! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 50401! = 1Wikipedia.PHP: using gmp_fact functionA native PHP function called gmp_fact is ava... [...]

## Palindrome words

A palindrome is a word, number, phrase, or other sequences of characters which reads the same backward as forward, such as madam or racecar or the number 10801. Sentence-length palindromes may be written when allowances are made for adjustments to capital letters, punctuation, and word dividers... [...]