Skip to content

Instantly share code, notes, and snippets.

@gregberns
Last active June 3, 2017 22:31
Show Gist options
  • Save gregberns/bc0ef7b8fe2c83ca880498f1ea1038e2 to your computer and use it in GitHub Desktop.
Save gregberns/bc0ef7b8fe2c83ca880498f1ea1038e2 to your computer and use it in GitHub Desktop.

Programming Problems

Below are several programming problems. Try and solve them without Googling the answers.

Factorial

Create a function(s) that takes an integer and returns its factorial.

Example: Takes 3, returns (1 * 2 * 3) or 6

Bonus points: use recursion

FizzBuzz

FizzBuzz is a game where players count up, and if the number is divisible by 3 they say 'Fizz' instead of the number. If the number is divisible by '5' they say 'Buzz', and if it is divisible by 3 and 5 they say 'FizzBuzz'.

Example: 1, 2, 'Fizz', 4, 'Buzz', etc.

Create a function(s) that executed the FizzBuzz problem, counting from 1 to 100.

Sum In List

Given a list of integers and a 'sum value' find two values in the list that when added together equal the 'sum value'. The list of integers is already sorted.

Example 1:

List: [1,2,3,9]

Sum: 8

This has no two numbers which when added togher equal 8. (Make sure you have a way of representing an empty return value.)

Example 2:

List: [1,2,4,4]

Sum: 8

Function would return 4 and 4.

Hint: there are several ways of solving this. The more ways you find, the better. Also bonus points if you can explain their Big O value.

SuperSize Me

Write a function that rearranges an integer into its largest possible value.

superSize 123456 `shouldBe` 654321
superSize    105 `shouldBe`    510
superSize     12 `shouldBe`     21

If the argument passed through is single digit or is already the maximum possible integer, your function should simply return it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment