A serie of programming exercises (Project Euler, Codility, ...) with solutions written in GO.
package goexercises
import "github.com/alesr/goexercises"
func BinaryGap(n int) int
BinaryGap -
https://codility.com/programmers/lessons/1-iterations/binary_gap/ Find
longest sequence of zeros in binary representation of an integer.
func CyclicRotation(arr []int, rotation int) []int
CyclicRotation -
https://codility.com/programmers/lessons/2-arrays/cyclic_rotation/
Rotate an array to the right by a given number of steps.
func EvenFibonacci(limit int) int
EvenFibonacci - https://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 million, find the sum of the even-valued
terms.
func FizzBuzzWoof(n, d1, d2, d3 int) string
FizzBuzzWoof receives n, d1, d2, d3 as positive integer as arguments and
returns:
Fizz -> if n is divisible by d1
Buzz -> if n is divisible by d2
Woof -> if n is divisible by d3
FizzBuzz -> if n is divisible by d1 and d2
FizzWoof -> if n is divisible by d1 and d3
BuzzWoof -> if n is divisible by d2 and d3
FizzBuzzWoof -> if n is divisible by d1 and d2 and d3
string(n) -> if n is not evenly divisible by any given divisor
func FrogJmp(x, y, d int) int
FrogJmp -
https://codility.com/programmers/lessons/3-time_complexity/frog_jmp/
Count minimal number of jumps from position X to Y.
func LargestPalindromeProd(n int) int
LargestPalindromeProd - https://projecteuler.net/problem=4 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.
func LargestPrimeFactor(n int) int
LargestPrimeFactor - https://projecteuler.net/problem=3 The prime
factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor
of the number 600851475143?
func MultiplesOf(n int) int
MultiplesOf - Multiples of 3 and 5 https://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.
func OddOccurrences(arr []int) int
OddOccurrences -
https://codility.com/programmers/lessons/2-arrays/odd_occurrences_in_array/start/
Find value that occurs in odd number of elements.
func PermCheck(slice []int) int
PermCheck -
https://codility.com/programmers/lessons/4-counting_elements/perm_check/
Check whether array A is a permutation.
func PermMissingElem(arr []int) int
PermMissingElem -
https://codility.com/programmers/lessons/3-time_complexity/perm_missing_elem/
Find the missing element in a given permutation.
func Prime10001(n int) int
Prime10001 - https://projecteuler.net/problem=7 By listing the first six
prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is
13. What is the 10 001st prime number?
func SmallestMultiple(n int) int
SmallestMultiple - https://projecteuler.net/problem=5 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?
func SumSqrDiff(n int) int
SumSqrDiff - https://projecteuler.net/problem=6 The sum of the squares
of the first ten natural numbers is, 12 + 22 + ... + 102 = 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. Find the difference between the sum of the squares of the first
one hundred natural numbers and the square of the sum.
func TapeEquilibrium(slice []int) int
TapeEquilibrium -
https://codility.com/programmers/lessons/3-time_complexity/tape_equilibrium/
Minimize the value `|(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|`