├── July_26
├── squared_divisors.md
├── count_smileys.rb
├── squared_divisors.rb
├── count_duplicates.rb
├── example_solutions
│ ├── count_duplicates.rb
│ ├── count_smileys.rb
│ └── squared_divisors.rb
├── count_duplicates.md
├── optimzation-example.md
└── count_smileys.md
├── August_3
├── hashtag_generator.rb
├── gaps_in_primes.rb
├── prime_factorization.rb
├── tribonnaci_sequence.rb
├── example_solutions
│ ├── tribonacci_sequence.rb
│ ├── hashtag_generator.rb
│ ├── gaps_in_primes.rb
│ └── prime_factorization.rb
├── prime_factorization.md
├── hashtag_generator.md
├── tribonnaci_sequence.md
└── gaps_in_primes.md
├── September_20
├── remove_duplicates.rb
├── example_solutions
│ ├── count_smileys.rb
│ ├── remove_duplicates.rb
│ ├── largest_prime_factor.rb
│ ├── expanded_notation.rb
│ └── fizzbuzz.rb
├── fizzbuzz.rb
├── count_smileys.rb
├── expanded_notation.rb
├── largest_prime_factor.rb
├── remove_duplicates.md
├── expanded_notation.md
├── largest_prime_factor.md
├── fizzbuzz.md
└── count_smileys.md
├── January_19
├── node.rb
├── example_solutions
│ ├── node.rb
│ └── linked_list.rb
├── linked_list.rb
└── linked_list.md
├── September_6
├── see_saw_array.rb
├── lonely_number.rb
├── most_occuring_word.rb
├── lonely_number.md
├── most_occuring_word.md
└── see_saw_array.md
├── August_9
├── two-sum.rb
├── iq-test.rb
├── expanded_notation.rb
├── time_conversion.rb
├── example_solutions
│ ├── time_conversion.rb
│ ├── expanded_notation.rb
│ ├── iq_test.rb
│ └── two_sum.rb
├── expanded_notation.md
├── two-sum.md
├── time_conversion.md
└── iq-test.md
├── July_19
├── even_fibonnaci_numbers.rb
├── largest_palindrome_product.rb
├── largest_prime_factor.rb
├── largest_prime_factor.md
├── largest_palindrome_product.md
├── even_fibonnaci_numbers.md
└── example_solutions
│ ├── even_fibonaci_numbers.rb
│ ├── largest_prime_factor.rb
│ └── largest_palindrome_product.rb
├── August_30
├── count_letters_in_string.rb
├── playing_with_digits.rb
├── contains_substrings.rb
├── palindrome_chain_length.rb
├── example_solutions
│ ├── contains_substrings.rb
│ ├── playing_with_digits.rb
│ ├── palindrome_chain_length.rb
│ └── count_letters_in_strings.rb
├── contains_substrings.md
├── count_letters_in_string.md
├── playing_with_digits.md
└── palindrome_chain_length.md
├── August_17
├── last_digit_of_large_number.rb
├── balanced_parenthesis.rb
├── palindrome_permutation.rb
├── example_solutions
│ ├── last_digit_of_large_number.rb
│ ├── palindrome_permutation.rb
│ └── balanced_parenthesis.rb
├── palindrome_permutation.md
├── balanced_parenthesis.md
└── last_digit_of_large_number.md
├── Workshop
├── second_largest_sum.md
├── prime_factorization.md
├── remove_duplicates.md
├── two_sum.md
└── make_anagrams.md
├── October_18
├── break_camelcase.md
└── take_a_walk.md
├── September_27
├── largest_two_terms.md
├── prime_factorization.md
└── make_anagrams.md
├── LICENSE
├── README.md
└── November_1
└── linked_list.md
/July_26/squared_divisors.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/August_3/hashtag_generator.rb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/September_20/remove_duplicates.rb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/September_20/example_solutions/count_smileys.rb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/September_20/example_solutions/remove_duplicates.rb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/September_20/example_solutions/largest_prime_factor.rb:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/September_20/fizzbuzz.rb:
--------------------------------------------------------------------------------
1 | def fizzbuzz
2 | # your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_3/gaps_in_primes.rb:
--------------------------------------------------------------------------------
1 | def gap(g, m, n)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/January_19/node.rb:
--------------------------------------------------------------------------------
1 | class Node
2 | def initialize
3 |
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/September_6/see_saw_array.rb:
--------------------------------------------------------------------------------
1 | def balanced?(see_saw_array)
2 |
3 | end
4 |
--------------------------------------------------------------------------------
/August_9/two-sum.rb:
--------------------------------------------------------------------------------
1 | def two_sum(array, target)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/July_26/count_smileys.rb:
--------------------------------------------------------------------------------
1 | def count_smileys(array)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/July_26/squared_divisors.rb:
--------------------------------------------------------------------------------
1 | def list_squared(m,n)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_9/iq-test.rb:
--------------------------------------------------------------------------------
1 | def iq_test(string_of_numbers)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/July_19/even_fibonnaci_numbers.rb:
--------------------------------------------------------------------------------
1 | def even_fib_sum
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/July_26/count_duplicates.rb:
--------------------------------------------------------------------------------
1 | def duplicate_count(text)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/September_6/lonely_number.rb:
--------------------------------------------------------------------------------
1 | def lonely_number(array)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_3/prime_factorization.rb:
--------------------------------------------------------------------------------
1 | def prime_factorization(n)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_30/count_letters_in_string.rb:
--------------------------------------------------------------------------------
1 | def count_letters(string)
2 | #your code
3 | end
4 |
--------------------------------------------------------------------------------
/August_9/expanded_notation.rb:
--------------------------------------------------------------------------------
1 | def expanded_notation(number)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_9/time_conversion.rb:
--------------------------------------------------------------------------------
1 | def time_conversion(seconds)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_17/last_digit_of_large_number.rb:
--------------------------------------------------------------------------------
1 | def last_digit(n1, n2)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_3/tribonnaci_sequence.rb:
--------------------------------------------------------------------------------
1 | def tribonacci(signature, n)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_30/playing_with_digits.rb:
--------------------------------------------------------------------------------
1 | def digit_power(num, exponent)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/July_19/largest_palindrome_product.rb:
--------------------------------------------------------------------------------
1 | def largest_palindrome
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/September_20/count_smileys.rb:
--------------------------------------------------------------------------------
1 | def count_smileys(smiley_array)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/September_20/expanded_notation.rb:
--------------------------------------------------------------------------------
1 | def expanded_form(integer)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/September_6/most_occuring_word.rb:
--------------------------------------------------------------------------------
1 | def most_occuring_word(string)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_17/balanced_parenthesis.rb:
--------------------------------------------------------------------------------
1 | def balanced_parentheses(string)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_30/contains_substrings.rb:
--------------------------------------------------------------------------------
1 | def contains_substring?(arr1, arr2)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_17/palindrome_permutation.rb:
--------------------------------------------------------------------------------
1 | def palindrome_permutation(string)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/August_30/palindrome_chain_length.rb:
--------------------------------------------------------------------------------
1 | def palindrome_chain_length(num)
2 | #your code here
3 | end
4 |
--------------------------------------------------------------------------------
/September_20/largest_prime_factor.rb:
--------------------------------------------------------------------------------
1 | def largest_prime_factor(integer)
2 | # your code here
3 | end
4 |
--------------------------------------------------------------------------------
/July_19/largest_prime_factor.rb:
--------------------------------------------------------------------------------
1 | def largest_prime_factor(n)
2 | #your code here
3 | end
4 |
5 | largest_prime_factor(600851475143)
6 |
--------------------------------------------------------------------------------
/July_19/largest_prime_factor.md:
--------------------------------------------------------------------------------
1 | ## Largest Prime Factor
2 |
3 | The prime factors of 13195 are 5, 7, 13 and 29.
4 |
5 | What is the largest prime factor of the number 600851475143 ?
6 |
--------------------------------------------------------------------------------
/August_9/example_solutions/time_conversion.rb:
--------------------------------------------------------------------------------
1 | def conversion(seconds)
2 | h = seconds/ 3600
3 | seconds = seconds % 3600
4 | min = seconds / 60
5 | seconds = seconds % 60
6 | s = seconds
7 | return [h,min,s]
8 | end
9 |
--------------------------------------------------------------------------------
/January_19/example_solutions/node.rb:
--------------------------------------------------------------------------------
1 | class Node
2 | attr_accessor :value, :next_node
3 |
4 | def initialize(value, next_node = nil)
5 | @value = value
6 | @next_node = next_node
7 | end
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/August_3/example_solutions/tribonacci_sequence.rb:
--------------------------------------------------------------------------------
1 | def tribonacci(signature,n)
2 | #your code here
3 | array = signature
4 | i = 3
5 | while i < n
6 | new_num = array[i-1]+array[i-2]+array[i-3]
7 | array << new_num
8 | i += 1
9 | end
10 | return array.slice(0,n)
11 | end
12 |
--------------------------------------------------------------------------------
/August_9/example_solutions/expanded_notation.rb:
--------------------------------------------------------------------------------
1 | def expanded_form(num)
2 | arr = []
3 | i = 0
4 | while num != 0
5 | digit = num % 10
6 | if digit != 0
7 | arr << digit * (10**i)
8 | end
9 | num = num / 10
10 | i += 1
11 | end
12 | return arr.reverse.join(" + ")
13 | end
14 |
--------------------------------------------------------------------------------
/September_20/example_solutions/expanded_notation.rb:
--------------------------------------------------------------------------------
1 | def expanded_form(num)
2 | arr = []
3 | i = 0
4 | while num != 0
5 | digit = num % 10
6 | if digit != 0
7 | arr << digit * (10**i)
8 | end
9 | num = num / 10
10 | i += 1
11 | end
12 | return arr.reverse.join(" + ")
13 | end
14 |
--------------------------------------------------------------------------------
/August_3/example_solutions/hashtag_generator.rb:
--------------------------------------------------------------------------------
1 | def generateHashtag(str)
2 | # ...
3 | if str == ""
4 | return false
5 | else
6 | result = "#" + str.split(" ").map { |word| word.capitalize }.join("")
7 | end
8 |
9 | if result.length > 140
10 | return false
11 | end
12 | return result
13 | end
14 |
--------------------------------------------------------------------------------
/August_30/example_solutions/contains_substrings.rb:
--------------------------------------------------------------------------------
1 | def contains_substrings(array1, array2)
2 | matches = []
3 | array1.each do |substring|
4 | array2.each do |potential_match|
5 | if potential_match.include?(substring)
6 | matches << substring
7 | end
8 | end
9 | end
10 | return matches.uniq.sort
11 | end
12 |
--------------------------------------------------------------------------------
/September_20/example_solutions/fizzbuzz.rb:
--------------------------------------------------------------------------------
1 | def fizzbuzz
2 | i = 0
3 | while i < 100
4 | fizz = i % 3 == 0
5 | buzz = i % 5 == 0
6 | if fizz && buzz
7 | puts "fizzbuzz"
8 | elsif buzz
9 | puts "buzz"
10 | elsif fizz
11 | puts "fizz"
12 | else
13 | puts i
14 | end
15 | i += 1
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/Workshop/second_largest_sum.md:
--------------------------------------------------------------------------------
1 | ## Second Largest Sum
2 |
3 | Given an array of unique, non-sorted numbers, return the second largest sum of any two numbers in the array.
4 |
5 | ### Examples
6 |
7 | ```ruby
8 | array = [1,23,4,6,10]
9 | second_largest_sum(array)
10 | => 29
11 |
12 | array = [10,2,5,7,9]
13 | second_largest_sum(array)
14 | => 17
15 | ```
16 |
--------------------------------------------------------------------------------
/August_9/example_solutions/iq_test.rb:
--------------------------------------------------------------------------------
1 | def iq_test(string_of_numbers)
2 | #your code here
3 | numbers_array = numbers.split(" ").map(&:to_i)
4 | if numbers_array.select { |num| num % 2 == 0 }.count == 1
5 | return numbers_array.find_index { |num| num % 2 == 0 } + 1
6 | else
7 | return numbers_array.find_index { |num| num % 2 == 1 } + 1
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/August_17/example_solutions/last_digit_of_large_number.rb:
--------------------------------------------------------------------------------
1 | def last_digit(n1, n2)
2 | #your code here
3 | last_digit = n1 % 10
4 | if last_digit == 0
5 | return 0
6 | elsif n2 == 0
7 | return 1
8 | else
9 | multiple_of_4 = n2 % 4
10 | if multiple_of_4 == 0
11 | multiple_of_4 = 4
12 | end
13 | return n1 ** (multiple_of_4) % 10
14 | end
15 |
--------------------------------------------------------------------------------
/July_19/largest_palindrome_product.md:
--------------------------------------------------------------------------------
1 | ## Largest Palindrome Product (3 digits)
2 |
3 | A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
4 |
5 | Find the largest palindrome made from the product of two 3-digit numbers.
6 |
7 | Bonus: Try to check whether a number is a palindrome WITHOUT using to_s or to_a
8 |
--------------------------------------------------------------------------------
/October_18/break_camelcase.md:
--------------------------------------------------------------------------------
1 | ## theStrawThatBrokeTheCamelsBack
2 |
3 | Write a function, ```straw```, which takes in a string in camelCase, and returns a string with spaces between each word.
4 |
5 | ### Examples
6 |
7 | ```ruby
8 | straw("theStrawThatBrokeTheCamelsBack")
9 | => "the Straw That Broke The Camels Back"
10 |
11 | straw("camelCase")
12 | => "camel Case"
13 | ```
14 |
--------------------------------------------------------------------------------
/July_19/even_fibonnaci_numbers.md:
--------------------------------------------------------------------------------
1 | ## Even Fibonacci Numbers
2 |
3 | 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:
4 |
5 | 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
6 |
7 | By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
8 |
--------------------------------------------------------------------------------
/August_30/example_solutions/playing_with_digits.rb:
--------------------------------------------------------------------------------
1 | def dig_pow(n, p)
2 | k = n
3 | digits_arr = []
4 | while k > 0
5 | digits_arr << k % 10
6 | k = k / 10
7 | end
8 |
9 | digits_arr = digits_arr.reverse
10 |
11 | sum = 0
12 | i = 0
13 | while i < digits_arr.length
14 | sum += digits_arr[i] ** (p + i)
15 | i += 1
16 | end
17 |
18 | return sum / n
19 | end
20 |
--------------------------------------------------------------------------------
/July_19/example_solutions/even_fibonaci_numbers.rb:
--------------------------------------------------------------------------------
1 | def fib(n)
2 | if n == 1
3 | return 1
4 | elsif n == 2
5 | return 2
6 | else
7 | return fib(n-1) + fib(n-2)
8 | end
9 | end
10 |
11 | def fib_sum
12 | sum = 0
13 | i = 1
14 | until fib(i) > 4000000
15 | if fib(i) % 2 == 0
16 | sum += fib(i)
17 | end
18 | i += 1
19 | end
20 | return sum
21 | end
22 |
--------------------------------------------------------------------------------
/August_17/example_solutions/palindrome_permutation.rb:
--------------------------------------------------------------------------------
1 | def palindrome_permutation(string)
2 | hash = {}
3 | string.chars.each do |letter|
4 | if !hash[letter]
5 | hash[letter] = 1
6 | else
7 | hash[letter] += 1
8 | end
9 | end
10 |
11 | number_of_odds = hash.select { |key, value| value.odd? }.count
12 | return false if number_of_odds > 1
13 | return true
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/August_30/example_solutions/palindrome_chain_length.rb:
--------------------------------------------------------------------------------
1 | def palindrome_chain_length(n)
2 | chain = 0
3 | until n == reverse(n)
4 | n = n + reverse(n)
5 | chain += 1
6 | end
7 | return chain
8 | end
9 |
10 | def reverse(number)
11 | n = number
12 | new_num = 0
13 | while n != 0
14 | new_num = (new_num) * 10 + n % 10
15 | n = n / 10
16 | end
17 | return new_num
18 | end
19 |
--------------------------------------------------------------------------------
/August_3/prime_factorization.md:
--------------------------------------------------------------------------------
1 | ## Prime Factorization
2 |
3 | Given a positive number n > 1 find the prime factor decomposition of n. The result will be a string with the following form :
4 |
5 | ```ruby
6 | "(p1**n1)(p2**n2)...(pk**nk)"
7 | ```
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | prime_factorization(86240)
13 | => ""(2**5)(5)(7**2)(11)""
14 |
15 | prime_factorization(200)
16 | => ""(2**3)(5**2)""
17 | ```
18 |
--------------------------------------------------------------------------------
/July_26/example_solutions/count_duplicates.rb:
--------------------------------------------------------------------------------
1 | def duplicate_count(text)
2 | #your code here
3 | dupes = {}
4 | text.chars.each do |letter|
5 | if !dupes.key?(letter.downcase)
6 | dupes[letter.downcase] = 0
7 | else
8 | dupes[letter.downcase] += 1
9 | end
10 | end
11 | dupe_count = dupes.keep_if { |key, value| value >= 1 }.length
12 | return dupe_count
13 | end
14 |
--------------------------------------------------------------------------------
/September_27/largest_two_terms.md:
--------------------------------------------------------------------------------
1 | ## Second Largest Sum
2 |
3 | Given an array of non-sorted numbers, return the second largest sum of any two numbers in the array.
4 |
5 | **Note:** You are NOT allowed to use the ```#max``` method
6 |
7 | ### Examples
8 |
9 | ```ruby
10 | array = [1,23,4,6,10]
11 | second_largest_sum(array)
12 | => 29
13 |
14 | array = [10,2,5,7,9]
15 | second_largest_sum(array)
16 | => 17
17 | ```
18 |
--------------------------------------------------------------------------------
/Workshop/prime_factorization.md:
--------------------------------------------------------------------------------
1 | ## Prime Factorization
2 |
3 | Given a positive number n > 1 find the prime factor decomposition of n. The result will be a string with the following form :
4 |
5 | ```ruby
6 | "(p1**n1)(p2**n2)...(pk**nk)"
7 | ```
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | prime_factorization(86240)
13 | => ""(2**5)(5)(7**2)(11)""
14 |
15 | prime_factorization(200)
16 | => ""(2**3)(5**2)""
17 | ```
18 |
--------------------------------------------------------------------------------
/September_27/prime_factorization.md:
--------------------------------------------------------------------------------
1 | ## Prime Factorization
2 |
3 | Given a positive number n > 1 find the prime factor decomposition of n. The result will be a string with the following form :
4 |
5 | ```ruby
6 | "(p1**n1)(p2**n2)...(pk**nk)"
7 | ```
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | prime_factorization(86240)
13 | => ""(2**5)(5)(7**2)(11)""
14 |
15 | prime_factorization(200)
16 | => ""(2**3)(5**2)""
17 | ```
18 |
--------------------------------------------------------------------------------
/January_19/linked_list.rb:
--------------------------------------------------------------------------------
1 | require_relative 'node'
2 | class LinkedList
3 | def initialize
4 |
5 | end
6 |
7 | def last
8 |
9 | end
10 |
11 | def include?(search)
12 |
13 | end
14 |
15 | def print
16 |
17 | end
18 |
19 | def push(value)
20 |
21 | end
22 |
23 | def pop
24 |
25 | end
26 |
27 | def insert(value, insert_index)
28 |
29 | end
30 |
31 | def delete(search)
32 |
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/Workshop/remove_duplicates.md:
--------------------------------------------------------------------------------
1 | ## Remove Duplicates
2 |
3 | Write a method ```remove_dupes```, which takes in a string and returns a new string without any duplicate characters.
4 |
5 | Note: Do not use ```#uniq``` (that defeats the purpose of the whole exercise)
6 |
7 | ### Examples
8 |
9 | remove_dupes("string")
10 | => "string"
11 |
12 | remove_dupes("hahahahahahha")
13 | => "ha"
14 |
15 | remove_dupes("devbootcamp")
16 | => "devbotcamp"
17 |
--------------------------------------------------------------------------------
/August_17/example_solutions/balanced_parenthesis.rb:
--------------------------------------------------------------------------------
1 | def balanced_parantheses(string)
2 | parens_counter = 0
3 | string.each_char do |char|
4 |
5 | if char == '('
6 | parens_counter += 1
7 | elsif char == ')'
8 | parens_counter -= 1
9 | end
10 |
11 | if parens_counter < 0
12 | return false
13 | end
14 |
15 | end
16 | if parens_counter == 0
17 | return true
18 | end
19 |
20 | return false
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/September_20/remove_duplicates.md:
--------------------------------------------------------------------------------
1 | ## Remove Duplicates
2 |
3 | Write a method ```remove_dupes```, which takes in a string and returns a new string without any duplicate characters.
4 |
5 | Note: Do not use ```#uniq``` (that defeats the purpose of the whole exercise)
6 |
7 | ### Examples
8 |
9 | remove_dupes("string")
10 | => "string"
11 |
12 | remove_dupes("hahahahahahha")
13 | => "ha"
14 |
15 | remove_dupes("devbootcamp")
16 | => "devbotcamp"
17 |
--------------------------------------------------------------------------------
/August_9/expanded_notation.md:
--------------------------------------------------------------------------------
1 | ## Expanded Notation
2 |
3 | Write a function, ```expanded_form```, that takes a number ```n``` and returns the expanded notation of said number.
4 |
5 | For example, the expanded form of ```1337``` is ```1000+300+30+7```.
6 |
7 | ### Examples
8 | ```ruby
9 | expanded_form(12)
10 | => '10 + 2'
11 | expanded_form(42)
12 | => '40 + 2'
13 | expanded_form(70304)
14 | => '70000 + 300 + 4' #note how the tens and thousands place are ignored
15 | ```
16 |
--------------------------------------------------------------------------------
/September_6/lonely_number.md:
--------------------------------------------------------------------------------
1 | ## One is the Loneliest Number
2 |
3 | Write a method ```lonely_number``` which takes an array of numbers. The array will have exactly one unique number- every other number will be repeated at least once. Your method must return the lonely number.
4 |
5 | ### Examples
6 |
7 | ```ruby
8 | array = [123,234,123]
9 | lonely_number(array)
10 | => 234
11 |
12 | another_array = [2,2,6,3,8,6,2,3]
13 | lonely_number(another_array)
14 | => 8
15 | ```
16 |
--------------------------------------------------------------------------------
/September_20/expanded_notation.md:
--------------------------------------------------------------------------------
1 | ## Expanded Notation
2 |
3 | Write a function, ```expanded_form```, that takes a number ```n``` and returns the expanded notation of said number.
4 |
5 | For example, the expanded form of ```1337``` is ```1000+300+30+7```.
6 |
7 | ### Examples
8 | ```ruby
9 | expanded_form(12)
10 | => '10 + 2'
11 | expanded_form(42)
12 | => '40 + 2'
13 | expanded_form(70304)
14 | => '70000 + 300 + 4' #note how the tens and thousands place are ignored
15 | ```
16 |
--------------------------------------------------------------------------------
/September_20/largest_prime_factor.md:
--------------------------------------------------------------------------------
1 | ## Largest Prime Factor
2 |
3 | The prime factors of 13195 are 5, 7, 13 and 29. Therefore, the largest prime factor is 29.
4 |
5 | Write a function, ```largest_prime_factor```, which takes in an integer (note: this number might be very very large)
6 |
7 | ### Examples
8 |
9 | ```ruby
10 | largest_prime_factor(200000)
11 | => 5
12 | largest_prime_factor(1029381098109)
13 | => 1321
14 | largest_prime_factor(600851475143)
15 | => 6857
16 |
17 | ```
18 |
--------------------------------------------------------------------------------
/July_26/example_solutions/count_smileys.rb:
--------------------------------------------------------------------------------
1 | def count_smileys(arr)
2 | #your code here
3 | arr.select { |face| is_smiley(face) }.count
4 | end
5 |
6 | def is_smiley(face)
7 | valid_eyes = [':',';']
8 | valid_noses = ['-','~']
9 | valid_mouths = [')','D']
10 | if valid_eyes.include?(face[0])
11 | if valid_mouths.include?(face[1])
12 | return true
13 | elsif valid_noses.include?(face[1])
14 | if valid_mouths.include?(face[2])
15 | return true
16 | end
17 | end
18 | end
19 | return false
20 | end
21 |
--------------------------------------------------------------------------------
/July_19/example_solutions/largest_prime_factor.rb:
--------------------------------------------------------------------------------
1 | def largest_prime_factor(num)
2 | largest_factor = 0
3 | i = 2
4 | until i > num
5 | if num % i == 0 && is_prime(i)
6 | largest_factor = i
7 | num = num / i
8 | end
9 | i += 1
10 | end
11 | return largest_factor
12 | end
13 |
14 | def is_prime(n)
15 | if n <= 1
16 | return false
17 | elsif n == 2
18 | return true
19 | else
20 | i = 2
21 | until i > Math.sqrt(n)
22 | if n % i == 0
23 | return false
24 | end
25 | i += 1
26 | end
27 | end
28 | return true
29 | end
30 |
--------------------------------------------------------------------------------
/July_19/example_solutions/largest_palindrome_product.rb:
--------------------------------------------------------------------------------
1 | def largest_palindrome
2 | i = 999
3 | largest_palindrome = 0
4 | until i < 101
5 | j = 999
6 | until j < 101
7 | product = i * j
8 | if is_palindrome(product) && (product > largest_palindrome)
9 | largest_palindrome = i*j
10 | end
11 | j -= 1
12 | end
13 | i -= 1
14 | end
15 | return largest_palindrome
16 | end
17 |
18 | def palindrome?(number)
19 | n = number
20 | new_num = 0
21 | while n != 0
22 | new_num = (new_num) * 10 + n % 10
23 | n = n / 10
24 | end
25 | return number == new_num
26 | end
27 |
--------------------------------------------------------------------------------
/August_17/palindrome_permutation.md:
--------------------------------------------------------------------------------
1 | ## Palindrome Permutation
2 |
3 | A palindrome is a word or phrase that reads the same forward as it does backwards. Write a function, ```palindrome_permutation?```, which takes in a string, and returns whether it is a permutation of a palindrome. For example, ```"tact coa"``` is a permutation of a palindrome ```"taco cat"```.
4 |
5 | ### Examples
6 |
7 | ```ruby
8 | palindrome_permutation("nah nah")
9 | => true # "hannah" is a palindrome
10 |
11 | palindrome_permutation("nananan batman")
12 | => false
13 |
14 | palindrome_permutation("even odd never or")
15 | => true # "never odd or even" is a palindrome
16 |
--------------------------------------------------------------------------------
/August_9/two-sum.md:
--------------------------------------------------------------------------------
1 | ## Two-Sum
2 |
3 | Write a method that takes an array of non-sorted unique integers and a target integer ```t```, and returns true if two numbers in the array add up to ```t```.
4 |
5 | If no sum of two numbers in the array is equivalent to ```t```, return false.
6 |
7 | **Bonus**: Instead of returning true, return the *positions* of the two matching numbers in the array.
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | two_sum([1,5,6,8,10],13)
13 | => true, since 5 + 8 equals 13
14 | two_sum([9,3,2,13,21,34],34)
15 | => true, since 13 + 21 equals 34
16 | two_sum([17,4,6,13],13)
17 | => false, since no two numbers sum up to 13
18 | ```
19 |
--------------------------------------------------------------------------------
/Workshop/two_sum.md:
--------------------------------------------------------------------------------
1 | ## Two-Sum
2 |
3 | Write a method that takes an array of non-sorted unique integers and a target integer ```t```, and returns true if two numbers in the array add up to ```t```.
4 |
5 | If no sum of two numbers in the array is equivalent to ```t```, return false.
6 |
7 | **Bonus**: Instead of returning true, return the *positions* of the two matching numbers in the array.
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | two_sum([1,5,6,8,10],13)
13 | => true, since 5 + 8 equals 13
14 | two_sum([9,3,2,13,21,34],34)
15 | => true, since 13 + 21 equals 34
16 | two_sum([17,4,6,13],13)
17 | => false, since no two numbers sum up to 13
18 | ```
19 |
--------------------------------------------------------------------------------
/August_9/time_conversion.md:
--------------------------------------------------------------------------------
1 | ## Time Conversion
2 |
3 | Write a function ```time_conversion``` which takes in a number of ```seconds```, and returns an array containing the ```[hours, minutes, seconds]```.
4 |
5 | **Bonus**: Add an additional field, ```day```, so your array returns ```[days, hours, minutes, seconds]```
6 |
7 | ### Examples
8 |
9 | ```ruby
10 | time_conversion(3600)
11 | => [1,0,0] #3600 seconds is equivalent to exactly one hours
12 | time_conversion(23040)
13 | => [6,24,0] #equivalent to 6 hrs and 24 minutes
14 | time_conversion(1738)
15 | => [0,28,58] #equivalent to 24 minutes and 58 seconds
16 | time_conversion(90210)
17 | => [25,3,30]
18 |
--------------------------------------------------------------------------------
/September_20/fizzbuzz.md:
--------------------------------------------------------------------------------
1 | ## FizzBuzz
2 |
3 | Ah, FizzBuzz. The algorithm that's probably been [written](http://wiki.c2.com/?FizzBuzzTest) [about](https://blog.codinghorror.com/why-cant-programmers-program/) [more](http://codingbat.com/doc/practice/fizzbuzz-code.html) [times](https://www.tomdalling.com/blog/software-design/fizzbuzz-in-too-much-detail/) than it's actually been asked in an interview.
4 |
5 | The premise is simple: write a function that prints every number up to 100. There are three rules:
6 | - If the number is divisible by three, print ```fizz``` instead.
7 | - If it's divisible by five, print ```buzz```
8 | - If it's divisible by 3 AND 5, print ```fizzbuzz```.
9 |
--------------------------------------------------------------------------------
/August_3/hashtag_generator.md:
--------------------------------------------------------------------------------
1 | ## Hashtag Generator
2 |
3 | The marketing team are spending way too much time typing in hashtags.
4 | Let's help them with out own Hashtag Generator!
5 |
6 | Here's the deal:
7 |
8 | - If the final result is longer than 140 chars it must return false.
9 | - If the input is a empty string it must return false.
10 | - It must start with a hashtag (#).
11 | - All words must have their first letter capitalized.
12 |
13 | Example Input to Output:
14 |
15 | ```ruby
16 | hashtag_generator("Hello there thanks for trying my Kata")
17 | => "#HelloThereThanksForTryingMyKata"
18 |
19 | hashtag_generator("Hello World")
20 | => "#HelloWorld"
21 | ```
22 |
--------------------------------------------------------------------------------
/August_30/example_solutions/count_letters_in_strings.rb:
--------------------------------------------------------------------------------
1 | def character_count(string)
2 | letter_hash = {}
3 | string.chars.each do |char|
4 | if !letter_hash[char]
5 | letter_hash[char] = 1
6 | else
7 | letter_hash[char] += 1
8 | end
9 | end
10 | return letter_hash
11 | end
12 |
13 | def most_recurring_character(string)
14 | letter_hash = character_count(string)
15 | most_recurring = 0
16 | most_recurring_character = ""
17 | letter_hash.each do |letter, count|
18 | if count > most_recurring
19 | most_recurring = count
20 | most_recurring_character = letter
21 | end
22 | end
23 | return most_recurring_character
24 | end
25 |
--------------------------------------------------------------------------------
/July_26/example_solutions/squared_divisors.rb:
--------------------------------------------------------------------------------
1 | def list_squared(m, n)
2 | # your code
3 | list = []
4 | i = m
5 | until i == n
6 | if is_perfect_square?(sum_of_squared_divisors(i))
7 | list << [i, sum_of_squared_divisors(i)]
8 | end
9 | i += 1
10 | end
11 | return list
12 | end
13 |
14 | def sum_of_squared_divisors(n)
15 | divisors = []
16 | i = 1
17 | until i > Math.sqrt(n)
18 | if n % i == 0
19 | divisors << i
20 | divisors << n / i
21 | end
22 | i += 1
23 | end
24 | return divisors.uniq.map { |num| num * num }.reduce(:+)
25 | end
26 |
27 | def is_perfect_square?(n)
28 | if Math.sqrt(n) % 1 == 0
29 | return true
30 | end
31 | false
32 | end
33 |
--------------------------------------------------------------------------------
/July_26/count_duplicates.md:
--------------------------------------------------------------------------------
1 | ## Count Duplicates
2 |
3 | Write a function, count_duplicates, that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
4 |
5 | ### Examples
6 |
7 | ```ruby
8 | "abcde" -> 0 # no characters repeats more than once
9 | "aabbcde" -> 2 # 'a' and 'b'
10 | "aabBcde" -> 2 # 'a' occurs twice and 'b' twice (b and B)
11 | "indivisibility" -> 1 # 'i' occurs six times
12 | "Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice
13 | "aA11" -> 2 # 'a' and '1'
14 | "ABBA" -> 2 # 'A' and 'B' each occur twice
15 | ```
16 |
--------------------------------------------------------------------------------
/September_6/most_occuring_word.md:
--------------------------------------------------------------------------------
1 | ## Most Recurring Word
2 |
3 | Would the word 'wood' be the most recurring word in the sentence "how much wood would a wood chuck chuck if a wood"? Let's find out. Write a method ```most_recurring_word``` which takes in a string of words and returns the most repeated word. If there's a tie, return each word that ties for the most recurring word.
4 |
5 | ### Examples
6 |
7 | ```ruby
8 | sentence = "how much wood would a wood chuck chuck if a wood"
9 | most_recurring_word(sentence)
10 | => "wood"
11 |
12 | blue = "I'm blue da ba dee da ba daa"
13 | most_recurring_word(blue)
14 | => "da, ba"
15 |
16 | twinkle = "twinkle twinkle little star how I wonder what you are"
17 | most_recurring_word(twinkle)
18 | => "twinkle"
19 |
--------------------------------------------------------------------------------
/August_17/balanced_parenthesis.md:
--------------------------------------------------------------------------------
1 | ## Balanced Parenthesis
2 |
3 | Counting and matching opening and closing parentheses. Adding one extra ```)``` and breaking your code. We've all been through it. To help save future aspiring coders from this terrible agony, write a method, ```balanced_brackets```, which takes in a string
4 | and returns true if it is a valid combination of opening and closing parentheses.
5 |
6 | ### Examples
7 | ```ruby
8 | string = "(((hello)))"
9 | balanced_brackets(string)
10 | => true
11 |
12 | string = "(it's)((lit))((((fam))))"
13 | balanced_brackets(string)
14 | => true
15 |
16 | string = "(((((((lol))))"
17 | balanced_brackets(string)
18 | => false
19 |
20 | string = ")("
21 | balanced_brackets(string)
22 | => false
23 | ```
24 |
--------------------------------------------------------------------------------
/August_17/last_digit_of_large_number.md:
--------------------------------------------------------------------------------
1 | ## Last Digit of a VERY Large Number
2 |
3 | Write a function, ```last_digit```, which takes in two parameters, ```n1, n2```, and returns the last decimal digit of ```a^b```. Note that a and b may be very large!
4 |
5 | For example, the last decimal digit of ```9^7``` is ``` 9```, since ```9^7 = 4782969```. The last decimal digit of ```(2^200)^(2^300)```, which has over ```10^92``` decimal digits, is ```6```.
6 |
7 | The inputs to your function will always be non-negative integers.
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | last_digit(2,5)
13 | => 2 # 2^5 = 32
14 |
15 | last_digit(23,2)
16 | => 9 # 23^2 = 529
17 |
18 | last_digit(1234562304809,12039810293810298)
19 | => 1 # What happens if you raise n1^n2 here?
20 |
--------------------------------------------------------------------------------
/August_9/example_solutions/two_sum.rb:
--------------------------------------------------------------------------------
1 | def two_sum(array, target) #returns true or false
2 | map = {}
3 | i = 0
4 | while i < array.length
5 | difference = target - array[i]
6 | if map[difference]
7 | return true
8 | end
9 | map[array[i]] = 1
10 | i += 1
11 | end
12 | return false
13 | end
14 |
15 | def two_sum_positions(array, target) #returns the position of the two numbers
16 | map = {}
17 | found = false
18 | i = 0
19 | while i < array.length
20 | difference = target - array[i]
21 | if map[difference]
22 | position1 = array.find_index(difference)
23 | position2 = i
24 | return [position1, position2]
25 | end
26 | map[array[i]] = 1
27 | i += 1
28 | end
29 | return false
30 | end
31 |
--------------------------------------------------------------------------------
/August_30/contains_substrings.md:
--------------------------------------------------------------------------------
1 | ## Contains Substrings?
2 |
3 | Given two arrays of strings ```a1``` and ```a2```, write a method ```substring_checker``` which returns a sorted array in lexicographical (alphabetical) order of the strings of ```a1``` which are substrings of strings of ```a2```.
4 |
5 | ### Examples
6 | ```ruby
7 | #Example 1:
8 | a1 = ["arp", "live", "strong", "hello"]
9 | a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
10 | substring_checker(a1, a2)
11 | => ["arp","live","strong"]
12 |
13 | #Example 2:
14 | a1 = ["tarp", "mice", "bull"]
15 | a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
16 | substring_checker(a1,a2)
17 | => []
18 |
19 | #Example 3:
20 | a1 = ["its", "lit", "fam"]
21 | a2 = ["it", "is", "on", "fire", "family"]
22 | substring_checker(a1, a2)
23 | => ["fam"]
24 | ```
25 |
--------------------------------------------------------------------------------
/September_6/see_saw_array.md:
--------------------------------------------------------------------------------
1 | ## See-Saw Array
2 |
3 | Given a set of numbers, return true if there exists a number in the set in which the sum of all the numbers to the left of this number is equal to the sum of all the numbers to the right of it. If such a number does not exist, return false.
4 |
5 | Bonus:Rather than returning true, return the index of the balanced number
6 |
7 | ### Examples
8 |
9 | ```ruby
10 | see_saw = [1,2,3,5,6]
11 | => true
12 | => 3 # the index at which the see_saw is balanced
13 | # the sum of all numbers to the left of 5 (1+2+3)
14 | # is equal to the sum of all numbers to the right of 5
15 |
16 | see_saw = [1,10,2,5,6,9,4,1,4,8,14,6]
17 | => true
18 | => 6 # the index at which the see_saw is balanced
19 |
20 | see_saw = [3,5,1,5,2,3]
21 | => false
22 |
23 | ```
24 |
--------------------------------------------------------------------------------
/August_30/count_letters_in_string.md:
--------------------------------------------------------------------------------
1 | ## Count the Characters
2 |
3 | Write a method ```character_count``` which takes in a string and returns the number of times each letter occurs in the string as a hash.
4 |
5 | Bonus: Instead, return the character that occurs the most- if there is a tie, return the first occurring character
6 |
7 | ### Examples
8 | ```ruby
9 | character_count("helloworld")
10 | => {"h"=>1, "e"=>1, "l"=>3, "o"=>2, "w"=>1, "r"=>1, "d"=>1}
11 | => "h" #since h is the most recurring character
12 |
13 | character_count("devbootcamp")
14 | => {"d"=>1, "e"=>1, "v"=>1, "b"=>1, "o"=>2, "t"=>1, "c"=>1, "a"=>1, "m"=>1, "p"=>1}
15 | => "o" #since o is the most recurring character
16 |
17 | character_count("invisibility")
18 | => {"i"=>6, "n"=>1, "d"=>1, "v"=>1, "s"=>1, "b"=>1, "l"=>1, "t"=>1, "y"=>1}
19 | => "i" #since i is the most recurring character
20 |
--------------------------------------------------------------------------------
/July_26/optimzation-example.md:
--------------------------------------------------------------------------------
1 | ## Optimization Example (for runtime)
2 |
3 | - Consider these three algorithms, which all do the same thing: grab all the divisors for a given integer.
4 |
5 | - What is the run time for each? Can it be improved any further?
6 |
7 | ```ruby
8 | def divisors_v1(n)
9 | divisors = []
10 | i = 1
11 | until i > n
12 | if n % i == 0
13 | divisors << i
14 | end
15 | i += 1
16 | end
17 | return divisors
18 | end
19 |
20 | def divisors_v2(n)
21 | divisors = []
22 | i = 1
23 | until i > n / 2
24 | if n % i == 0
25 | divisors << i
26 | end
27 | i += 1
28 | end
29 | return divisors
30 | end
31 |
32 | def divisors_v3(n)
33 | divisors = []
34 | i = 1
35 | until i > Math.sqrt(n)
36 | if n % i == 0
37 | divisors << i
38 | divisors << n / i
39 | end
40 | i += 1
41 | end
42 | return divisors
43 | end
44 | ```
45 |
--------------------------------------------------------------------------------
/August_3/example_solutions/gaps_in_primes.rb:
--------------------------------------------------------------------------------
1 | def gap(g, m, n)
2 | # your code
3 | i = m #set counter equal to m
4 | while i <= (n - g) #stop when difference is greater than the gap
5 | if is_prime?(i) && is_prime?(i+g) && get_primes(i, i+g).length == 2
6 | return [i, i+g]
7 | end
8 | i += 1
9 | end
10 | return nil
11 | end
12 |
13 | def get_primes(m,n) #get all primes between m and n
14 | primes = []
15 | i = m
16 | while i <= n
17 | if is_prime?(i)
18 | primes << i
19 | end
20 | if i.odd?
21 | i += 2
22 | else
23 | i += 1
24 | end
25 | end
26 | return primes
27 | end
28 |
29 | def is_prime?(n)
30 | if n <= 1
31 | return false
32 | else
33 | i = 2
34 | until i > Math.sqrt(n)
35 | if n % i == 0
36 | return false
37 | end
38 | i += 1
39 | end
40 | end
41 | return true
42 | end
43 |
--------------------------------------------------------------------------------
/October_18/take_a_walk.md:
--------------------------------------------------------------------------------
1 | ## Taking a Walk
2 |
3 | You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones -- everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg. ```['n', 's', 'w', 'e']```).
4 |
5 | You know it takes you one minute to traverse one city block, so create a function that will return true if the walk the app gives you will take you exactly ten minutes (you don't want to be early or late!) and will, of course, return you to your starting point. Return false otherwise.
6 |
7 | ### Examples
8 |
9 | ```ruby
10 | take_a_walk(['n','s','n','s','n','s','n','s','n','s'])
11 | => true
12 |
13 | take_a_walk(['w'])
14 | => false
15 |
16 | take_a_walk(['w','e'])
17 | => true
18 | ```
19 |
--------------------------------------------------------------------------------
/August_3/example_solutions/prime_factorization.rb:
--------------------------------------------------------------------------------
1 | def primeFactors(n)
2 | if is_prime?(n)
3 | return "(#{n})"
4 | end
5 | prime_divisors_hash = {}
6 | while n != 1
7 | divisor = (2..n).find { |divisor| n % divisor == 0 }
8 | if !prime_divisors_hash.key?(divisor)
9 | prime_divisors_hash[divisor] = 1
10 | else
11 | prime_divisors_hash[divisor] += 1
12 | end
13 | n = n / divisor
14 | end
15 | return parse_hash(prime_divisors_hash)
16 | end
17 |
18 |
19 | def parse_hash(hash)
20 | string = ""
21 | hash.each do |k,v|
22 | if v == 1
23 | string += "(#{k})"
24 | else
25 | string += "(#{k}**#{v})"
26 | end
27 | end
28 | return string
29 | end
30 |
31 |
32 | def is_prime?(n)
33 | if n <= 1
34 | return false
35 | else
36 | i = 2
37 | until i > Math.sqrt(n)
38 | if n % i == 0
39 | return false
40 | end
41 | i += 1
42 | end
43 | end
44 | return true
45 | end
46 |
--------------------------------------------------------------------------------
/July_26/count_smileys.md:
--------------------------------------------------------------------------------
1 | ## Count the Smiley Faces
2 |
3 | Given an array as an argument, write a function ``` count_smileys``` that should return the total number of smiling faces.
4 |
5 | Rules for a smiling face:
6 | - Each smiley face must contain a valid pair of eyes. Eyes can be marked as ```:``` or ```;```
7 | - A smiley face can have a nose but it does not have to. Valid characters for a nose are ```-``` or ```~```
8 | - Every smiling face must have a smiling mouth that should be marked with either ```)``` or ```D```.
9 | - No additional characters are allowed except for those mentioned.
10 | - Valid smiley face examples:
11 | - ```:) :D ;-D :~)```
12 | - Invalid smiley faces:
13 | - ```;( :> :} :]```
14 |
15 | ### Examples
16 |
17 | ```ruby
18 | countSmileys([':)', ';(', ';}', ':-D']); // should return 2;
19 | countSmileys([';D', ':-(', ':-)', ';~)']); // should return 3;
20 | countSmileys([';]', ':[', ';*', ':$', ';-D']); // should return 1;
21 | ```
22 |
--------------------------------------------------------------------------------
/September_20/count_smileys.md:
--------------------------------------------------------------------------------
1 | ## Count the Smiley Faces
2 |
3 | Given an array as an argument, write a function ``` count_smileys``` that should return the total number of smiling faces.
4 |
5 | Rules for a smiling face:
6 | - Each smiley face must contain a valid pair of eyes. Eyes can be marked as ```:``` or ```;```
7 | - A smiley face can have a nose but it does not have to. Valid characters for a nose are ```-``` or ```~```
8 | - Every smiling face must have a smiling mouth that should be marked with either ```)``` or ```D```.
9 | - No additional characters are allowed except for those mentioned.
10 | - Valid smiley face examples:
11 | - ```:) :D ;-D :~)```
12 | - Invalid smiley faces:
13 | - ```;( :> :} :]```
14 |
15 | ### Examples
16 |
17 | ```ruby
18 | countSmileys([':)', ';(', ';}', ':-D']); // should return 2;
19 | countSmileys([';D', ':-(', ':-)', ';~)']); // should return 3;
20 | countSmileys([';]', ':[', ';*', ':$', ';-D']); // should return 1;
21 | ```
22 |
23 |
--------------------------------------------------------------------------------
/August_9/iq-test.md:
--------------------------------------------------------------------------------
1 | ## IQ Test
2 |
3 | Bob is preparing to pass an IQ test. The most frequent task in this test is to find out which one of the given numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is different in evenness, and return a position of this number.
4 |
5 | Write a function, ```iq_test```, that takes a given string of numbers, and returns which number is the odd (or even) one out.
6 |
7 | Keep in mind that your task is to help Bob solve a real IQ test, which means indexes of the elements start from 1, not 0.
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | iq_test("2 4 7 8 10")
13 | => 3 #the third number, 7, is odd, while the other four are even
14 | iq_test("1 2 1 1 3 7 9")
15 | => 2 #the second number, 2, is even, while the other numbers are odd
16 | iq_test("2 4 2 2 4 5 6 8")
17 | => 6 #the sixth number, 5, is odd, while the others are even
18 | ```
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Weihsuan Li
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/August_30/playing_with_digits.md:
--------------------------------------------------------------------------------
1 | ## Playing With Digits
2 |
3 | Some numbers have funny properties. For example:
4 |
5 | ```
6 | 89 --> 8¹ + 9² = 89 * 1
7 | 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2
8 | 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51
9 | ```
10 |
11 | Given a positive integer n written as ```abcd```... (a, b, c, d... being digits) and a positive integer ```p``` we want to find a positive integer k, if it exists, such as the sum of the digits of n taken to the successive powers of p is equal to k * n. In other words:
12 |
13 | Is there an integer k such that:
14 | ```
15 | (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k
16 | ```
17 |
18 | If it is the case we will return k, if not return -1.
19 |
20 | Note: n, p will always be given as strictly positive integers.
21 |
22 | ### Examples
23 |
24 | ```ruby
25 | dig_pow(89, 1) should return 1 since 8¹ + 9² = 89 = 89 * 1
26 | dig_pow(92, 1) should return -1 since there is no k such as 9¹ + 2² equals 92 * k
27 | dig_pow(695, 2) should return 2 since 6² + 9³ + 5⁴= 1390 = 695 * 2
28 | dig_pow(46288, 3) should return 51 since 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51
29 | ```
30 |
--------------------------------------------------------------------------------
/September_27/make_anagrams.md:
--------------------------------------------------------------------------------
1 | ## Make Anagrams
2 |
3 | Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example, ```bacdc``` and ```dcbac``` are anagrams, but ```bacdc``` and ```dcbad``` are not.
4 |
5 | Alice decides on an encryption scheme involving two large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. Can you help her find this number?
6 |
7 | Given two strings, ```a``` and ```b``` , that may or may not be of the same length, determine the minimum number of character deletions required to make ```a``` and ```b``` anagrams. Any characters can be deleted from either of the strings.
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | a = "xyz"
13 | b = "tux"
14 |
15 | make_anagrams(a,b)
16 | => 4 # remove "y" and "z" from a, and remove "t" and "u" from b
17 |
18 | make_anagrams("devbootcamp", "dbc")
19 | => 8
20 |
21 | make_anagrams("abc", "abc")
22 | => 0
23 | ```
24 |
--------------------------------------------------------------------------------
/Workshop/make_anagrams.md:
--------------------------------------------------------------------------------
1 | ## Make Anagrams
2 |
3 | Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example, ```bacdc``` and ```dcbac``` are anagrams, but ```bacdc``` and ```dcbad``` are not.
4 |
5 | Alice decides on an encryption scheme involving two large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. Can you help her find this number?
6 |
7 | Given two strings, ```a``` and ```b``` , that may or may not be of the same length, determine the minimum number of character deletions required to make ```a``` and ```b``` anagrams. Any characters can be deleted from either of the strings.
8 |
9 | ### Examples
10 |
11 | ```ruby
12 | a = "xyz"
13 | b = "tux"
14 |
15 | make_anagrams(a,b)
16 | => 4 # remove "y" and "z" from a, and remove "t" and "u" from b
17 |
18 | make_anagrams("devbootcamp", "dbc")
19 | => 8
20 |
21 | make_anagrams("abc", "abc")
22 | => 0
23 | ```
24 |
--------------------------------------------------------------------------------
/August_3/tribonnaci_sequence.md:
--------------------------------------------------------------------------------
1 | ## Tribonnaci Sequence
2 |
3 | Well met with Fibonacci bigger brother, AKA Tribonacci.
4 |
5 | As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next.
6 |
7 | So, if we are to start our Tribonacci sequence with [1,1,1] as a starting input (AKA signature), we have this sequence:
8 |
9 | ```ruby
10 | {1,1,1,3,5,9,17,31,...}
11 | ```
12 |
13 | But what if we started with [0,0,1] as a signature? We would get this sequence:
14 |
15 | ```ruby
16 | {0,0,1,1,2,4,7,13,24,...}
17 | ```
18 |
19 | You need to create a tribonacci function that given a signature array/list, returns the first n elements - signature included of the so seeded sequence.
20 |
21 | Signature will always contain 3 numbers; n will always be a non-negative number; if n==0, then return an empty array and be ready for anything else which is not clearly specified
22 |
23 | ### Examples
24 |
25 | ```ruby
26 | tribonacci([1,1,1],10)
27 | => [1,1,1,3,5,9,17,31,57,105]
28 |
29 | tribonacci([1,2,3],10)
30 | => [1,2,3,6,11,20,37,68,125,230]
31 |
32 | tribonacci([3,2,1],10)
33 | => [3,2,1,6,9,16,31,56,103,190]
34 |
35 | tribonacci([1,2,3],0)
36 | => []
37 | ```
38 |
--------------------------------------------------------------------------------
/August_30/palindrome_chain_length.md:
--------------------------------------------------------------------------------
1 | ## Palindrome Chain Length
2 |
3 | A number is a palindrome if it is equal to the number with digits in reversed order. For example, ```5, 44, 171, 4884``` are palindromes and ```43, 194, 4773``` are not palindromes.
4 |
5 | Write a method, ```palindrome_chain_length```, which takes a positive number and returns the number of special steps needed to obtain a palindrome. The special step is: "reverse the digits, and add to the original number." If the resulting number is not a palindrome, repeat the procedure with the sum until the resulting number is a palindrome.
6 |
7 | If the input number is already a palindrome, the number of steps is 0.
8 |
9 | Input will always be a positive integer.
10 |
11 | Bonus: Figure out how to check if a number is a palindrome WITHOUT converting it into a string
12 |
13 | ### Examples
14 |
15 | For example, start with 87:
16 |
17 | 87 + 78 = 165; 165 + 561 = 726; 726 + 627 = 1353; 1353 + 3531 = 4884
18 |
19 | 4884 is a palindrome and we needed 4 steps to obtain it, so palindrome_chain_length(87) == 4
20 |
21 | ```ruby
22 | palindrome_chain_length(87)
23 | => 4
24 |
25 | palindrome_chain_length(1337)
26 | => 1
27 |
28 | palindrome_permutation(2048)
29 | => 2
30 | ```
31 |
--------------------------------------------------------------------------------
/August_3/gaps_in_primes.md:
--------------------------------------------------------------------------------
1 | ## Gaps in Primes
2 |
3 | The prime numbers are not regularly spaced. For example from 2 to 3 the gap is 1. From 3 to 5 the gap is 2. From 7 to 11 it is 4. Between 2 and 50 we have the following pairs of 2-gaps primes: 3-5, 5-7, 11-13, 17-19, 29-31, 41-43.
4 |
5 | We will write a function gap with parameters:
6 |
7 | - ```g``` (integer >= 2) which indicates the gap we are looking for
8 |
9 | - ```m``` (integer > 2) which gives the start of the search (m inclusive)
10 |
11 | - ```n``` (integer >= m) which gives the end of the search (n inclusive)
12 |
13 | In the example above ```gap(2, 3, 50)``` will return ```[3, 5] or (3, 5) or {3, 5}``` which is the first pair between 3 and 50 with a 2-gap.
14 |
15 | So this function should return the first pair of two prime numbers spaced with a gap of g between the limits m, n if these numbers exist otherwise nil or null or None or Nothing (depending on the language). In C++ return in such a case {0, 0}.
16 |
17 | ### Examples:
18 | - ```gap(2, 5, 7) --> [5, 7] or (5, 7) or {5, 7}```
19 |
20 | - ```gap(2, 5, 5) --> nil```
21 |
22 | - ```gap(4, 130, 200) --> [163, 167] or (163, 167) or {163, 167}```
23 |
24 | - ([193, 197] is also such a 4-gap primes between 130 and 200 but it's not the first pair)
25 |
26 | - ```gap(6,100,110) --> nil or {0, 0}``` :
27 | - between 100 and 110 we have 101, 103, 107, 109
28 | - 101-107 is not a 6-gap because there is 103 in between
29 | - 103-109 is not a 6-gap because there is 107 in between.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Whiteboarding Wednesday
2 | Centralized source for whiteboarding problems covered each Wednesday.
3 |
4 | ## What is it?
5 |
6 | A weekly workshop created to help DBC students and alumi practice their technical interview skills.
7 |
8 | ## Weekly Problems
9 |
10 | * ### 2017
11 | - [Week 1 (7/19)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/July_19)
12 |
13 | - [Week 2 (7/26)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/July_26)
14 |
15 | - [Week 3 (8/3)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/August_3)
16 |
17 | - [Week 4 (8/9)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/August_9)
18 |
19 | - [Week 5 (8/17)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/August_17)
20 |
21 | - [Week 6 (8/30)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/August_30)
22 |
23 | - [Week 7 (9/6)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/September_6)
24 |
25 | - [Week 8 (9/20)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/September_20)
26 |
27 | - [Week 9 (9/27)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/September_27)
28 |
29 | - [Week 10 (10/18)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/October_18)
30 |
31 | * ### 2018
32 | - [Week 1 (1/19)](https://github.com/MrRogerino/dbc-whiteboarding/tree/master/January_19)
33 |
34 |
35 | ## Resources
36 |
37 | **External**
38 | - [Khan Academy's Algorithms Course](https://www.khanacademy.org/computing/computer-science/algorithms)
39 | - [Interview Cake](https://www.interviewcake.com/)
40 | - [Brian Stroti's Ruby Graph Algorithms](https://github.com/brianstorti/ruby-graph-algorithms)
41 | - [Coursera: Algorithms, Part I from Princeton](https://www.coursera.org/course/algs4partI)
42 | - [Coursera: Algorithms: Design and Analysis, Part 1 from Stanford](https://www.coursera.org/course/algo)
43 | - [Andy's answer to: Why have tech interview become hard?](http://qr.ae/RoLQfu)
44 |
45 | ## Contact Info
46 |
47 | Roger Li: @weihsuan.li24@gmail.com
48 |
49 | ## Feedback
50 |
51 | [Form](https://goo.gl/forms/sQSFnZT3H0l5tPvL2)
52 |
53 | All feedback is welcome and appreciated!
54 |
55 |
--------------------------------------------------------------------------------
/January_19/linked_list.md:
--------------------------------------------------------------------------------
1 | ## Introduction to Linked Lists
2 |
3 | Today we'll code out one of the most fundamental data structures of computer science: a linked list. Linked lists are used similarly to arrays to store data. Essentially, a linked list is a series of connected "nodes"- each node contains some data, as well as a pointer to the "next" node (or nothing, if it's at the end of a list). Storing data in this fashion has its advantages and disadvantages compared to an array. For example, insertion and deletion of elements is much more efficient in a linked list compared to an array. What are some other pros and cons of storing data in a linked list?
4 |
5 | ### Class Setup
6 |
7 | Let's start by defining our two classes: ```Node``` and ```LinkedList```.
8 | A ```Node``` has two basic attributes- a ```value```, which stores some data, and a ```next_node```, which will either point to another node (hence the "link" part of the list), or ```nil```, if it's at the end of the linked list.
9 | A ```LinkedList``` only has one basic attribute: a ```head``` which is equal to the value of some ```Node``` object. Set up each class with these attributes.
10 |
11 | ### Basic Methods
12 |
13 | Now that we have our skeleton set up, let's define some basic methods for our ```LinkedList``` class. Our ```Node``` class should remain untouched while we write methods for our ```LinkedList```.
14 |
15 | - Let's start with a ```#last``` method, which returns the value of the last node in a linked list. Think about how iterating through a linked list is different from an array. How do we know what the current value is? How do we know when we're at the end of the list?
16 |
17 | - Next, let's define a ```#include?``` method, which takes in some value as an parameter and returns true if the value exists within the list. How is this similar or different compared to ```Array#include?```?
18 |
19 | ### More Methods
20 |
21 | We've just defined some methods that demonstrate how to iterate through a ```LinkedList```. Now, let's define some methods which will alter a given ```LinkedList```.
22 |
23 | - The first method we will define is ```#push```; similar to ```Array#push```, this method will take in a parameter, and append that value to the end of the list. What does appending mean in the context of a ```LinkedList```? How is it different from ```Array#push```?
24 |
25 | - Let's go ahead and define a similar method: ```#pop```, which will remove the last item from a ```LinkedList``` and return it. What parts of previous methods can we use to help define this method? Once we ```pop``` a node from the end of a list, do we need to do anything else?
26 |
27 | - Our final method will be ```insert```, which will take in two parameters: the value to be inserted, and the index at which the value should be inserted at. How do we keep track of an index in a ```LinkedList```?
28 |
--------------------------------------------------------------------------------
/November_1/linked_list.md:
--------------------------------------------------------------------------------
1 | ## Introduction to Linked Lists
2 |
3 | Today we'll code out one of the most fundamental data structures of computer science: a linked list. Linked lists are used similarly to arrays to store data. Essentially, a linked list is a series of connected "nodes"- each node contains some data, as well as a pointer to the "next" node (or nothing, if it's at the end of a list). Storing data in this fashion has its advantages and disadvantages compared to an array. For example, insertion and deletion of elements is much more efficient in a linked list compared to an array. What are some other pros and cons of storing data in a linked list?
4 |
5 | ### Class Setup
6 |
7 | Let's start by defining our two classes: ```Node``` and ```LinkedList```.
8 | A ```Node``` has two basic attributes- a ```value```, which stores some data, and a ```next_node```, which will either point to another node (hence the "link" part of the list), or ```nil```, if it's at the end of the linked list.
9 | A ```LinkedList``` only has one basic attribute: a ```head``` which is equal to the value of some ```Node``` object. Set up each class with these attributes.
10 |
11 | ### Basic Methods
12 |
13 | Now that we have our skeleton set up, let's define some basic methods for our ```LinkedList``` class. Our ```Node``` class should remain untouched while we write methods for our ```LinkedList```.
14 |
15 | - Let's start with a ```#last``` method, which returns the last node in a linked list. Think about how iterating through a linked list is different from an array. How do we know when we're at the end of the list?
16 |
17 | - Next, let's define a ```#include?``` method, which takes in some value as an parameter and returns true if the value exists within the list. How is this similar or different compared to ```Array#include?```?
18 |
19 | - Finally, let's make a `#print` method that will print out our list in order- this will ensure that as we define methods that alter our list, we have a way to check whether each method is doing what we intended. For clarity's sake, make sure our output looks something like this: ```1 -> 3 -> 5 -> 10```, where each number represents a value of a node, and each arrow points to the next node in the list.
20 |
21 | ### More Methods
22 |
23 | We've just defined some methods that demonstrate how to iterate through a ```LinkedList```. Now, let's define some methods which will alter a given ```LinkedList```.
24 |
25 | - The first method we will define is ```#push```; similar to ```Array#push```, this method will take in a parameter, and append that value to the end of the list. What does appending mean in the context of a ```LinkedList```? How is it different from ```Array#push```?
26 |
27 | - Let's go ahead and define a similar method: ```#pop```, which will remove the last item from a ```LinkedList``` and return it. What parts of previous methods can we use to help define this method? Once we ```pop``` a node from the end of a list, do we need to do anything else?
28 |
29 | - Our final method will be ```insert```, which will take in two parameters: the value to be inserted, and the index at which the value should be inserted at. How do we keep track of an index in a ```LinkedList```
30 |
31 |
32 | ### Challenge Mode
33 |
34 | - Let's take another ```Array``` method and define it within the context of a ```LinkedList```. What about ```#delete```? What does the ```delete``` method do when called upon an ```Array```, and how does that translate to a ```LinkedList```. As you define these methods, notice the similarities and differences between the two classes.
35 |
--------------------------------------------------------------------------------
/January_19/example_solutions/linked_list.rb:
--------------------------------------------------------------------------------
1 | require_relative 'node'
2 |
3 | class LinkedList
4 | def initialize(head)
5 | @head = head
6 | end
7 |
8 | def last
9 | current_node = @head
10 | while current_node.next_node != nil
11 | current_node = current_node.next_node
12 | end
13 |
14 | current_node
15 | end
16 |
17 | def include?(search)
18 | current_node = @head
19 | while current_node.next_node != nil
20 | return true if current_node.value == search
21 | current_node = current_node.next_node
22 | end
23 |
24 | false
25 | end
26 |
27 | def print
28 | if @head == nil
29 | puts "LinkedList is empty"
30 | return
31 | end
32 |
33 | current_node = @head
34 | output = "#{@head.value}"
35 | while current_node.next_node != nil
36 | current_node = current_node.next_node
37 | output += " -> #{current_node.value}"
38 | end
39 |
40 | puts output
41 | end
42 |
43 | def push(value)
44 | last_node = self.last
45 | last_node.next_node = Node.new(value)
46 | end
47 |
48 | def pop
49 | current_node = @head
50 |
51 | if current_node.next_node == nil
52 | @head = nil
53 | return current_node
54 | end
55 |
56 | second_node = @head.next_node
57 | while second_node.next_node != nil
58 | current_node = second_node
59 | second_node = second_node.next_node
60 | end
61 |
62 | current_node.next_node = nil
63 | return second_node
64 | end
65 |
66 | def insert(value, insert_index)
67 | current_node = @head
68 | current_index = 1
69 |
70 | if insert_index == 0 # inserting at the very beginning of the list
71 | @head = Node.new(value, current_node)
72 | return
73 | end
74 |
75 | while current_node.next_node != nil
76 | p "current index: #{current_index}"
77 | if insert_index == current_index
78 | next_node = current_node.next_node
79 | current_node.next_node = Node.new(value, next_node)
80 | return
81 | end
82 | current_node = current_node.next_node
83 | current_index += 1
84 | end
85 |
86 | puts "Insert index does not exist"
87 | end
88 |
89 | def delete(search)
90 | # before iterating through the list, we have to check the head value
91 | # and keep moving the head until the value it matches the non-seach value
92 | while @head.value == search || @head.next_node == nil # checks to see if head node value is equal to search value or if at the end of the list
93 | if @head.next_node == nil && @head.value == search # if at the end of the list, and the head still matches the search value
94 | @head = nil
95 | return # return an empty list
96 | elsif @head.next_node == nil && @head.value != search # if at the end of the list, but the last value does NOT match the search
97 | return
98 | else
99 | @head = @head.next_node # move the head one forward
100 | end
101 | end
102 |
103 | # iterate through the list
104 | previous_node = @head
105 | current_node = @head.next_node
106 | while current_node.next_node != nil
107 | if current_node.value == search
108 | previous_node.next_node = current_node.next_node
109 | end
110 | previous_node = current_node
111 | current_node = current_node.next_node
112 | end
113 |
114 | if current_node.value == search
115 | previous_node.next_node = nil
116 | end
117 |
118 | end
119 | end
120 |
--------------------------------------------------------------------------------