Skip to content

m-housni/coding-challenges

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coding Challenges

A list of coding challenges I've solved in different languages

  1. D0: basic
  2. D1: easy
  3. D2: hard
  4. D3: very hard

Project Euler

Longest Collatz sequence

  • The following iterative sequence is defined for the set of positive integers:
  • n → n/2 (n is even)
  • n → 3n + 1 (n is odd)
  • Using the rule above and starting with 13, we generate the following sequence:
  • 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
  • It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is * thought that all starting numbers finish at 1.
  • Which starting number, under one million, produces the longest chain?
  • NOTE: Once the chain starts the terms are allowed to go above one million.
  • n/2 = 1 => n=2 , n/2=2 => n=4 , n=8 or n=1, n = 16, n=32 or n=5 => n=64

Target number from two arrays

Highly divisible triangular number

  • The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first * ten terms would be:
  • 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
  • Let us list the factors of the first seven triangle numbers:
  • 1: 1
  • 3: 1,3
  • 6: 1,2,3,6
  • 10: 1,2,5,10
  • 15: 1,3,5,15
  • 21: 1,3,7,21
  • 28: 1,2,4,7,14,28
  • We can see that 28 is the first triangle number to have over five divisors.
  • What is the value of the first triangle number to have over five hundred divisors?
  • https://github.com/m-housni/coding-challenges/blob/main/D2/highlyDivisibleTriangularNumber.py

Largest product in a grid

What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?*

Summation of primes

Special Pythagorean triplet

Is given number prime (D0)

Largest product in a series

  • The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
  • 73167176531330624919225119674426574742355349194939698352031277450632623957831801698480186947885184858615607891129494954595017379583319528532088055112540698747158523863050715693290963295227443043556689664895044524452316173185640309871112172238311362229893423380308135336276614282806444486645238749303589072962904915604407723907138105158593079608667017242712188399879790879227492190169972088809377665727333001053367881220235421809751254540594752243525849077116705560136048395864467063244157221553975369781797784617406495514929086256932197846862248283972241375657056057490261407972968652414535100474821663704844031998900088952434506585412275886668811642717147992444292823086346567481391912316282458617866458359124566529476545682848912883142607690042242190226710556263211111093705442175069416589604080719840385096245544436298123098787992724428490918884580156166097919133875499200524063689912560717606058861164671094050775410022569831552000559357297257163626956188267042825248360082325753042075296345
  • Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
  • https://github.com/m-housni/coding-challenges/blob/main/D1/largestProductInSerie.py

10001st prime

Sum square difference (D0)

  • 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 = 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.
  • https://github.com/m-housni/coding-challenges/blob/main/D0/sumSquareDiff.py

Smallest multiple

is Pelindrom (D0)

Number to array (D0)

Largest palindrome product

Largest prime factor

Even Fibonacci numbers

Multiples of p and q (D1)

Multiples of 3 and 5 (D1)

findTarget (D0)

Given a list of integers and a target integer this function will return the index of the target if it exists or None (null in python)

hasInfiniteLoop (D3)

Write a function which takes a peice of code as input and returns true if the program has an infinite loop and false otherwise.

searchSubArraysSumsToK (D2)

Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals k.

sortingAlgorithms (D2)

  1. Bubble sort
  2. Selection sort
  3. Swap sort
  4. Insertion sort
  5. Merge sort
  6. Quick sort

isSubsequentArray (D2)

Given two arrays of integers arr1 and arr2, arr2 is subsequent array of arr1 if arr1 includes all elements of arr2 in the same order but not necessarily adjacent.

Example: [2,0,4] is subsequent array of [1,2,3,0,4]