From 2fe1098805de6fb91f5b567484f01d3f90ae720a Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Wed, 31 Mar 2021 16:40:23 -0700 Subject: [PATCH 001/121] Add intersection challenge --- DIRECTORY.md | 1 + data_structures/arrays/intersection.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 data_structures/arrays/intersection.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index 03f2942..878bdcb 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -12,6 +12,7 @@ * [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb) * [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb) * [Get Products Of All Other Elements](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/get_products_of_all_other_elements.rb) + * [Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/intersection.rb) * [Remove Elements](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/remove_elements.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/richest_customer_wealth.rb) * [Shuffle Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/shuffle_array.rb) diff --git a/data_structures/arrays/intersection.rb b/data_structures/arrays/intersection.rb new file mode 100644 index 0000000..bd826a0 --- /dev/null +++ b/data_structures/arrays/intersection.rb @@ -0,0 +1,23 @@ +# Challenge name: Intersection of two arrays ii +# +# Given two arrays, write a function to compute their intersection. +# +# @param {Integer[]} nums1 +# @param {Integer[]} nums2 +# @return {Integer[]} + +# +# Approach 1: +# +# Time Complexity: +# +def intersect(arr1, arr2) +end +nums1 = [1, 2, 2, 1] +nums2 = [2, 2] +intersect(nums1, nums2) +# => [2,2] +nums1 = [4, 9, 5] +nums2 = [9, 4, 9, 8, 4] +intersect(nums1, nums2) +# => [4,9] \ No newline at end of file From 4674c2d97b205f14a2b471d00c24afca4e44048f Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 31 Mar 2021 19:02:57 -0700 Subject: [PATCH 002/121] Valid anagram: hash table approach --- .../arrays/strings/anagram_checker.rb | 2 +- data_structures/hash_table/anagram_checker.rb | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 data_structures/hash_table/anagram_checker.rb diff --git a/data_structures/arrays/strings/anagram_checker.rb b/data_structures/arrays/strings/anagram_checker.rb index bcd5e36..1918b07 100644 --- a/data_structures/arrays/strings/anagram_checker.rb +++ b/data_structures/arrays/strings/anagram_checker.rb @@ -15,7 +15,7 @@ # @return {Boolean} # -# Approach 1: Sort and Compare +# Approach: Sort and Compare # # Complexity analysis: # diff --git a/data_structures/hash_table/anagram_checker.rb b/data_structures/hash_table/anagram_checker.rb new file mode 100644 index 0000000..43163d4 --- /dev/null +++ b/data_structures/hash_table/anagram_checker.rb @@ -0,0 +1,55 @@ +# Challenge name: Is anagram +# +# Given two strings s and t , write a function to determine +# if t is an anagram of s. +# +# Note: +# You may assume the string contains only lowercase alphabets. +# +# Follow up: +# What if the inputs contain unicode characters? +# How would you adapt your solution to such case? +# +# @param {String} s +# @param {String} t +# @return {Boolean} + +# +# Approach: Hash table +# +# Complexity analysis: +# +# Time complexity: O(n). Time complexity is O(n) since accessing the counter table is a constant time operation. +# Space complexity: O(1). Although we do use extra space, the space complexity is O(1) because the table's size stays constant no matter how large n is. +# +def is_anagram(s, t) + s_length = s.length + t_length = t.length + counter = Hash.new(0) + + return false unless s_length == t_length + + (0...s_length).each do |i| + counter[s[i]] += 1 + counter[t[i]] -= 1 + end + + counter.each do |k, v| + return false unless v == 0 + end + + true +end + +s = 'anagram' +t = 'nagaram' +puts(is_anagram(s, t)) +# => true +s = 'rat' +t = 'car' +puts(is_anagram(s, t)) +# => false +s = 'a' +t = 'ab' +puts(is_anagram(s, t)) +# => false From 2da2ec55f6e32b1c418e44c6b2a4576ecfbfb54f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 1 Apr 2021 02:03:14 +0000 Subject: [PATCH 003/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index d0c4469..42b9add 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -32,6 +32,7 @@ * [Postorder Traversal](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/binary_trees/postorder_traversal.rb) * [Preorder Traversal](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/binary_trees/preorder_traversal.rb) * Hash Table + * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/anagram_checker.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/find_all_duplicates_in_an_array.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/richest_customer_wealth.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/two_sum.rb) From ad959fcfb037a205a42bfed1b496624e2faa05ad Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 31 Mar 2021 19:04:39 -0700 Subject: [PATCH 004/121] Minor changes --- data_structures/hash_table/anagram_checker.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/data_structures/hash_table/anagram_checker.rb b/data_structures/hash_table/anagram_checker.rb index 43163d4..03f72fa 100644 --- a/data_structures/hash_table/anagram_checker.rb +++ b/data_structures/hash_table/anagram_checker.rb @@ -19,8 +19,11 @@ # # Complexity analysis: # -# Time complexity: O(n). Time complexity is O(n) since accessing the counter table is a constant time operation. -# Space complexity: O(1). Although we do use extra space, the space complexity is O(1) because the table's size stays constant no matter how large n is. +# Time complexity: O(n). Time complexity is O(n) since accessing the counter +# table is a constant time operation. +# Space complexity: O(1). Although we do use extra space, +# the space complexity is O(1) because the table's size stays constant no +# matter how large n is. # def is_anagram(s, t) s_length = s.length @@ -45,10 +48,12 @@ s = 'anagram' t = 'nagaram' puts(is_anagram(s, t)) # => true + s = 'rat' t = 'car' puts(is_anagram(s, t)) # => false + s = 'a' t = 'ab' puts(is_anagram(s, t)) From 6b8529a1a698e7316cb809fd01c557f6b7726142 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 31 Mar 2021 19:05:51 -0700 Subject: [PATCH 005/121] Update anagram_checker.rb --- data_structures/hash_table/anagram_checker.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data_structures/hash_table/anagram_checker.rb b/data_structures/hash_table/anagram_checker.rb index 03f72fa..1158134 100644 --- a/data_structures/hash_table/anagram_checker.rb +++ b/data_structures/hash_table/anagram_checker.rb @@ -17,6 +17,8 @@ # # Approach: Hash table # + +# # Complexity analysis: # # Time complexity: O(n). Time complexity is O(n) since accessing the counter From dc533283a2a3c5743fae1548210f8968fb7a8d08 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 09:36:46 -0700 Subject: [PATCH 006/121] Add hash table approach --- data_structures/hash_table/anagram_checker.rb | 73 ++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/data_structures/hash_table/anagram_checker.rb b/data_structures/hash_table/anagram_checker.rb index 1158134..0d0f2f6 100644 --- a/data_structures/hash_table/anagram_checker.rb +++ b/data_structures/hash_table/anagram_checker.rb @@ -17,8 +17,6 @@ # # Approach: Hash table # - -# # Complexity analysis: # # Time complexity: O(n). Time complexity is O(n) since accessing the counter @@ -60,3 +58,74 @@ s = 'a' t = 'ab' puts(is_anagram(s, t)) # => false + + +def is_anagram(s, t) + s_length = s.length + t_length = t.length + counter = Hash.new(0) + + return false unless s_length == t_length + + (0...s_length).each do |i| + counter[s[i]] += 1 + end + + (0...s_length).each do |i| + counter[t[i]] -= 1 + + return false if counter[t[i]] < 0 + end + + true +end + +s = 'anagram' +t = 'nagaram' +puts(is_anagram(s, t)) +# => true + +s = 'rat' +t = 'car' +puts(is_anagram(s, t)) +# => false + +s = 'a' +t = 'ab' +puts(is_anagram(s, t)) +# => false + +# +# Approach 2: Hash table +# + +# Algorithm: we could also first increment the counter for s, +# then decrement the counter for t. If at any point the counter +# drops below zero, we know that t contains an extra letter, +# not in s, and return false immediately. + +# Complexity analysis: +# +# Time complexity: O(n). +# Space complexity: O(1). +# + +def is_anagram(s, t) + s_length = s.length + t_length = t.length + counter = Hash.new(0) + + return false unless s_length == t_length + + (0...s_length).each do |i| + counter[s[i]] += 1 + end + + (0...s_length).each do |i| + counter[t[i]] -= 1 + + return false if counter[t[i]] < 0 + end + + true +end From 44c32084541b2679161577a1257d1454d4f4752d Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 09:36:52 -0700 Subject: [PATCH 007/121] Add another hash table approach --- data_structures/hash_table/anagram_checker.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/data_structures/hash_table/anagram_checker.rb b/data_structures/hash_table/anagram_checker.rb index 0d0f2f6..16fc429 100644 --- a/data_structures/hash_table/anagram_checker.rb +++ b/data_structures/hash_table/anagram_checker.rb @@ -129,3 +129,38 @@ def is_anagram(s, t) true end + +# +# Approach 3: populate 2 hashes and compare them +# + +def is_anagram(s, t) + s = s.chars + t = t.chars + + return false if s.count != t.count + + hash1 = {} + s.chars.each do |value| + hash1[value] = if hash1[value] + hash1[value] + 1 + else + 1 + end + end + + hash2 = {} + t.chars.each do |value| + hash2[value] = if hash2[value] + hash2[value] + 1 + else + 1 + end + end + + hash1.keys.each do |key| + return false if hash2[key] != hash1[key] + end + + true +end From 434e72a4f7cc0cd977e98c941449e492929e1d2f Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 09:38:27 -0700 Subject: [PATCH 008/121] Add very simple tests --- data_structures/hash_table/anagram_checker.rb | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/data_structures/hash_table/anagram_checker.rb b/data_structures/hash_table/anagram_checker.rb index 16fc429..abbb209 100644 --- a/data_structures/hash_table/anagram_checker.rb +++ b/data_structures/hash_table/anagram_checker.rb @@ -130,6 +130,21 @@ def is_anagram(s, t) true end +s = 'anagram' +t = 'nagaram' +puts(is_anagram(s, t)) +# => true + +s = 'rat' +t = 'car' +puts(is_anagram(s, t)) +# => false + +s = 'a' +t = 'ab' +puts(is_anagram(s, t)) +# => false + # # Approach 3: populate 2 hashes and compare them # @@ -141,7 +156,7 @@ def is_anagram(s, t) return false if s.count != t.count hash1 = {} - s.chars.each do |value| + s.each do |value| hash1[value] = if hash1[value] hash1[value] + 1 else @@ -150,7 +165,7 @@ def is_anagram(s, t) end hash2 = {} - t.chars.each do |value| + t.each do |value| hash2[value] = if hash2[value] hash2[value] + 1 else @@ -164,3 +179,18 @@ def is_anagram(s, t) true end + +s = 'anagram' +t = 'nagaram' +puts(is_anagram(s, t)) +# => true + +s = 'rat' +t = 'car' +puts(is_anagram(s, t)) +# => false + +s = 'a' +t = 'ab' +puts(is_anagram(s, t)) +# => false From 515b076e61872aaeac08d09ad6c77007ce1d75d5 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 09:42:45 -0700 Subject: [PATCH 009/121] remove duplication --- data_structures/hash_table/anagram_checker.rb | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/data_structures/hash_table/anagram_checker.rb b/data_structures/hash_table/anagram_checker.rb index abbb209..e15eed4 100644 --- a/data_structures/hash_table/anagram_checker.rb +++ b/data_structures/hash_table/anagram_checker.rb @@ -17,6 +17,7 @@ # # Approach: Hash table # + # Complexity analysis: # # Time complexity: O(n). Time complexity is O(n) since accessing the counter @@ -59,42 +60,6 @@ t = 'ab' puts(is_anagram(s, t)) # => false - -def is_anagram(s, t) - s_length = s.length - t_length = t.length - counter = Hash.new(0) - - return false unless s_length == t_length - - (0...s_length).each do |i| - counter[s[i]] += 1 - end - - (0...s_length).each do |i| - counter[t[i]] -= 1 - - return false if counter[t[i]] < 0 - end - - true -end - -s = 'anagram' -t = 'nagaram' -puts(is_anagram(s, t)) -# => true - -s = 'rat' -t = 'car' -puts(is_anagram(s, t)) -# => false - -s = 'a' -t = 'ab' -puts(is_anagram(s, t)) -# => false - # # Approach 2: Hash table # From c2bd60c2231b3ccbc385a4dd46d3e7ead10aab9b Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Thu, 1 Apr 2021 09:31:12 -0700 Subject: [PATCH 010/121] Add palindrome challenge --- DIRECTORY.md | 1 + data_structures/arrays/strings/palindrome.rb | 44 ++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 data_structures/arrays/strings/palindrome.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index d0c4469..bca02fb 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -23,6 +23,7 @@ * Strings * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb) * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) + * [Palindrome](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/palindrome.rb) * [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb) * [Two Sum Ii](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum_ii.rb) diff --git a/data_structures/arrays/strings/palindrome.rb b/data_structures/arrays/strings/palindrome.rb new file mode 100644 index 0000000..1ebcfbe --- /dev/null +++ b/data_structures/arrays/strings/palindrome.rb @@ -0,0 +1,44 @@ +# Challenge name: Valid Palindrome +# +# Given a string s, determine if it is a palindrome, +# considering only alphanumeric characters and ignoring cases. +# +# Example 1: +# Input: s = "A man, a plan, a canal: Panama" +# Output: true +# Explanation: "amanaplanacanalpanama" is a palindrome. +# +# Example 2: +# Input: s = "race a car" +# Output: false +# Explanation: "raceacar" is not a palindrome. +# +# Constraints: +# 1 <= s.length <= 2 * 105 +# s consists only of printable ASCII characters. +# @param {String} s +# @return {Boolean} + +# +# Approach 1: Brute Force +# +# Time Complexity: +# +def is_palindrome(s) + s.downcase +end + +s = 'A man, a plan, a canal: Panama' +puts is_palindrome(s) +# Output: true +# Explanation: "amanaplanacanalpanama" is a palindrome. + +s = 'race a car' +puts is_palindrome(s) +# Output: false +# Explanation: "raceacar" is not a palindrome. + +s = 'ab_a' +puts is_palindrome(s) +# Output: true +# Explanation: "aba" is a palindrome. \ No newline at end of file From 13aec345eaca265cc5ea218754faefc62fe557a6 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 09:54:34 -0700 Subject: [PATCH 011/121] add generate_parenthesis backtracking approach --- backtracking/generate_paranthesis.rb | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 backtracking/generate_paranthesis.rb diff --git a/backtracking/generate_paranthesis.rb b/backtracking/generate_paranthesis.rb new file mode 100644 index 0000000..5881aea --- /dev/null +++ b/backtracking/generate_paranthesis.rb @@ -0,0 +1,47 @@ +# Given n pairs of parentheses, write a function to generate all combinations +# of well-formed parentheses. +# +# Example 1: +# +# Input: n = 3 +# Output: ["((()))","(()())","(())()","()(())","()()()"] +# Example 2: +# +# Input: n = 1 +# Output: ["()"] +# +# +# Constraints: +# +# 1 <= n <= 8 + +# @param {Integer} n +# @return {String[]} +def generate_parenthesis(n) + parenthesis = [] + backtrack(parenthesis, "", 0, 0, n) + parenthesis +end + +def backtrack(parenthesis, curr, open, close, max) + if curr.length == max * 2 + parenthesis.push(curr) + return + end + + if open < max + backtrack(parenthesis, curr + "(", open + 1, close, max) + end + + if close < open + backtrack(parenthesis, curr + ")", open, close + 1, max) + end +end + +n = 3 +print(generate_parenthesis(n)) +# Output: ["((()))","(()())","(())()","()(())","()()()"] + +n = 1 +print(generate_parenthesis(n)) +# Output: ["()"] From 1350b46474aa437169639166e041ebdfdaa469af Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 1 Apr 2021 16:54:50 +0000 Subject: [PATCH 012/121] updating DIRECTORY.md --- DIRECTORY.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 42b9add..7c86a15 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1,4 +1,7 @@ +## Backtracking + * [Generate Paranthesis](https://github.com/TheAlgorithms/Ruby/blob/master/backtracking/generate_paranthesis.rb) + ## Bit Manipulation * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/power_of_two.rb) From 1d974b2ea18e646fe277ada716902d42ed95c659 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 09:58:04 -0700 Subject: [PATCH 013/121] Add approach description --- backtracking/generate_paranthesis.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backtracking/generate_paranthesis.rb b/backtracking/generate_paranthesis.rb index 5881aea..587a25c 100644 --- a/backtracking/generate_paranthesis.rb +++ b/backtracking/generate_paranthesis.rb @@ -15,6 +15,16 @@ # # 1 <= n <= 8 +# Approach: +# +# Let's only add '(' or ')' when we know it will remain a valid sequence. +# We can do this by keeping track of the number of opening and closing brackets +# we have placed so far. +# +# We can start an opening bracket if we still have one (of n) left to place. +# And we could start a closing bracket if it'd not exceed the number of opening +# brackets. + # @param {Integer} n # @return {String[]} def generate_parenthesis(n) From 7eea20ed6e0369db5d5ff8d2f99aa431ac78a224 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 10:06:40 -0700 Subject: [PATCH 014/121] Add complexity analysis and detailed example --- backtracking/generate_paranthesis.rb | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/backtracking/generate_paranthesis.rb b/backtracking/generate_paranthesis.rb index 587a25c..0ea684e 100644 --- a/backtracking/generate_paranthesis.rb +++ b/backtracking/generate_paranthesis.rb @@ -25,6 +25,14 @@ # And we could start a closing bracket if it'd not exceed the number of opening # brackets. +# Complexity Analysis +# +# Time Complexity: O(4^n/sqrt(n). Each valid sequence has at most n steps during the backtracking procedure. +# Space Complexity: O(4^n/sqrt(n), as described above, and using O(n) space to store the sequence. + +# Refer to the attached diagram for recursion, +# The numbers next to each node are the counts of left and right parantheses + # @param {Integer} n # @return {String[]} def generate_parenthesis(n) @@ -52,6 +60,47 @@ n = 3 print(generate_parenthesis(n)) # Output: ["((()))","(()())","(())()","()(())","()()()"] +# *** Example: n = 3 *** Space after each DFS instance +# backtrack called with 0 0 [] +# backtrack called with ( 1 0 [] +# backtrack called with (( 2 0 [] +# backtrack called with ((( 3 0 [] +# backtrack called with ((() 3 1 [] +# backtrack called with ((()) 3 2 [] +# backtrack called with ((())) 3 3 [] +# backtrack return with ((()) 3 2 ["((()))"] +# backtrack return with ((() 3 1 ["((()))"] +# backtrack return with ((( 3 0 ["((()))"] +# backtrack called with (() 2 1 ["((()))"] +# backtrack called with (()( 3 1 ["((()))"] +# backtrack called with (()() 3 2 ["((()))"] +# backtrack called with (()()) 3 3 ["((()))"] +# backtrack return with (()() 3 2 ["((()))", "(()())"] +# backtrack return with (()( 3 1 ["((()))", "(()())"] +# backtrack called with (()) 2 2 ["((()))", "(()())"] +# backtrack called with (())( 3 2 ["((()))", "(()())"] +# backtrack called with (())() 3 3 ["((()))", "(()())"] +# backtrack return with (())( 3 2 ["((()))", "(()())", "(())()"] +# backtrack return with (()) 2 2 ["((()))", "(()())", "(())()"] +# backtrack return with (() 2 1 ["((()))", "(()())", "(())()"] +# backtrack return with (( 2 0 ["((()))", "(()())", "(())()"] +# backtrack called with () 1 1 ["((()))", "(()())", "(())()"] +# backtrack called with ()( 2 1 ["((()))", "(()())", "(())()"] +# backtrack called with ()(( 3 1 ["((()))", "(()())", "(())()"] +# backtrack called with ()(() 3 2 ["((()))", "(()())", "(())()"] +# backtrack called with ()(()) 3 3 ["((()))", "(()())", "(())()"] +# backtrack return with ()(() 3 2 ["((()))", "(()())", "(())()", "()(())"] +# backtrack return with ()(( 3 1 ["((()))", "(()())", "(())()", "()(())"] +# backtrack called with ()() 2 2 ["((()))", "(()())", "(())()", "()(())"] +# backtrack called with ()()( 3 2 ["((()))", "(()())", "(())()", "()(())"] +# backtrack called with ()()() 3 3 ["((()))", "(()())", "(())()", "()(())"] +# backtrack return with ()()( 3 2 ["((()))", "(()())", "(())()", "()(())", "()()()"] +# backtrack return with ()() 2 2 ["((()))", "(()())", "(())()", "()(())", "()()()"] +# backtrack return with ()( 2 1 ["((()))", "(()())", "(())()", "()(())", "()()()"] +# backtrack return with () 1 1 ["((()))", "(()())", "(())()", "()(())", "()()()"] +# backtrack return with ( 1 0 ["((()))", "(()())", "(())()", "()(())", "()()()"] +# backtrack return with 0 0 ["((()))", "(()())", "(())()", "()(())", "()()()"] + n = 1 print(generate_parenthesis(n)) # Output: ["()"] From fc0c664f6bd123fd2e6f5dba7a06c05497240866 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 1 Apr 2021 10:45:41 -0700 Subject: [PATCH 015/121] close ) --- backtracking/generate_paranthesis.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backtracking/generate_paranthesis.rb b/backtracking/generate_paranthesis.rb index 0ea684e..5c0e3fa 100644 --- a/backtracking/generate_paranthesis.rb +++ b/backtracking/generate_paranthesis.rb @@ -27,8 +27,8 @@ # Complexity Analysis # -# Time Complexity: O(4^n/sqrt(n). Each valid sequence has at most n steps during the backtracking procedure. -# Space Complexity: O(4^n/sqrt(n), as described above, and using O(n) space to store the sequence. +# Time Complexity: O(4^n/sqrt(n)). Each valid sequence has at most n steps during the backtracking procedure. +# Space Complexity: O(4^n/sqrt(n)), as described above, and using O(n) space to store the sequence. # Refer to the attached diagram for recursion, # The numbers next to each node are the counts of left and right parantheses From e90238e1f712285bb87d421acdb34de0760d8ef5 Mon Sep 17 00:00:00 2001 From: Abhinav Anand Date: Fri, 2 Apr 2021 23:01:29 +0530 Subject: [PATCH 016/121] Added factorial iterative program --- maths/factorial_iterative.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 maths/factorial_iterative.rb diff --git a/maths/factorial_iterative.rb b/maths/factorial_iterative.rb new file mode 100644 index 0000000..cc070b3 --- /dev/null +++ b/maths/factorial_iterative.rb @@ -0,0 +1,28 @@ +=begin +A ruby program calculate factorial of a given number. +Mathematical Explanation: The factorial of a number is the product of all the integers from 1 to that number. +i.e: n! = n*(n-1)*(n-2)......*2*1 +=end + +def factorial(n) + if n < 0 + return nil + end + + fac = 1 + while n > 0 + fac = fac * n + n -= 1 + end + + return fac +end + +puts '4! = ' + factorial(4).to_s +# 4! = 24 + +puts '0! = ' + factorial(0).to_s +# 0! = 1 + +puts '10! = ' + factorial(10).to_s +# 10! = 3628800 From 30c9176098283561bee7598eaaebe3019bd345cd Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Fri, 2 Apr 2021 11:22:53 -0700 Subject: [PATCH 017/121] minor changes --- .../{factorial_iterative.rb => factorial.rb} | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) rename maths/{factorial_iterative.rb => factorial.rb} (72%) diff --git a/maths/factorial_iterative.rb b/maths/factorial.rb similarity index 72% rename from maths/factorial_iterative.rb rename to maths/factorial.rb index cc070b3..e83b347 100644 --- a/maths/factorial_iterative.rb +++ b/maths/factorial.rb @@ -4,18 +4,21 @@ Mathematical Explanation: The factorial of a number is the product of all the in i.e: n! = n*(n-1)*(n-2)......*2*1 =end +# +# Approach: Interative +# + def factorial(n) - if n < 0 - return nil - end - - fac = 1 - while n > 0 - fac = fac * n - n -= 1 - end - - return fac + return nil if n < 0 + + fac = 1 + + while n > 0 + fac *= n + n -= 1 + end + + fac end puts '4! = ' + factorial(4).to_s From 46ec0d4fecc019582272ee848f6be2659abd9d21 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 2 Apr 2021 18:23:23 +0000 Subject: [PATCH 018/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 42b9add..b732e81 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -66,6 +66,7 @@ * [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb) * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) + * [Factorial](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Number Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/number_of_digits.rb) * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/maths/power_of_two.rb) From b1b6f80a0bf16781f828027437c55c6404eaf031 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Sun, 4 Apr 2021 18:26:00 +0530 Subject: [PATCH 019/121] average mean ruby program implementation --- maths/average_mean.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 maths/average_mean.rb diff --git a/maths/average_mean.rb b/maths/average_mean.rb new file mode 100644 index 0000000..0efd5d0 --- /dev/null +++ b/maths/average_mean.rb @@ -0,0 +1,28 @@ +# A ruby program for finding average mean + +module AverageMean + # Average mean = sum of elements / total number of elements + def self.average_mean(n, *array) + if n.instance_of? Integer + if n == array.size + puts "The average mean of the following elements #{array} is #{array.sum/array.size}." + else + puts "Provide the required #{n} elements properly!" + end + else + raise + end + rescue + puts "Error: Please provide number only!" + end +end + +# Valid inputs +AverageMean.average_mean(2, 3, 1) +AverageMean.average_mean(5, 1, 2, 3, 4, 5) +AverageMean.average_mean(3, 2, 2, 2) + +# Invalid inputs +AverageMean.average_mean(2, 3, 1, 5) +AverageMean.average_mean(2, 3, "a") +AverageMean.average_mean("a", 1, 2) From 04a4c9aaedfac2f3b9145be39f1201362a053a0d Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Mon, 5 Apr 2021 13:57:41 -0700 Subject: [PATCH 020/121] Add solution using .reverse --- data_structures/arrays/strings/palindrome.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/data_structures/arrays/strings/palindrome.rb b/data_structures/arrays/strings/palindrome.rb index 1ebcfbe..03490ac 100644 --- a/data_structures/arrays/strings/palindrome.rb +++ b/data_structures/arrays/strings/palindrome.rb @@ -20,12 +20,13 @@ # @return {Boolean} # -# Approach 1: Brute Force +# Approach 1: Using Ruby method .reverse # -# Time Complexity: +# Time Complexity: O(n) # def is_palindrome(s) - s.downcase + letters_only = s.downcase.gsub(/[^0-9a-z]/i, '') + letters_only.reverse == letters_only end s = 'A man, a plan, a canal: Panama' From 6c7b37ab76b1a52c93205d91fb65a9d0413cc1db Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Mon, 5 Apr 2021 14:08:23 -0700 Subject: [PATCH 021/121] Add solution using a reversed array --- data_structures/arrays/strings/palindrome.rb | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/data_structures/arrays/strings/palindrome.rb b/data_structures/arrays/strings/palindrome.rb index 03490ac..4d70171 100644 --- a/data_structures/arrays/strings/palindrome.rb +++ b/data_structures/arrays/strings/palindrome.rb @@ -39,6 +39,35 @@ puts is_palindrome(s) # Output: false # Explanation: "raceacar" is not a palindrome. +s = 'ab_a' +puts is_palindrome(s) +# Output: true +# Explanation: "aba" is a palindrome. + +# +# Approach 2: Reversed array +# +# Time Complexity: O(n) +# +def is_palindrome(s) + letters_only_array = s.downcase.gsub(/[^0-9a-z]/i, '').split('') + reversed_array = [] + letters_only_array.each do |letter| + reversed_array.unshift(letter) + end + letters_only_array == reversed_array +end + +s = 'A man, a plan, a canal: Panama' +puts is_palindrome(s) +# Output: true +# Explanation: "amanaplanacanalpanama" is a palindrome. + +s = 'race a car' +puts is_palindrome(s) +# Output: false +# Explanation: "raceacar" is not a palindrome. + s = 'ab_a' puts is_palindrome(s) # Output: true From 7655003b6cc333ee1512a33f7c9fa0901974189d Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Mon, 5 Apr 2021 14:31:57 -0700 Subject: [PATCH 022/121] Add solution using two pointers --- data_structures/arrays/strings/palindrome.rb | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/data_structures/arrays/strings/palindrome.rb b/data_structures/arrays/strings/palindrome.rb index 4d70171..28e7921 100644 --- a/data_structures/arrays/strings/palindrome.rb +++ b/data_structures/arrays/strings/palindrome.rb @@ -68,6 +68,42 @@ puts is_palindrome(s) # Output: false # Explanation: "raceacar" is not a palindrome. +s = 'ab_a' +puts is_palindrome(s) +# Output: true +# Explanation: "aba" is a palindrome. + +# +# Approach 2: Two Pointers +# +# Time Complexity: O(n) +# +def is_palindrome(s) + letters_only = s.downcase.gsub(/[^0-9a-z]/i, '') + p1 = 0 + p2 = letters_only.length - 1 + + while p1 < p2 + if letters_only[p1] == letters_only[p2] + p1 += 1 + p2 -= 1 + else + return false + end + end + true +end + +s = 'A man, a plan, a canal: Panama' +puts is_palindrome(s) +# Output: true +# Explanation: "amanaplanacanalpanama" is a palindrome. + +s = 'race a car' +puts is_palindrome(s) +# Output: false +# Explanation: "raceacar" is not a palindrome. + s = 'ab_a' puts is_palindrome(s) # Output: true From e6b674275ea56995dafe8e7e080e3789ea503f91 Mon Sep 17 00:00:00 2001 From: nyapsilon Date: Fri, 9 Apr 2021 21:24:04 +0300 Subject: [PATCH 023/121] Minor code style improvements Tabs are corrected, semantic blocks are separated. --- Searches/binary_search.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Searches/binary_search.rb b/Searches/binary_search.rb index bbc8efa..d0710a2 100644 --- a/Searches/binary_search.rb +++ b/Searches/binary_search.rb @@ -8,18 +8,21 @@ def binary_search(array, key) return middle if array[middle] == key if key < array[middle] - back = middle - 1 -else - front = middle + 1 -end + back = middle - 1 + else + front = middle + 1 + end end + nil end puts "Enter a sorted space-separated list:" arr = gets.chomp.split(' ').map(&:to_i) + puts "Enter the value to be searched:" value = gets.chomp.to_i + puts if binary_search(arr, value) != nil "Found at index #{binary_search(arr, value)}" else From bd6b1067c0b56d206e7c4a9307c57312289bc197 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Fri, 9 Apr 2021 21:07:54 -0700 Subject: [PATCH 024/121] Update data_structures/arrays/strings/palindrome.rb --- data_structures/arrays/strings/palindrome.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/data_structures/arrays/strings/palindrome.rb b/data_structures/arrays/strings/palindrome.rb index 28e7921..176243e 100644 --- a/data_structures/arrays/strings/palindrome.rb +++ b/data_structures/arrays/strings/palindrome.rb @@ -76,7 +76,14 @@ puts is_palindrome(s) # # Approach 2: Two Pointers # -# Time Complexity: O(n) + +# +# Complexity Analysis: +# +# Time Complexity: O(n), in length n of the string. We traverse over each +# character at most once until the two pointers meet in the middle, or when +# we break and return early. +# Space Complexity: O(1). No extra space required, at all. # def is_palindrome(s) letters_only = s.downcase.gsub(/[^0-9a-z]/i, '') @@ -107,4 +114,4 @@ puts is_palindrome(s) s = 'ab_a' puts is_palindrome(s) # Output: true -# Explanation: "aba" is a palindrome. \ No newline at end of file +# Explanation: "aba" is a palindrome. From 49db26c56be44d2ca3ab00034e264a1ae877604e Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Fri, 9 Apr 2021 21:07:57 -0700 Subject: [PATCH 025/121] Update data_structures/arrays/strings/palindrome.rb --- data_structures/arrays/strings/palindrome.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/data_structures/arrays/strings/palindrome.rb b/data_structures/arrays/strings/palindrome.rb index 176243e..587e242 100644 --- a/data_structures/arrays/strings/palindrome.rb +++ b/data_structures/arrays/strings/palindrome.rb @@ -47,7 +47,17 @@ puts is_palindrome(s) # # Approach 2: Reversed array # -# Time Complexity: O(n) +# Complexity Analysis: +# +# Time Complexity: O(n), in length n of the string. +# +# We need to iterate through the string: When we filter out non-alphanumeric characters and convert the remaining +# characters to lower-case. When we reverse the string. When we compare the original and the reversed strings. +# Each iteration runs linearly in time (since each character operation completes in constant time). +# Thus, the effective run-time complexity is linear. +# +# Space Complexity: O(n), in length n of the string. We need O(n) additional +# space to store the filtered string and the reversed string. # def is_palindrome(s) letters_only_array = s.downcase.gsub(/[^0-9a-z]/i, '').split('') From 443cf9db8850e78d45f1fde83907f1d021e597e0 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 10 Apr 2021 04:07:57 +0000 Subject: [PATCH 026/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index d118dca..c94db91 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -65,6 +65,7 @@ * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add_digits.rb) * [Aliquot Sum](https://github.com/TheAlgorithms/Ruby/blob/master/maths/aliquot_sum.rb) * [Aliquot Sum Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/aliquot_sum_test.rb) + * [Average Mean](https://github.com/TheAlgorithms/Ruby/blob/master/maths/average_mean.rb) * [Binary To Decimal](https://github.com/TheAlgorithms/Ruby/blob/master/maths/binary_to_decimal.rb) * [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb) * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) From 9fbd75fa66dd64a7766fa250075e37bcd26c406f Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 09:56:05 -0700 Subject: [PATCH 027/121] Add hash table approach --- data_structures/arrays/arrays_intersection.rb | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 data_structures/arrays/arrays_intersection.rb diff --git a/data_structures/arrays/arrays_intersection.rb b/data_structures/arrays/arrays_intersection.rb new file mode 100644 index 0000000..cf1c1dc --- /dev/null +++ b/data_structures/arrays/arrays_intersection.rb @@ -0,0 +1,55 @@ +# Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays. +# +# Example 1: +# +# Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8] +# Output: [1,5] +# Explanation: Only 1 and 5 appeared in the three arrays. +# +# Example 2: +# +# Input: arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764] +# Output: [] +# +# + +# +# Approach: Hash table +# + +# Complexity Analysis + +# Time Complexity: O(n) - n is the total length of +# all of the input arrays. +# Space Complexity: O(n) - n is the total length of all of the +# input arrays. This is because we adopted a Hash table to store all +# numbers and their number of appearances as values. + +def arrays_intersection(arr1, arr2, arr3) + hash = Hash.new(0) + + add_to_hash(arr1, hash) + add_to_hash(arr2, hash) + add_to_hash(arr3, hash) + + hash.select { |key, value| value == 3 }.keys +end + +def add_to_hash(arr, hash) + arr.each_with_index do |value, index| + hash[value] += 1 + end +end + +arr1 = [1,2,3,4,5] +arr2 = [1,2,5,7,9] +arr3 = [1,3,4,5,8] +print arrays_intersection(arr1, arr2, arr3) +# Output: [1,5] +# Explanation: Only 1 and 5 appeared in the three arrays. + +arr1 = [197,418,523,876,1356] +arr2 = [501,880,1593,1710,1870] +arr3 = [521,682,1337,1395,1764] +print arrays_intersection(arr1, arr2, arr3) +# Output: [] From 21e8bb04ef3d4346e1ba94dfb093fb7e1ed3cba3 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 10 Apr 2021 16:56:19 +0000 Subject: [PATCH 028/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index a34b83d..bd38b0d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -14,6 +14,7 @@ ## Data Structures * Arrays * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/add_digits.rb) + * [Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/arrays_intersection.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_all_duplicates_in_an_array.rb) * [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb) * [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb) From fe4e56e8a4a04b3fc317477ad6a16e369f50bf1a Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 09:57:25 -0700 Subject: [PATCH 029/121] Move to correct path --- data_structures/{arrays => hash_table}/arrays_intersection.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename data_structures/{arrays => hash_table}/arrays_intersection.rb (100%) diff --git a/data_structures/arrays/arrays_intersection.rb b/data_structures/hash_table/arrays_intersection.rb similarity index 100% rename from data_structures/arrays/arrays_intersection.rb rename to data_structures/hash_table/arrays_intersection.rb From d6e7b9f1d8411d02a81664f517dbec81b56f9e27 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 10 Apr 2021 16:57:53 +0000 Subject: [PATCH 030/121] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index bd38b0d..daeb2cc 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -14,7 +14,6 @@ ## Data Structures * Arrays * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/add_digits.rb) - * [Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/arrays_intersection.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_all_duplicates_in_an_array.rb) * [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb) * [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb) @@ -38,6 +37,7 @@ * [Preorder Traversal](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/binary_trees/preorder_traversal.rb) * Hash Table * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/anagram_checker.rb) + * [Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/arrays_intersection.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/find_all_duplicates_in_an_array.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/richest_customer_wealth.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/two_sum.rb) From 745b66227bb05231d401d51e558a00aae42d3a39 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 10:04:40 -0700 Subject: [PATCH 031/121] Minor changes --- .../hash_table/arrays_intersection.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/data_structures/hash_table/arrays_intersection.rb b/data_structures/hash_table/arrays_intersection.rb index cf1c1dc..7d270fc 100644 --- a/data_structures/hash_table/arrays_intersection.rb +++ b/data_structures/hash_table/arrays_intersection.rb @@ -32,24 +32,25 @@ def arrays_intersection(arr1, arr2, arr3) add_to_hash(arr2, hash) add_to_hash(arr3, hash) - hash.select { |key, value| value == 3 }.keys + hash.select { |_key, value| value == 3 }.keys end def add_to_hash(arr, hash) - arr.each_with_index do |value, index| - hash[value] += 1 + arr.count.times do |pointer| + value = arr[pointer] + hash[value] += 1 end end -arr1 = [1,2,3,4,5] -arr2 = [1,2,5,7,9] -arr3 = [1,3,4,5,8] +arr1 = [1, 2, 3, 4, 5] +arr2 = [1, 2, 5, 7, 9] +arr3 = [1, 3, 4, 5, 8] print arrays_intersection(arr1, arr2, arr3) # Output: [1,5] # Explanation: Only 1 and 5 appeared in the three arrays. -arr1 = [197,418,523,876,1356] -arr2 = [501,880,1593,1710,1870] -arr3 = [521,682,1337,1395,1764] +arr1 = [197, 418, 523, 876, 1356] +arr2 = [501, 880, 1593, 1710, 1870] +arr3 = [521, 682, 1337, 1395, 1764] print arrays_intersection(arr1, arr2, arr3) # Output: [] From 2197a587fb4d6405adc425adfa81bf06922c550b Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 10:15:00 -0700 Subject: [PATCH 032/121] Update arrays_intersection.rb --- data_structures/hash_table/arrays_intersection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/hash_table/arrays_intersection.rb b/data_structures/hash_table/arrays_intersection.rb index 7d270fc..f100e37 100644 --- a/data_structures/hash_table/arrays_intersection.rb +++ b/data_structures/hash_table/arrays_intersection.rb @@ -32,7 +32,7 @@ def arrays_intersection(arr1, arr2, arr3) add_to_hash(arr2, hash) add_to_hash(arr3, hash) - hash.select { |_key, value| value == 3 }.keys + hash.select { |key, value| value == 3 }.keys end def add_to_hash(arr, hash) From ce0d1863a292cb69ab7ab01b4145e8e462058f29 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 10:38:43 -0700 Subject: [PATCH 033/121] Next greater element --- .../arrays/next_greater_element.rb | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 data_structures/arrays/next_greater_element.rb diff --git a/data_structures/arrays/next_greater_element.rb b/data_structures/arrays/next_greater_element.rb new file mode 100644 index 0000000..fc71766 --- /dev/null +++ b/data_structures/arrays/next_greater_element.rb @@ -0,0 +1,55 @@ +# You are given two integer arrays nums1 and nums2 both of unique elements, where nums1 is a subset of nums2. +# +# Find all the next greater numbers for nums1's elements in the corresponding places of nums2. +# +# The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, return -1 for this number. + +# Example 1: +# +# Input: nums1 = [4,1,2], nums2 = [1,3,4,2] +# Output: [-1,3,-1] +# +# Explanation: +# For number 4 in the first array, you cannot find the next greater number for it in the second array, so output -1. +# For number 1 in the first array, the next greater number for it in the second array is 3. +# For number 2 in the first array, there is no next greater number for it in the second array, so output -1. +# +# Example 2: +# +# Input: nums1 = [2,4], nums2 = [1,2,3,4] +# Output: [3,-1] +# +# Explanation: +# For number 2 in the first array, the next greater number for it in the second array is 3. +# For number 4 in the first array, there is no next greater number for it in the second array, so output -1. + +# @param {Integer[]} nums1 +# @param {Integer[]} nums2 +# @return {Integer[]} +def next_greater_element(nums1, nums2) + nums1.each_with_index do |value, pointer1| + max = 0 + pos_nums2 = nums2.find_index(value) + + nums2[pos_nums2..nums2.count].each do |value| + if value > nums1[pointer1] + max = value + break + end + end + + nums1[pointer1] = (nums1[pointer1] < max ? max : -1) + end + + nums1 +end + +nums1 = [4, 1, 2] +nums2 = [1, 3, 4, 2] +print next_greater_element(nums1, nums2) +# Output: [-1,3,-1] + +nums1 = [2, 4] +nums2 = [1, 2, 3, 4] +print next_greater_element(nums1, nums2) +# Output: [3,-1] From 1c9a26f389a5d62b60a10a7879c0eed848ec8c0f Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 10:41:01 -0700 Subject: [PATCH 034/121] Minor changes --- data_structures/arrays/next_greater_element.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/data_structures/arrays/next_greater_element.rb b/data_structures/arrays/next_greater_element.rb index fc71766..0790ab1 100644 --- a/data_structures/arrays/next_greater_element.rb +++ b/data_structures/arrays/next_greater_element.rb @@ -18,7 +18,7 @@ # # Input: nums1 = [2,4], nums2 = [1,2,3,4] # Output: [3,-1] -# +# # Explanation: # For number 2 in the first array, the next greater number for it in the second array is 3. # For number 4 in the first array, there is no next greater number for it in the second array, so output -1. @@ -27,18 +27,18 @@ # @param {Integer[]} nums2 # @return {Integer[]} def next_greater_element(nums1, nums2) - nums1.each_with_index do |value, pointer1| + nums1.each_with_index do |nums1_value, pointer1| max = 0 - pos_nums2 = nums2.find_index(value) + pos_nums2 = nums2.find_index(nums1_value) - nums2[pos_nums2..nums2.count].each do |value| - if value > nums1[pointer1] - max = value + nums2[pos_nums2..nums2.count].each do |nums2_value| + if nums2_value > nums1_value + max = nums2_value break end end - nums1[pointer1] = (nums1[pointer1] < max ? max : -1) + nums1[pointer1] = (nums1_value < max ? max : -1) end nums1 From 4e0d914d63c1eb4c4ea2eb436325b3e2992623cf Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 10 Apr 2021 17:41:17 +0000 Subject: [PATCH 035/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index c94db91..763e907 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -18,6 +18,7 @@ * [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb) * [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb) * [Get Products Of All Other Elements](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/get_products_of_all_other_elements.rb) + * [Next Greater Element](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/next_greater_element.rb) * [Remove Elements](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/remove_elements.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/richest_customer_wealth.rb) * [Shuffle Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/shuffle_array.rb) From 4d9d7ca1cdad47591163d384c8de5f891f23c2a8 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 10:46:55 -0700 Subject: [PATCH 036/121] add complexity analysis --- data_structures/arrays/next_greater_element.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/data_structures/arrays/next_greater_element.rb b/data_structures/arrays/next_greater_element.rb index 0790ab1..ffe957e 100644 --- a/data_structures/arrays/next_greater_element.rb +++ b/data_structures/arrays/next_greater_element.rb @@ -23,6 +23,15 @@ # For number 2 in the first array, the next greater number for it in the second array is 3. # For number 4 in the first array, there is no next greater number for it in the second array, so output -1. +# +# Approach: Brute Force +# + +# Complexity Analysis +# +# Time complexity : O(m*n). The complete nums1 array (of size n) needs to be scanned for all the m elements of nums2 in the worst case. +# Space complexity : O(1). No additional space since we're swapping elements in nums1 and returning the input array. + # @param {Integer[]} nums1 # @param {Integer[]} nums2 # @return {Integer[]} From 20d5ea3b6d419bd3b9fc62f07c3863607ff1c167 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 10 Apr 2021 10:49:41 -0700 Subject: [PATCH 037/121] Update next_greater_element.rb --- data_structures/arrays/next_greater_element.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/arrays/next_greater_element.rb b/data_structures/arrays/next_greater_element.rb index ffe957e..92b3344 100644 --- a/data_structures/arrays/next_greater_element.rb +++ b/data_structures/arrays/next_greater_element.rb @@ -29,8 +29,8 @@ # Complexity Analysis # -# Time complexity : O(m*n). The complete nums1 array (of size n) needs to be scanned for all the m elements of nums2 in the worst case. -# Space complexity : O(1). No additional space since we're swapping elements in nums1 and returning the input array. +# Time complexity: O(m*n). The complete nums1 array (of size n) needs to be scanned for all the m elements of nums2 in the worst case. +# Space complexity: O(1). No additional space since we're swapping elements in nums1 and returning the input array. # @param {Integer[]} nums1 # @param {Integer[]} nums2 From 1a8dc1debfad7e10719736dafd32edfbc291a393 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Sun, 11 Apr 2021 00:36:28 +0530 Subject: [PATCH 038/121] add feature implementation --- maths/add.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 maths/add.rb diff --git a/maths/add.rb b/maths/add.rb new file mode 100644 index 0000000..7351c32 --- /dev/null +++ b/maths/add.rb @@ -0,0 +1,20 @@ +# A ruby program to add numbers +# Addition or sum of numbers means adding each and every element of the inputs +# Sum or addition of 1 and 3 is 1 + 3 = 4 + +def self_add(*array) + sum = 0 + array.each { |a| sum+=a } + puts "The sum of following elements #{array} is #{sum}" + rescue + puts "Error: Please provide number only!" +end + +# Valid inputs +self_add(1) +self_add(2, 5, -4) +self_add(25, 45) + +# Invalid inputs +self_add("1", 2, 3) +self_add("a", 1) From f94eafd15a76817545647c5c408af416fd21ee15 Mon Sep 17 00:00:00 2001 From: maxbarsukov Date: Sun, 11 Apr 2021 14:39:22 +0300 Subject: [PATCH 039/121] The Searches folder is renamed to lowercase just like the other folders --- {Searches => searches}/binary_search.rb | 0 {Searches => searches}/depth_first_search.rb | 0 {Searches => searches}/double_linear_search.rb | 0 {Searches => searches}/jump_search.rb | 0 {Searches => searches}/linear_search.rb | 0 {Searches => searches}/recursive_double_linear_search.rb | 0 {Searches => searches}/recursive_linear_search.rb | 0 {Searches => searches}/ternary_search.rb | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename {Searches => searches}/binary_search.rb (100%) rename {Searches => searches}/depth_first_search.rb (100%) rename {Searches => searches}/double_linear_search.rb (100%) rename {Searches => searches}/jump_search.rb (100%) rename {Searches => searches}/linear_search.rb (100%) rename {Searches => searches}/recursive_double_linear_search.rb (100%) rename {Searches => searches}/recursive_linear_search.rb (100%) rename {Searches => searches}/ternary_search.rb (100%) diff --git a/Searches/binary_search.rb b/searches/binary_search.rb similarity index 100% rename from Searches/binary_search.rb rename to searches/binary_search.rb diff --git a/Searches/depth_first_search.rb b/searches/depth_first_search.rb similarity index 100% rename from Searches/depth_first_search.rb rename to searches/depth_first_search.rb diff --git a/Searches/double_linear_search.rb b/searches/double_linear_search.rb similarity index 100% rename from Searches/double_linear_search.rb rename to searches/double_linear_search.rb diff --git a/Searches/jump_search.rb b/searches/jump_search.rb similarity index 100% rename from Searches/jump_search.rb rename to searches/jump_search.rb diff --git a/Searches/linear_search.rb b/searches/linear_search.rb similarity index 100% rename from Searches/linear_search.rb rename to searches/linear_search.rb diff --git a/Searches/recursive_double_linear_search.rb b/searches/recursive_double_linear_search.rb similarity index 100% rename from Searches/recursive_double_linear_search.rb rename to searches/recursive_double_linear_search.rb diff --git a/Searches/recursive_linear_search.rb b/searches/recursive_linear_search.rb similarity index 100% rename from Searches/recursive_linear_search.rb rename to searches/recursive_linear_search.rb diff --git a/Searches/ternary_search.rb b/searches/ternary_search.rb similarity index 100% rename from Searches/ternary_search.rb rename to searches/ternary_search.rb From b2fc530555f38f2da5f3fe173e5ae6f97b406ee3 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 11 Apr 2021 22:56:29 +0000 Subject: [PATCH 040/121] updating DIRECTORY.md --- DIRECTORY.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index a34b83d..45e03fa 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -104,14 +104,14 @@ * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_5/sol1.rb) ## Searches - * [Binary Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/binary_search.rb) - * [Depth First Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/depth_first_search.rb) - * [Double Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/double_linear_search.rb) - * [Jump Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/jump_search.rb) - * [Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/linear_search.rb) - * [Recursive Double Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/recursive_double_linear_search.rb) - * [Recursive Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/recursive_linear_search.rb) - * [Ternary Search](https://github.com/TheAlgorithms/Ruby/blob/master/Searches/ternary_search.rb) + * [Binary Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/binary_search.rb) + * [Depth First Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/depth_first_search.rb) + * [Double Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/double_linear_search.rb) + * [Jump Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/jump_search.rb) + * [Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/linear_search.rb) + * [Recursive Double Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/recursive_double_linear_search.rb) + * [Recursive Linear Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/recursive_linear_search.rb) + * [Ternary Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/ternary_search.rb) ## Sorting * [Bogo Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bogo_sort.rb) From ae40765c38c30ef075f3c8c150f1dd28df282a21 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Tue, 13 Apr 2021 00:58:45 +0530 Subject: [PATCH 041/121] average median feature implementation --- maths/average_median.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 maths/average_median.rb diff --git a/maths/average_median.rb b/maths/average_median.rb new file mode 100644 index 0000000..52f86c2 --- /dev/null +++ b/maths/average_median.rb @@ -0,0 +1,37 @@ +# A ruby program to find average median + +module AverageMedian + + def self.average_median(n, *array) + if n.instance_of? Integer + if n == array.size + array.sort + if array.size%2 == 0 + mid_element_1 = array.size/2 + mid_element_2 = mid_element_1 + 1 + puts "The average median of the following elements #{array} is #{(array[mid_element_1-1] + array[mid_element_2-1])/2}." + else + mid_element = (array.size + 1)/2 + puts "The average median of the following elements #{array} is #{array[mid_element-1]}." + end + else + puts "Provide the required #{n} elements properly!" + end + else + raise + end + rescue + puts "Error: Please provide number only!" + end +end + +# Valid inputs +AverageMedian.average_median(2, 3, 1) +AverageMedian.average_median(5, 1, 2, 3, 4, 5) +AverageMedian.average_median(3, 2, 2, 2) +AverageMedian.average_median(1, 5) + +# Invalid inputs +AverageMedian.average_median(2, 3, 1, 5) +AverageMedian.average_median(2, 3, "a") +AverageMedian.average_median("a", 1, 2) From 0df659abae276bb7b42821a4f30d0883fd6ef16e Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 14 Apr 2021 16:29:37 -0700 Subject: [PATCH 042/121] renaming --- maths/add.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maths/add.rb b/maths/add.rb index 7351c32..1c756b4 100644 --- a/maths/add.rb +++ b/maths/add.rb @@ -2,7 +2,7 @@ # Addition or sum of numbers means adding each and every element of the inputs # Sum or addition of 1 and 3 is 1 + 3 = 4 -def self_add(*array) +def add(*array) sum = 0 array.each { |a| sum+=a } puts "The sum of following elements #{array} is #{sum}" @@ -11,10 +11,10 @@ def self_add(*array) end # Valid inputs -self_add(1) -self_add(2, 5, -4) -self_add(25, 45) +add(1) +add(2, 5, -4) +add(25, 45) # Invalid inputs -self_add("1", 2, 3) -self_add("a", 1) +add("1", 2, 3) +add("a", 1) From 82d71a94c7f82b27bce665c40eb43942d3257bd9 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 14 Apr 2021 16:36:21 -0700 Subject: [PATCH 043/121] Update average_median.rb --- maths/average_median.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/average_median.rb b/maths/average_median.rb index 52f86c2..5e94bd7 100644 --- a/maths/average_median.rb +++ b/maths/average_median.rb @@ -1,4 +1,5 @@ # A ruby program to find average median +# Reference: https://dev.to/colerau/how-to-find-the-median-and-mean-of-an-array-in-ruby-4f04 module AverageMedian From fbe6e9851d43c9c094aed24a5fe30c199aa465d3 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 14 Apr 2021 16:39:13 -0700 Subject: [PATCH 044/121] add output --- maths/average_median.rb | 46 ++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/maths/average_median.rb b/maths/average_median.rb index 5e94bd7..9e447bd 100644 --- a/maths/average_median.rb +++ b/maths/average_median.rb @@ -2,18 +2,17 @@ # Reference: https://dev.to/colerau/how-to-find-the-median-and-mean-of-an-array-in-ruby-4f04 module AverageMedian - def self.average_median(n, *array) if n.instance_of? Integer if n == array.size array.sort - if array.size%2 == 0 + if array.size % 2 == 0 mid_element_1 = array.size/2 mid_element_2 = mid_element_1 + 1 - puts "The average median of the following elements #{array} is #{(array[mid_element_1-1] + array[mid_element_2-1])/2}." + puts "The average median of the following elements #{array} is #{(array[mid_element_1 - 1] + array[mid_element_2 - 1]) / 2}." else - mid_element = (array.size + 1)/2 - puts "The average median of the following elements #{array} is #{array[mid_element-1]}." + mid_element = (array.size + 1) / 2 + puts "The average median of the following elements #{array} is #{array[mid_element - 1]}." end else puts "Provide the required #{n} elements properly!" @@ -26,13 +25,36 @@ module AverageMedian end end +# # Valid inputs -AverageMedian.average_median(2, 3, 1) -AverageMedian.average_median(5, 1, 2, 3, 4, 5) -AverageMedian.average_median(3, 2, 2, 2) -AverageMedian.average_median(1, 5) +# +puts AverageMedian.average_median(2, 3, 1) +# The average median of the following elements [3, 1] is 2. + +puts AverageMedian.average_median(5, 1, 2, 3, 4, 5) +# The average median of the following elements [1, 2, 3, 4, 5] is 3. + +puts AverageMedian.average_median(3, 2, 2, 2) +# The average median of the following elements [2, 2, 2] is 2. + +puts AverageMedian.average_median(1, 5) +# The average median of the following elements [5] is 5. + +# # Invalid inputs -AverageMedian.average_median(2, 3, 1, 5) -AverageMedian.average_median(2, 3, "a") -AverageMedian.average_median("a", 1, 2) +# + +puts AverageMedian.average_median(2, 3, 1, 5) +# Provide the required 2 elements properly! + +puts AverageMedian.average_median(2, 3, "a") +# Traceback (most recent call last): +# 4: from /Users/voliveira/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `
' +# 3: from /Users/voliveira/.rvm/rubies/ruby-2.7.0/bin/irb:23:in `load' +# 2: from /Users/voliveira/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `' +# 1: from (irb):30 +# NameError (undefined local variable or method `verageMedian' for main:Object) + +puts AverageMedian.average_median("a", 1, 2) +# Error: Please provide number only! From 256f376574bc179d4e131a2ead1e546443efe223 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 14 Apr 2021 16:40:39 -0700 Subject: [PATCH 045/121] add output for add algo --- maths/add.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/maths/add.rb b/maths/add.rb index 1c756b4..a8a6c35 100644 --- a/maths/add.rb +++ b/maths/add.rb @@ -10,11 +10,25 @@ def add(*array) puts "Error: Please provide number only!" end +# # Valid inputs -add(1) -add(2, 5, -4) -add(25, 45) +# +puts add(1) +# The sum of following elements [1] is 1 + +puts add(2, 5, -4) +# The sum of following elements [2, 5, -4] is 3 + +puts add(25, 45) +# The sum of following elements [25, 45] is 70 + +# # Invalid inputs -add("1", 2, 3) -add("a", 1) +# + +puts add("1", 2, 3) +# Error: Please provide number only! + +puts add("a", 1) +# Error: Please provide number only! From 0f3441c0882faa759dcfcccb021631e0f5b45dd0 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 14 Apr 2021 23:41:50 +0000 Subject: [PATCH 046/121] updating DIRECTORY.md --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4f8a0a7..df4f340 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -65,10 +65,12 @@ ## Maths * [Abs](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs.rb) * [Abs Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_test.rb) + * [Add](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add.rb) * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add_digits.rb) * [Aliquot Sum](https://github.com/TheAlgorithms/Ruby/blob/master/maths/aliquot_sum.rb) * [Aliquot Sum Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/aliquot_sum_test.rb) * [Average Mean](https://github.com/TheAlgorithms/Ruby/blob/master/maths/average_mean.rb) + * [Average Median](https://github.com/TheAlgorithms/Ruby/blob/master/maths/average_median.rb) * [Binary To Decimal](https://github.com/TheAlgorithms/Ruby/blob/master/maths/binary_to_decimal.rb) * [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb) * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) From 50e6dc6f86993d9ad93fdf4760d4204fcc49fd9c Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 15 Apr 2021 17:25:30 -0700 Subject: [PATCH 047/121] Arrays intersection: two-pointer approach --- data_structures/arrays/arrays_intersection.rb | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 data_structures/arrays/arrays_intersection.rb diff --git a/data_structures/arrays/arrays_intersection.rb b/data_structures/arrays/arrays_intersection.rb new file mode 100644 index 0000000..63db80e --- /dev/null +++ b/data_structures/arrays/arrays_intersection.rb @@ -0,0 +1,67 @@ +# Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays. +# +# Example 1: +# +# Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8] +# Output: [1,5] +# Explanation: Only 1 and 5 appeared in the three arrays. +# +# Example 2: +# +# Input: arr1 = [197,418,523,876,1356], arr2 = [501,880,1593,1710,1870], arr3 = [521,682,1337,1395,1764] +# Output: [] +# +# + +# +# Approach: Two-pointer +# + +# Complexity Analysis +# +# Time Complexity: O(n), where n is the total length of all of the +# input arrays. +# Space Complexity: O(1), as we only initiate three integer variables +# using constant space. + +# @param {Integer[]} arr1 +# @param {Integer[]} arr2 +# @param {Integer[]} arr3 +# @return {Integer[]} +def arrays_intersection(arr1, arr2, arr3) + result = [] + + # prepare three pointers to iterate through three arrays + # p1, p2, and p3 point to the beginning of arr1, arr2, and arr3 accordingly + p1 = p2 = p3 = 0 + + while (p1 < arr1.count) && (p2 < arr2.count) && (p3 < arr3.count) + if arr1[p1] == arr2[p2] && arr1[p1] == arr3[p3] + result.push(arr1[p1]) + + p1 += 1 + p2 += 1 + p3 += 1 + elsif arr1[p1] < arr2[p2] + p1 += 1 + elsif arr2[p2] < arr3[p3] + p2 += 1 + else + p3 += 1 + end + end + + result +end + +arr1 = [1, 2, 3, 4, 5] +arr2 = [1, 2, 5, 7, 9] +arr3 = [1, 3, 4, 5, 8] +print(arrays_intersection(arr1, arr2, arr3)) +# Output: [1,5] + +arr1 = [197, 418, 523, 876, 1356] +arr2 = [501, 880, 1593, 1710, 1870] +arr3 = [521, 682, 1337, 1395, 1764] +print(arrays_intersection(arr1, arr2, arr3)) +# Output: [] From 6a076bde0750af89a078e98a49c0e7c0b4735f33 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 16 Apr 2021 00:25:50 +0000 Subject: [PATCH 048/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index df4f340..4c08933 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -14,6 +14,7 @@ ## Data Structures * Arrays * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/add_digits.rb) + * [Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/arrays_intersection.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_all_duplicates_in_an_array.rb) * [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb) * [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb) From da89bae9314f1dc838ec299556324908a479f1f3 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 15 Apr 2021 17:27:27 -0700 Subject: [PATCH 049/121] Update arrays_intersection.rb --- data_structures/arrays/arrays_intersection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/arrays/arrays_intersection.rb b/data_structures/arrays/arrays_intersection.rb index 63db80e..c9780e0 100644 --- a/data_structures/arrays/arrays_intersection.rb +++ b/data_structures/arrays/arrays_intersection.rb @@ -14,7 +14,7 @@ # # -# Approach: Two-pointer +# Approach: Two-pointers # # Complexity Analysis From b101ef25d7aec58f631293f0ff91c355c298120a Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Thu, 15 Apr 2021 18:00:29 -0700 Subject: [PATCH 050/121] Update and rename arrays_intersection.rb to sorted_arrays_intersection.rb --- ...arrays_intersection.rb => sorted_arrays_intersection.rb} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename data_structures/arrays/{arrays_intersection.rb => sorted_arrays_intersection.rb} (90%) diff --git a/data_structures/arrays/arrays_intersection.rb b/data_structures/arrays/sorted_arrays_intersection.rb similarity index 90% rename from data_structures/arrays/arrays_intersection.rb rename to data_structures/arrays/sorted_arrays_intersection.rb index c9780e0..a48a7c2 100644 --- a/data_structures/arrays/arrays_intersection.rb +++ b/data_structures/arrays/sorted_arrays_intersection.rb @@ -28,7 +28,7 @@ # @param {Integer[]} arr2 # @param {Integer[]} arr3 # @return {Integer[]} -def arrays_intersection(arr1, arr2, arr3) +def sorted_arrays_intersection(arr1, arr2, arr3) result = [] # prepare three pointers to iterate through three arrays @@ -57,11 +57,11 @@ end arr1 = [1, 2, 3, 4, 5] arr2 = [1, 2, 5, 7, 9] arr3 = [1, 3, 4, 5, 8] -print(arrays_intersection(arr1, arr2, arr3)) +print(sorted_arrays_intersection(arr1, arr2, arr3)) # Output: [1,5] arr1 = [197, 418, 523, 876, 1356] arr2 = [501, 880, 1593, 1710, 1870] arr3 = [521, 682, 1337, 1395, 1764] -print(arrays_intersection(arr1, arr2, arr3)) +print(sorted_arrays_intersection(arr1, arr2, arr3)) # Output: [] From b1131f996a577f874dd3470d373daed7cf302c83 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 16 Apr 2021 01:00:45 +0000 Subject: [PATCH 051/121] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4c08933..1028fcd 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -14,7 +14,6 @@ ## Data Structures * Arrays * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/add_digits.rb) - * [Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/arrays_intersection.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_all_duplicates_in_an_array.rb) * [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb) * [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb) @@ -25,6 +24,7 @@ * [Shuffle Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/shuffle_array.rb) * [Single Number](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/single_number.rb) * [Sort Squares Of An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/sort_squares_of_an_array.rb) + * [Sorted Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/sorted_arrays_intersection.rb) * Strings * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb) * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) From 2c11993806af4b8d91228274faf2576c325dc283 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 16 Apr 2021 14:12:30 -0700 Subject: [PATCH 052/121] Add brute force solution --- data_structures/arrays/intersection.rb | 29 ++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/data_structures/arrays/intersection.rb b/data_structures/arrays/intersection.rb index bd826a0..9633d7b 100644 --- a/data_structures/arrays/intersection.rb +++ b/data_structures/arrays/intersection.rb @@ -7,17 +7,38 @@ # @return {Integer[]} # -# Approach 1: +# Approach 1: Brute Force # -# Time Complexity: +# Time Complexity: O(n^2) # def intersect(arr1, arr2) + result = [] + + if arr1.length < arr2.length + shorter = arr1 + longer = arr2 + else + shorter = arr2 + longer = arr1 + end + + shorter.each do |matcher| + longer.each do |number| + next if number != matcher + result.push(number) + break + end + end + + result end + nums1 = [1, 2, 2, 1] nums2 = [2, 2] -intersect(nums1, nums2) +puts intersect(nums1, nums2) # => [2,2] + nums1 = [4, 9, 5] nums2 = [9, 4, 9, 8, 4] -intersect(nums1, nums2) +puts intersect(nums1, nums2) # => [4,9] \ No newline at end of file From 7b20bca2f82d02d9bc7046bc7d386a11f7389c84 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 16 Apr 2021 16:21:49 -0700 Subject: [PATCH 053/121] Add hash solution --- data_structures/arrays/intersection.rb | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/data_structures/arrays/intersection.rb b/data_structures/arrays/intersection.rb index 9633d7b..a59f58c 100644 --- a/data_structures/arrays/intersection.rb +++ b/data_structures/arrays/intersection.rb @@ -38,6 +38,38 @@ nums2 = [2, 2] puts intersect(nums1, nums2) # => [2,2] +nums1 = [4, 9, 5] +nums2 = [9, 4, 9, 8, 4] +puts intersect(nums1, nums2) +# => [4,9] + +# +# Approach 2: Hash +# +# Time Complexity: O(n) +# +def intersect(arr1, arr2) + result = [] + + hash = Hash.new(0) + + arr2.each {|num| hash[num] += 1 } + + arr1.each do |num| + if hash.has_key?(num) + result << num if hash[num] >= 1 + hash[num] -= 1 + end + end + + result +end + +nums1 = [1, 2, 2, 1] +nums2 = [2, 2] +puts intersect(nums1, nums2) +# => [2,2] + nums1 = [4, 9, 5] nums2 = [9, 4, 9, 8, 4] puts intersect(nums1, nums2) From b0287375a44d9c55bf992fae05028f0ccf51efcb Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 16 Apr 2021 16:33:19 -0700 Subject: [PATCH 054/121] Add two pointers solution --- data_structures/arrays/intersection.rb | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/data_structures/arrays/intersection.rb b/data_structures/arrays/intersection.rb index a59f58c..b0091bc 100644 --- a/data_structures/arrays/intersection.rb +++ b/data_structures/arrays/intersection.rb @@ -61,7 +61,7 @@ def intersect(arr1, arr2) hash[num] -= 1 end end - + result end @@ -70,6 +70,45 @@ nums2 = [2, 2] puts intersect(nums1, nums2) # => [2,2] +nums1 = [4, 9, 5] +nums2 = [9, 4, 9, 8, 4] +puts intersect(nums1, nums2) +# => [4,9] + +# +# Approach 3: Two Pointers +# +# Time Complexity: O(n log n) +# +def intersect(nums1, nums2) + result = [] + p1 = 0 + p2 = 0 + nums1 = nums1.sort + nums2 = nums2.sort + while p1 < nums1.length && p2 < nums2.length + if nums1[p1] < nums2[p2] + p1 += 1 + elsif nums1[p1] > nums2[p2] + p2 += 1 + elsif nums1[p1] == nums2[p2] + result << nums1[p1] + p1 += 1 + p2 += 1 + end + end + + result +end +nums1 = [1, 2, 2, 1] +nums2 = [2, 2] +intersect(nums1, nums2) + +nums1 = [1, 2, 2, 1] +nums2 = [2, 2] +puts intersect(nums1, nums2) +# => [2,2] + nums1 = [4, 9, 5] nums2 = [9, 4, 9, 8, 4] puts intersect(nums1, nums2) From 211bb2c23f18b1e84b2f365ef455d986987f65f0 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 16 Apr 2021 16:57:39 -0700 Subject: [PATCH 055/121] Added sudoku challenge --- DIRECTORY.md | 1 + data_structures/arrays/sudoku.rb | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 data_structures/arrays/sudoku.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index d0c4469..00ba121 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -24,6 +24,7 @@ * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb) * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) * [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb) + * [Sudoku](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/sudoku.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb) * [Two Sum Ii](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum_ii.rb) * Binary Trees diff --git a/data_structures/arrays/sudoku.rb b/data_structures/arrays/sudoku.rb new file mode 100644 index 0000000..cae5d60 --- /dev/null +++ b/data_structures/arrays/sudoku.rb @@ -0,0 +1,40 @@ +# Challenge name: Valid Sudoku + +# Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: +# Each row must contain the digits 1-9 without repetition. +# Each column must contain the digits 1-9 without repetition. +# Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. + +# @param {Character[][]} board +# @return {Boolean} + +# +# Approach 1: +# +# Time Complexity: +# +def is_valid_sudoku(board) +end + +board = [["5","3",".",".","7",".",".",".","."] + ,["6",".",".","1","9","5",".",".","."] + ,[".","9","8",".",".",".",".","6","."] + ,["8",".",".",".","6",".",".",".","3"] + ,["4",".",".","8",".","3",".",".","1"] + ,["7",".",".",".","2",".",".",".","6"] + ,[".","6",".",".",".",".","2","8","."] + ,[".",".",".","4","1","9",".",".","5"] + ,[".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => true +board = [["8","3",".",".","7",".",".",".","."] + ,["6",".",".","1","9","5",".",".","."] + ,[".","9","8",".",".",".",".","6","."] + ,["8",".",".",".","6",".",".",".","3"] + ,["4",".",".","8",".","3",".",".","1"] + ,["7",".",".",".","2",".",".",".","6"] + ,[".","6",".",".",".",".","2","8","."] + ,[".",".",".","4","1","9",".",".","5"] + ,[".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => false \ No newline at end of file From 055bc6fe27e1ff4540226cd3816bc6376db004e8 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Sat, 17 Apr 2021 14:30:24 +0530 Subject: [PATCH 056/121] find max feature implementation --- maths/find_max.rb | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 maths/find_max.rb diff --git a/maths/find_max.rb b/maths/find_max.rb new file mode 100644 index 0000000..54b5072 --- /dev/null +++ b/maths/find_max.rb @@ -0,0 +1,66 @@ +# A ruby program to find max from a set of elements + +module FindMax + # This find_max method will return the max element out of the array + def self.find_max(*array) + max = array[0] + array.each do |a| + if a >= max + max = a + end + end + puts "The Max of the following elements #{array} is #{max}." + rescue + puts "Error: Please provide number only!" + end + + # The max method will return the maximum element from the set of input elements provided + def self.predefined_max(*array) + puts "The Max of the following elements #{array} is #{array.max}." + rescue + puts "Error: Please provide number only!" + end + + # The sort method will sort the elements in ascending order. And the last method will return the end element out of the array + def self.predefined_sort_last_max(*array) + puts "The Max of the following elements #{array} is #{array.sort.last}." + rescue + puts "Error: Please provide number only!" + end +end + +# Using find_max +# Valid inputs +FindMax.find_max(11, 29, 33) +# The Max of the following elements [11, 29, 33] is 33. + +FindMax.find_max(-221, -852, -1100, -10) +# The Max of the following elements [-221, -852, -1100, -10] is -10. + +# Invalid inputs +FindMax.find_max(5, "95", 2) +# Error: Please provide number only! + +# Using predefined_max +# Valid inputs +FindMax.predefined_max(51, 82, 39) +# The Max of the following elements [51, 82, 39] is 82. + +FindMax.predefined_max(-11, -51, -10, -10) +# The Max of the following elements [-11, -51, -10, -10] is -10. + +# Invalid inputs +FindMax.predefined_max("x", 5, 95, 2) +# Error: Please provide number only! + +# Using predefined_sort_last_max +# Valid inputs +FindMax.predefined_sort_last_max(1, 2, 3) +# The Max of the following elements [1, 2, 3] is 3. + +FindMax.predefined_sort_last_max(-21, -52, -100, -1) +# The Max of the following elements [-21, -52, -100, -1] is -1. + +# Invalid inputs +FindMax.predefined_sort_last_max(5, 95, 2, "a") +# Error: Please provide number only! From db2d1b74a299e15038b71b8d77a76d5791a88e59 Mon Sep 17 00:00:00 2001 From: Jessica Kwok <60627484+jsca-kwok@users.noreply.github.com> Date: Mon, 19 Apr 2021 15:54:48 -0700 Subject: [PATCH 057/121] Update data_structures/arrays/intersection.rb Co-authored-by: Vitor Oliveira --- data_structures/arrays/intersection.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/data_structures/arrays/intersection.rb b/data_structures/arrays/intersection.rb index b0091bc..a3cb29c 100644 --- a/data_structures/arrays/intersection.rb +++ b/data_structures/arrays/intersection.rb @@ -78,7 +78,10 @@ puts intersect(nums1, nums2) # # Approach 3: Two Pointers # -# Time Complexity: O(n log n) +# Complexity analysis: + +# Time Complexity: O(nlogn + mlogm), where n and m are the lengths of the arrays. We sort two arrays independently and then do a linear scan. +# Space Complexity: from O(logn+logm) to O(n+m), depending on the implementation of the sorting algorithm. # def intersect(nums1, nums2) result = [] @@ -112,4 +115,4 @@ puts intersect(nums1, nums2) nums1 = [4, 9, 5] nums2 = [9, 4, 9, 8, 4] puts intersect(nums1, nums2) -# => [4,9] \ No newline at end of file +# => [4,9] From 5c1580fc10038963e124a6b7fc3878aeacbf188d Mon Sep 17 00:00:00 2001 From: Jessica Kwok <60627484+jsca-kwok@users.noreply.github.com> Date: Mon, 19 Apr 2021 15:55:22 -0700 Subject: [PATCH 058/121] Update data_structures/arrays/intersection.rb Co-authored-by: Vitor Oliveira --- data_structures/arrays/intersection.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/data_structures/arrays/intersection.rb b/data_structures/arrays/intersection.rb index a3cb29c..dfcd49b 100644 --- a/data_structures/arrays/intersection.rb +++ b/data_structures/arrays/intersection.rb @@ -46,7 +46,14 @@ puts intersect(nums1, nums2) # # Approach 2: Hash # -# Time Complexity: O(n) +# Complexity Analysis +# +# Time Complexity: O(n+m), where n and m are the lengths of the arrays. +# We iterate through the first, and then through the second array; insert +# and lookup operations in the hash map take a constant time. +# +# Space Complexity: O(min(n,m)). We use hash map to store numbers (and their +# counts) from the smaller array. # def intersect(arr1, arr2) result = [] From 0c1892d4ef3e9e8e9a4e8015f408208d8b9fded0 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 21 Apr 2021 15:24:43 +0530 Subject: [PATCH 059/121] find_max code refactor --- maths/find_max.rb | 62 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/maths/find_max.rb b/maths/find_max.rb index 54b5072..f84ba83 100644 --- a/maths/find_max.rb +++ b/maths/find_max.rb @@ -1,66 +1,64 @@ # A ruby program to find max from a set of elements -module FindMax - # This find_max method will return the max element out of the array - def self.find_max(*array) - max = array[0] - array.each do |a| - if a >= max - max = a - end +# This find_max method will return the max element out of the array +def self.find_max(*array) + max = array[0] + array.each do |a| + if a >= max + max = a end - puts "The Max of the following elements #{array} is #{max}." - rescue - puts "Error: Please provide number only!" end + return "The Max of the following elements #{array} is #{max}." + rescue + return "Error: Please provide number only!" +end - # The max method will return the maximum element from the set of input elements provided - def self.predefined_max(*array) - puts "The Max of the following elements #{array} is #{array.max}." - rescue - puts "Error: Please provide number only!" - end +# Max method will return the maximum element from the set of input elements provided +def self.predefined_max(*array) + return "The Max of the following elements #{array} is #{array.max}." + rescue + return "Error: Please provide number only!" +end - # The sort method will sort the elements in ascending order. And the last method will return the end element out of the array - def self.predefined_sort_last_max(*array) - puts "The Max of the following elements #{array} is #{array.sort.last}." - rescue - puts "Error: Please provide number only!" - end +# Sort method will sort the elements in ascending order. Last method will return the end element out of the array +def self.predefined_sort_last_max(*array) + return "The Max of the following elements #{array} is #{array.sort.last}." + rescue + return "Error: Please provide number only!" end # Using find_max # Valid inputs -FindMax.find_max(11, 29, 33) +puts find_max(11, 29, 33) # The Max of the following elements [11, 29, 33] is 33. -FindMax.find_max(-221, -852, -1100, -10) +puts find_max(-221, -852, -1100, -10) # The Max of the following elements [-221, -852, -1100, -10] is -10. # Invalid inputs -FindMax.find_max(5, "95", 2) +puts find_max(5, "95", 2) # Error: Please provide number only! # Using predefined_max # Valid inputs -FindMax.predefined_max(51, 82, 39) +puts predefined_max(51, 82, 39) # The Max of the following elements [51, 82, 39] is 82. -FindMax.predefined_max(-11, -51, -10, -10) +puts predefined_max(-11, -51, -10, -10) # The Max of the following elements [-11, -51, -10, -10] is -10. # Invalid inputs -FindMax.predefined_max("x", 5, 95, 2) +puts predefined_max("x", 5, 95, 2) # Error: Please provide number only! # Using predefined_sort_last_max # Valid inputs -FindMax.predefined_sort_last_max(1, 2, 3) +puts predefined_sort_last_max(1, 2, 3) # The Max of the following elements [1, 2, 3] is 3. -FindMax.predefined_sort_last_max(-21, -52, -100, -1) +puts predefined_sort_last_max(-21, -52, -100, -1) # The Max of the following elements [-21, -52, -100, -1] is -1. # Invalid inputs -FindMax.predefined_sort_last_max(5, 95, 2, "a") +puts predefined_sort_last_max(5, 95, 2, "a") # Error: Please provide number only! From 984477c24c8d59533837e8c7386d073c2cd69b24 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 21 Apr 2021 22:12:10 +0530 Subject: [PATCH 060/121] code cleanup --- maths/find_max.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/maths/find_max.rb b/maths/find_max.rb index f84ba83..ec13cfb 100644 --- a/maths/find_max.rb +++ b/maths/find_max.rb @@ -1,30 +1,30 @@ # A ruby program to find max from a set of elements # This find_max method will return the max element out of the array -def self.find_max(*array) +def find_max(*array) max = array[0] array.each do |a| if a >= max max = a end end - return "The Max of the following elements #{array} is #{max}." + "The Max of the following elements #{array} is #{max}." rescue - return "Error: Please provide number only!" + "Error: Please provide number only!" end # Max method will return the maximum element from the set of input elements provided -def self.predefined_max(*array) - return "The Max of the following elements #{array} is #{array.max}." +def predefined_max(*array) + "The Max of the following elements #{array} is #{array.max}." rescue - return "Error: Please provide number only!" + "Error: Please provide number only!" end # Sort method will sort the elements in ascending order. Last method will return the end element out of the array -def self.predefined_sort_last_max(*array) - return "The Max of the following elements #{array} is #{array.sort.last}." +def predefined_sort_last_max(*array) + "The Max of the following elements #{array} is #{array.sort.last}." rescue - return "Error: Please provide number only!" + "Error: Please provide number only!" end # Using find_max From fb012895154638e262c8d8c4e4210633da0358db Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 21 Apr 2021 23:01:31 +0530 Subject: [PATCH 061/121] find_max -> DIRECTORY implementation --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 8fea99b..b0d0229 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -59,6 +59,7 @@ * [Square Root](https://github.com/TheAlgorithms/Ruby/blob/master/maths/square_root.rb) * [Square Root Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/square_root_test.rb) * [Sum Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/sum_of_digits.rb) + * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) ## Other * [Fisher Yates](https://github.com/TheAlgorithms/Ruby/blob/master/other/fisher_yates.rb) From 9b6a1252e270128d8f470a1c840e9ea9a988543f Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 21 Apr 2021 23:42:10 +0530 Subject: [PATCH 062/121] find_max -> DIRECTORY alphabetical order implementation --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index b0d0229..affe4fd 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -54,12 +54,12 @@ * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) + * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) * [Number Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/number_of_digits.rb) * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/maths/power_of_two.rb) * [Square Root](https://github.com/TheAlgorithms/Ruby/blob/master/maths/square_root.rb) * [Square Root Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/square_root_test.rb) * [Sum Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/sum_of_digits.rb) - * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) ## Other * [Fisher Yates](https://github.com/TheAlgorithms/Ruby/blob/master/other/fisher_yates.rb) From 1ec08e7207b83b3845b711b4ed38991738380f09 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Sat, 24 Apr 2021 01:25:37 +0530 Subject: [PATCH 063/121] find min feature implementation --- DIRECTORY.md | 1 + maths/find_min.rb | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 maths/find_min.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index affe4fd..a110ecb 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -55,6 +55,7 @@ * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) + * [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb) * [Number Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/number_of_digits.rb) * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/maths/power_of_two.rb) * [Square Root](https://github.com/TheAlgorithms/Ruby/blob/master/maths/square_root.rb) diff --git a/maths/find_min.rb b/maths/find_min.rb new file mode 100644 index 0000000..f78e4f4 --- /dev/null +++ b/maths/find_min.rb @@ -0,0 +1,64 @@ +# A ruby program to find min from a set of elements + +# This find_min method will return the min element out of the array +def find_min(*array) + min = array[0] + array.each do |a| + if a <= min + min = a + end + end + "The Min of the following elements #{array} is #{min}." + rescue + "Error: Please provide number only!" +end + +# Min method will return the minimum element from the set of input elements provided +def predefined_min(*array) + "The Min of the following elements #{array} is #{array.min}." + rescue + "Error: Please provide number only!" +end + +# Sort method will sort the elements in ascending order. First method will return the beginning element out of the array +def predefined_sort_first_min(*array) + "The Min of the following elements #{array} is #{array.sort.first}." + rescue + "Error: Please provide number only!" +end + +# Using find_min +# Valid inputs +puts find_min(11, 29, 33) +# The Min of the following elements [11, 29, 33] is 33. + +puts find_min(-221, -852, -1100, -10) +# The Min of the following elements [-221, -852, -1100, -10] is -10. + +# Invalid inputs +puts find_min(5, "95", 2) +# Error: Please provide number only! + +# Using predefined_min +# Valid inputs +puts predefined_min(51, 82, 39) +# The Min of the following elements [51, 82, 39] is 82. + +puts predefined_min(-11, -51, -10, -10) +# The Min of the following elements [-11, -51, -10, -10] is -10. + +# Invalid inputs +puts predefined_min("x", 5, 95, 2) +# Error: Please provide number only! + +# Using predefined_sort_first_min +# Valid inputs +puts predefined_sort_first_min(1, 2, 3) +# The Min of the following elements [1, 2, 3] is 3. + +puts predefined_sort_first_min(-21, -52, -100, -1) +# The Min of the following elements [-21, -52, -100, -1] is -1. + +# Invalid inputs +puts predefined_sort_first_min(5, 95, 2, "a") +# Error: Please provide number only! From 9f7e58c574648fce4bc4e5b9a4af1717df8f4a79 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 24 Apr 2021 23:19:41 -0700 Subject: [PATCH 064/121] Sort color algorhtm --- sorting/sort_color.rb | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 sorting/sort_color.rb diff --git a/sorting/sort_color.rb b/sorting/sort_color.rb new file mode 100644 index 0000000..e1cb3a1 --- /dev/null +++ b/sorting/sort_color.rb @@ -0,0 +1,63 @@ +# Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. +# +# We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. +# +# Example 1: +# +# Input: nums = [2,0,2,1,1,0] +# Output: [0,0,1,1,2,2] +# +# Example 2: +# +# Input: nums = [2,0,1] +# Output: [0,1,2] +# +# Example 3: +# +# Input: nums = [0] +# Output: [0] +# +# Example 4: +# +# Input: nums = [1] +# Output: [1] + +# @param {Integer[]} nums +# @return {Void} Do not return anything, modify nums in-place instead. +def sort_colors(nums) + bubble_sort(nums) +end + +def bubble_sort(array) + array_length = array.size + return array if array_length <= 1 + + loop do + swapped = false + (array_length - 1).times do |i| + if array[i] > array[i + 1] + array[i], array[i + 1] = array[i + 1], array[i] + swapped = true + end + end + break unless swapped + end + + array +end + +nums = [2,0,2,1,1,0] +puts sort_colors(nums) +# Output: [0,0,1,1,2,2] + +nums = [2,0,1] +puts sort_colors(nums) +# Output: [0,1,2] + +nums = [0] +puts sort_colors(nums) +# Output: [0] + +nums = [1] +puts sort_colors(nums) +# Output: [1] From 812a8e42afa4c3c01e5f387b496b4cc7cfc69f35 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 25 Apr 2021 06:19:56 +0000 Subject: [PATCH 065/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index df4f340..59eb222 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -138,4 +138,5 @@ * [Selection Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/selection_sort_test.rb) * [Shell Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/shell_sort.rb) * [Shell Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/shell_sort_test.rb) + * [Sort Color](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/sort_color.rb) * [Sort Tests](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/sort_tests.rb) From 42dafdfe7aec3ada31cb7b2d1aeee562b04c2cd1 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 24 Apr 2021 23:21:08 -0700 Subject: [PATCH 066/121] enter --- sorting/sort_color.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sorting/sort_color.rb b/sorting/sort_color.rb index e1cb3a1..fd428ee 100644 --- a/sorting/sort_color.rb +++ b/sorting/sort_color.rb @@ -34,12 +34,14 @@ def bubble_sort(array) loop do swapped = false + (array_length - 1).times do |i| if array[i] > array[i + 1] array[i], array[i + 1] = array[i + 1], array[i] swapped = true end end + break unless swapped end From fe6d8489c354b2f030b74630b84159f80a50fbc9 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 24 Apr 2021 23:26:02 -0700 Subject: [PATCH 067/121] Fix lint --- sorting/sort_color.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorting/sort_color.rb b/sorting/sort_color.rb index fd428ee..441679e 100644 --- a/sorting/sort_color.rb +++ b/sorting/sort_color.rb @@ -48,11 +48,11 @@ def bubble_sort(array) array end -nums = [2,0,2,1,1,0] +nums = [2, 0, 2, 1, 1, 0] puts sort_colors(nums) # Output: [0,0,1,1,2,2] -nums = [2,0,1] +nums = [2, 0, 1] puts sort_colors(nums) # Output: [0,1,2] From 79ca68d95872f25bb7c2743ac6e32993da779594 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Mon, 26 Apr 2021 13:59:02 -0700 Subject: [PATCH 068/121] Add brute force solution --- data_structures/arrays/sudoku.rb | 178 +++++++++++++++++++++++++++---- 1 file changed, 156 insertions(+), 22 deletions(-) diff --git a/data_structures/arrays/sudoku.rb b/data_structures/arrays/sudoku.rb index cae5d60..2f960a8 100644 --- a/data_structures/arrays/sudoku.rb +++ b/data_structures/arrays/sudoku.rb @@ -9,32 +9,166 @@ # @return {Boolean} # -# Approach 1: -# -# Time Complexity: +# Approach 1: Hash & Brute Force # def is_valid_sudoku(board) + rows = [] + columns = [] + grids = [] + + # make each row into a hash to track for duplicated values + board.each do |row| + row_hash = Hash.new(0) + row.each do |num| + next if num == "." + row_hash[num] += 1 + end + rows << row_hash + end + + # check each row hash for duplicated value + rows.each do |row| + row.each do |k, v| + if v > 1 + return false + end + end + end + + # make each column into a hash to track for duplicated values + (0..8).each do |i| + column_hash = Hash.new(0) + board.each do |row| + next if row[i] == "." + column_hash[row[i]] += 1 + columns << column_hash + end + end + + # check each column hash for duplicated value + columns.each do |column| + column.each do |k, v| + if v > 1 + return false + end + end + end + + # make each 3x3 grid into a hash to track for duplicated values + (0..2).each do |i| + grid_hash = Hash.new(0) + board.first(3).each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + board[3..5].each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + board.each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + end + (3..5).each do |i| + grid_hash = Hash.new(0) + board.first(3).each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + board[3..5].each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + board.each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + end + (6..8).last(3).each do |i| + grid_hash = Hash.new(0) + board.first(3).each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + board[3..5].each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + board.each do |row| + next if row[i] == "." + grid_hash[row[i]] += 1 + grids << grid_hash + end + end + + # check each grid hash for duplicated value + grids.each do |grid| + grid.each do |k, v| + if v > 1 + return false + end + end + end + + true end -board = [["5","3",".",".","7",".",".",".","."] - ,["6",".",".","1","9","5",".",".","."] - ,[".","9","8",".",".",".",".","6","."] - ,["8",".",".",".","6",".",".",".","3"] - ,["4",".",".","8",".","3",".",".","1"] - ,["7",".",".",".","2",".",".",".","6"] - ,[".","6",".",".",".",".","2","8","."] - ,[".",".",".","4","1","9",".",".","5"] - ,[".",".",".",".","8",".",".","7","9"]] +board = [["5","3",".",".","7",".",".",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + ["8",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] print(is_valid_sudoku(board)) # => true -board = [["8","3",".",".","7",".",".",".","."] - ,["6",".",".","1","9","5",".",".","."] - ,[".","9","8",".",".",".",".","6","."] - ,["8",".",".",".","6",".",".",".","3"] - ,["4",".",".","8",".","3",".",".","1"] - ,["7",".",".",".","2",".",".",".","6"] - ,[".","6",".",".",".",".","2","8","."] - ,[".",".",".","4","1","9",".",".","5"] - ,[".",".",".",".","8",".",".","7","9"]] + +board = [["8","3",".",".","7",".",".",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + ["8",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] print(is_valid_sudoku(board)) -# => false \ No newline at end of file +# => false +# explanation: duplicated value in column + +board = [["8","3",".",".","7",".","3",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + ["8",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => false +# explanation: duplicated value in row + +board = [["8","3",".",".","7",".",".",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + [".",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => false +# explanation: duplicated value in 3x3 grid \ No newline at end of file From f96495452962327fb64aca6650c38407d473edc2 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Mon, 26 Apr 2021 13:59:15 -0700 Subject: [PATCH 069/121] Add sets solution --- data_structures/arrays/sudoku.rb | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/data_structures/arrays/sudoku.rb b/data_structures/arrays/sudoku.rb index 2f960a8..9a6b3ae 100644 --- a/data_structures/arrays/sudoku.rb +++ b/data_structures/arrays/sudoku.rb @@ -160,6 +160,124 @@ print(is_valid_sudoku(board)) # => false # explanation: duplicated value in row +board = [["8","3",".",".","7",".",".",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + [".",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => false +# explanation: duplicated value in 3x3 grid + +# +# Approach 2: Sets +# +require 'set' + +def is_valid_sudoku(board) + return false unless check_rows(board) + return false unless check_cols(board) + row = -3 + while (row += 3) < 9 + col = - 3 + while (col += 3) < 9 + start_point = [row, col] + return false unless check_grid(board, start_point) + end + end + true +end + +def check_grid(board, start_point) + row = start_point[0] + col = start_point[1] + ss = Set.new + (row..(row + 2)).each do |cur_row| + (col..(col + 2)).each do |cur_col| + next if board[cur_row][cur_col] == "." + return false if ss.member?(board[cur_row][cur_col]) + ss.add board[cur_row][cur_col] + end + end + true +end + +def check_col(board, col) + ss = Set.new + (0..8).each do |row| + next if board[row][col] == "." + return false if ss.member?(board[row][col]) + ss.add board[row][col] + end + true +end + +def check_row(board, row) + ss = Set.new + (0..8).each do |col| + next if board[row][col] == "." + return false if ss.member?(board[row][col]) + ss.add board[row][col] + end + true +end + +def check_rows(board) + (0..8).each do |row| + return false unless check_row(board, row) + end + true +end + +def check_cols(board) + (0..8).each do |col| + return false unless check_col(board, col) + end + true +end + +board = [["5","3",".",".","7",".",".",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + ["8",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => true + +board = [["8","3",".",".","7",".",".",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + ["8",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => false +# explanation: duplicated value in column + +board = [["8","3",".",".","7",".","3",".","."], + ["6",".",".","1","9","5",".",".","."], + [".","9","8",".",".",".",".","6","."], + ["8",".",".",".","6",".",".",".","3"], + ["4",".",".","8",".","3",".",".","1"], + ["7",".",".",".","2",".",".",".","6"], + [".","6",".",".",".",".","2","8","."], + [".",".",".","4","1","9",".",".","5"], + [".",".",".",".","8",".",".","7","9"]] +print(is_valid_sudoku(board)) +# => false +# explanation: duplicated value in row + board = [["8","3",".",".","7",".",".",".","."], ["6",".",".","1","9","5",".",".","."], [".","9","8",".",".",".",".","6","."], From 010e5ff96a1b4f02aa16306acf3ccf1177747fb9 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Mon, 26 Apr 2021 14:03:15 -0700 Subject: [PATCH 070/121] Added good pairs challenge --- DIRECTORY.md | 1 + data_structures/arrays/good_pairs.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 data_structures/arrays/good_pairs.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index d0c4469..35ed6d8 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -15,6 +15,7 @@ * [Find The Highest Altitude](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/find_the_highest_altitude.rb) * [Fizz Buzz](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/fizz_buzz.rb) * [Get Products Of All Other Elements](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/get_products_of_all_other_elements.rb) + * [Good Pairs](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/good_pairs.rb) * [Remove Elements](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/remove_elements.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/richest_customer_wealth.rb) * [Shuffle Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/shuffle_array.rb) diff --git a/data_structures/arrays/good_pairs.rb b/data_structures/arrays/good_pairs.rb new file mode 100644 index 0000000..354382c --- /dev/null +++ b/data_structures/arrays/good_pairs.rb @@ -0,0 +1,23 @@ +# Challenge name: Number of good pairs +# +# Given an array of integers nums. +# A pair (i,j) is called good if nums[i] == nums[j] and i < j. +# Return the number of good pairs. +# +# @param {Integer[]} nums +# @return {Integer} +# + +def num_identical_pairs(nums) +end +nums = [1, 2, 3, 1, 1, 3] +puts(num_identical_pairs(nums)) +# Output: 4 +# Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed. +nums = [1, 1, 1, 1] +puts(num_identical_pairs(nums)) +# Output: 6 +# Explanation: Each pair in the array are good. +nums = [1, 2, 3] +puts(num_identical_pairs(nums)) +# Output: 0 \ No newline at end of file From cdee13e690250440db00af670671876f67fca917 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 28 Apr 2021 14:07:51 +0530 Subject: [PATCH 071/121] factorial feature implementation --- DIRECTORY.md | 1 + maths/factorial.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 maths/factorial.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index a110ecb..5d68b8d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -53,6 +53,7 @@ * [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb) * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) + * [Factorial](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) * [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb) diff --git a/maths/factorial.rb b/maths/factorial.rb new file mode 100644 index 0000000..ea265df --- /dev/null +++ b/maths/factorial.rb @@ -0,0 +1,39 @@ +# A ruby program to find factorial of a given integer +# Factorial of a given integer is defined as the product of all the positive integers less than or equal to the given integer +# Mathematical representation: n! = n * (n - 1) * (n - 2) * ... * 1 + +def factorial(number) + input = number + factorial = 1 + if number < 0 + "Please check your input number! The given number is a negative number." + else + while number > 0 + factorial *= number + number -= 1 + end + "The factorial of #{input} is #{factorial}." + end + rescue + "Error: Please provide integer only!" +end + +# Valid inputs +puts factorial(0) +# The factorial of 0 is 1. + +puts factorial(10) +# The factorial of 10 is 3628800. + +puts factorial(1) +# The factorial of 1 is 1. + +puts factorial(-5) +# Please check your input number! The given number is a negative number. + +# Invalid inputs +puts factorial("a") +# Error: Please provide integer only! + +puts factorial("2") +# Error: Please provide integer only! From e62c3bbb1190927d663a548bdee72a97de4933c7 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 28 Apr 2021 14:21:01 +0530 Subject: [PATCH 072/121] Revert "factorial feature implementation" This reverts commit cdee13e690250440db00af670671876f67fca917. --- DIRECTORY.md | 1 - maths/factorial.rb | 39 --------------------------------------- 2 files changed, 40 deletions(-) delete mode 100644 maths/factorial.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index 5d68b8d..a110ecb 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -53,7 +53,6 @@ * [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb) * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) - * [Factorial](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) * [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb) diff --git a/maths/factorial.rb b/maths/factorial.rb deleted file mode 100644 index ea265df..0000000 --- a/maths/factorial.rb +++ /dev/null @@ -1,39 +0,0 @@ -# A ruby program to find factorial of a given integer -# Factorial of a given integer is defined as the product of all the positive integers less than or equal to the given integer -# Mathematical representation: n! = n * (n - 1) * (n - 2) * ... * 1 - -def factorial(number) - input = number - factorial = 1 - if number < 0 - "Please check your input number! The given number is a negative number." - else - while number > 0 - factorial *= number - number -= 1 - end - "The factorial of #{input} is #{factorial}." - end - rescue - "Error: Please provide integer only!" -end - -# Valid inputs -puts factorial(0) -# The factorial of 0 is 1. - -puts factorial(10) -# The factorial of 10 is 3628800. - -puts factorial(1) -# The factorial of 1 is 1. - -puts factorial(-5) -# Please check your input number! The given number is a negative number. - -# Invalid inputs -puts factorial("a") -# Error: Please provide integer only! - -puts factorial("2") -# Error: Please provide integer only! From 9434ab9dc92eb3f79726ffa44b89fde1e7cbe47e Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 28 Apr 2021 14:56:40 +0530 Subject: [PATCH 073/121] factorial non-recursive non-iterative feature implementation --- DIRECTORY.md | 1 + .../factorial_non_recursive_non_iterative.rb | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 maths/factorial_non_recursive_non_iterative.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index a110ecb..fa2aaf9 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -53,6 +53,7 @@ * [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb) * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) + * [Factorial Non-recursive and Non-iterative](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial_non_recursive_non_iterative.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) * [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb) diff --git a/maths/factorial_non_recursive_non_iterative.rb b/maths/factorial_non_recursive_non_iterative.rb new file mode 100644 index 0000000..17a4f77 --- /dev/null +++ b/maths/factorial_non_recursive_non_iterative.rb @@ -0,0 +1,44 @@ +# A ruby program to find factorial of a given integer +# Factorial of a given integer is defined as the product of all the positive integers less than or equal to the given integer +# Mathematical representation: n! = n * (n - 1) * (n - 2) * ... * 1 + +# +# Non-recursive approach +# + +def factorial(number) + if number < 0 + "Please check your input number! The given number is a negative number." + else + if number == 0 + "The factorial of #{number} is 1." + else + "The factorial of #{number} is #{(1..number).inject(:*)}." + end + end + rescue + "Error: Please provide integer only!" +end + +# Valid inputs +puts factorial(0) +# The factorial of 0 is 1. + +puts factorial(4) +# The factorial of 4 is 24. + +puts factorial(10) +# The factorial of 10 is 3628800. + +puts factorial(1) +# The factorial of 1 is 1. + +puts factorial(-5) +# Please check your input number! The given number is a negative number. + +# Invalid inputs +puts factorial("a") +# Error: Please provide integer only! + +puts factorial("2") +# Error: Please provide integer only! From 12b8ffd1625a2a53e8b384160938cf47f0108377 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 28 Apr 2021 15:02:48 +0530 Subject: [PATCH 074/121] comments modified --- maths/factorial_non_recursive_non_iterative.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/factorial_non_recursive_non_iterative.rb b/maths/factorial_non_recursive_non_iterative.rb index 17a4f77..f19f4ad 100644 --- a/maths/factorial_non_recursive_non_iterative.rb +++ b/maths/factorial_non_recursive_non_iterative.rb @@ -3,7 +3,7 @@ # Mathematical representation: n! = n * (n - 1) * (n - 2) * ... * 1 # -# Non-recursive approach +# Non-recursive and non-iterative approach # def factorial(number) From 468babecd2ac6f4fad930308225feae88cdab70a Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 29 Apr 2021 01:28:23 +0000 Subject: [PATCH 075/121] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4a674ed..2000051 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -31,7 +31,7 @@ * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) * [Palindrome](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/palindrome.rb) * [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb) - * [Sudoku](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/sudoku.rb) + * [Sudoku](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/sudoku.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb) * [Two Sum Ii](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum_ii.rb) * Binary Trees From 6e70556e397f58783208e20cca18e0b8ed6bbdf2 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 28 Apr 2021 18:33:20 -0700 Subject: [PATCH 076/121] use elsif instead --- maths/factorial_non_recursive_non_iterative.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/maths/factorial_non_recursive_non_iterative.rb b/maths/factorial_non_recursive_non_iterative.rb index f19f4ad..f992a92 100644 --- a/maths/factorial_non_recursive_non_iterative.rb +++ b/maths/factorial_non_recursive_non_iterative.rb @@ -9,12 +9,11 @@ def factorial(number) if number < 0 "Please check your input number! The given number is a negative number." + elsif number == 0 + "The factorial of #{number} is 1." else - if number == 0 - "The factorial of #{number} is 1." - else - "The factorial of #{number} is #{(1..number).inject(:*)}." - end + result = (1..number).inject(:*) + "The factorial of #{number} is #{result}." end rescue "Error: Please provide integer only!" From abcec5f554f9206f94c1453b23e8f47f361f24f4 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 29 Apr 2021 01:34:12 +0000 Subject: [PATCH 077/121] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index b74cec4..4a418b5 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -79,7 +79,7 @@ * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) * [Factorial](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial.rb) - * [Factorial Non-recursive and Non-iterative](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial_non_recursive_non_iterative.rb) + * [Factorial Non Recursive Non Iterative](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial_non_recursive_non_iterative.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) * [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb) From e2c5fbfb4429e75e00b017cf287a100f18837a07 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Thu, 29 Apr 2021 16:36:00 +0530 Subject: [PATCH 078/121] weight conversions feature implementation --- DIRECTORY.md | 1 + conversions/weight_conversions.rb | 99 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 conversions/weight_conversions.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index 3d98259..bf86d5d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -10,6 +10,7 @@ ## Conversions * [Temperature Conversions](https://github.com/TheAlgorithms/Ruby/blob/master/conversions/temperature_conversions.rb) + * [Weight Conversions](https://github.com/TheAlgorithms/Ruby/blob/master/conversions/weight_conversions.rb) ## Data Structures * Arrays diff --git a/conversions/weight_conversions.rb b/conversions/weight_conversions.rb new file mode 100644 index 0000000..aa532b3 --- /dev/null +++ b/conversions/weight_conversions.rb @@ -0,0 +1,99 @@ +# A ruby program for weight conversions + +module WeightConversion + # Kilogram -> Gram = (kilogram_value * 1000) grams + def self.kilogram_to_gram(kilogram_input) + if Integer === kilogram_input + gram = kilogram_input * 1000 + "#{kilogram_input} kg = #{gram} g" + else + raise + end + rescue + "Error: Please provide number only!" + end + + # Gram -> Kilogram = (gram_value / 1000) kilograms + def self.gram_to_kilogram(gram_input) + kilogram = gram_input / 1000 + "#{gram_input} g = #{kilogram} kg" + rescue + "Error: Please provide number only!" + end + + # Pound -> Ounce = (pound_value * 16) oz + def self.pound_to_ounce(pound_input) + if Integer === pound_input + ounce = pound_input * 16 + "#{pound_input} lb = #{ounce} oz" + else + raise + end + rescue + "Error: Please provide number only!" + end + + # Ounce -> Pound = (ounce_value / 16) lb + def self.ounce_to_pound(ounce_input) + if Integer === ounce_input + pound = ounce_input / 16 + "#{ounce_input} oz = #{pound} lb" + else + raise + end + rescue + "Error: Please provide number only!" + end + + # Kilogram -> Pound = (kilogram_input * 2.205) lb + def self.kilogram_to_pound(kilogram_input) + if Integer === kilogram_input + pound = (kilogram_input * 2.205).round(2) + "#{kilogram_input} kg = #{pound} lb" + else + raise + end + rescue + "Error: Please provide number only!" + end + + # Pound -> Kilogram = (pound_input / 2.205) kg + def self.pound_to_kilogram(pound_input) + if Integer === pound_input + kilogram = (pound_input / 2.205).round(2) + "#{pound_input} lb = #{kilogram} kg" + else + raise + end + rescue + "Error: Please provide number only!" + end +end + +# Valid inputs +puts WeightConversion.kilogram_to_gram(2) +# 2 kg = 2000 g +puts WeightConversion.gram_to_kilogram(3000) +# 3000 g = 3 kg +puts WeightConversion.pound_to_ounce(16) +# 16 lb = 256 oz +puts WeightConversion.ounce_to_pound(16) +# 16 oz = 1 lb +puts WeightConversion.kilogram_to_pound(1) +# 1 kg = 2.21 lb +puts WeightConversion.pound_to_kilogram(100) +# 100 lb = 45.35 kg + +# Invalid inputs +puts WeightConversion.kilogram_to_gram("a") +# Error: Please provide number only! +puts WeightConversion.gram_to_kilogram("3000") +# Error: Please provide number only! +puts WeightConversion.pound_to_ounce("16") +# Error: Please provide number only! +puts WeightConversion.ounce_to_pound("x ") +# Error: Please provide number only! +puts WeightConversion.kilogram_to_pound("weight") +# Error: Please provide number only! +puts WeightConversion.pound_to_kilogram("100") +# Error: Please provide number only! From ba2e881edcc70eb868018beb4cb980f4429b9961 Mon Sep 17 00:00:00 2001 From: Vijay Siva Date: Sat, 1 May 2021 12:40:14 -0400 Subject: [PATCH 079/121] Add circular queue --- data_structures/queues/circular_queue.rb | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 data_structures/queues/circular_queue.rb diff --git a/data_structures/queues/circular_queue.rb b/data_structures/queues/circular_queue.rb new file mode 100644 index 0000000..93f26b7 --- /dev/null +++ b/data_structures/queues/circular_queue.rb @@ -0,0 +1,72 @@ +class CircularQueue + def initialize(max_size) + @max_size = max_size + @queue = Array.new(max_size, nil) + @front = 0 + @back = 0 + @size = 0 + end + + attr_accessor :front, :back, :size + attr_reader :max_size, :queue + + def empty? + size == 0 + end + + def peek + return nil if empty? + + queue[front] + end + + def add(x) + raise "Queue is at max capacity" if size == max_size + + + queue[back] = x + @back = (back + 1) % max_size + @size += 1 + end + + def pop + raise "Queue is empty" if size == 0 + + temp = queue[front] + queue[front] = nil + @front = (front + 1) % max_size + @size -= 1 + + temp + end +end + +queue = CircularQueue.new(3) + +begin + queue.pop +rescue => e + puts e.message +end + +queue.add(1) +queue.add(2) +queue.add(3) + +begin + queue.add(4) +rescue => e + puts e.message +end + +puts queue.inspect +# => # + +puts queue.peek +# => 1 + +queue.pop + +puts queue.peek +# => 2 + From b48c1d5479809b1658bae37324e42c25d198f31a Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 1 May 2021 10:28:09 -0700 Subject: [PATCH 080/121] Update data_structures/queues/circular_queue.rb --- data_structures/queues/circular_queue.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/data_structures/queues/circular_queue.rb b/data_structures/queues/circular_queue.rb index 93f26b7..0905ab5 100644 --- a/data_structures/queues/circular_queue.rb +++ b/data_structures/queues/circular_queue.rb @@ -1,3 +1,20 @@ +# Challenge name: Circular Queue +# +# Design the implementation of a circular queue. +# The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and +# the last position is connected back to the first position to make a circle. It is also called "Ring Buffer". +# + +# +# Complexity Analysis +# +# Time complexity: O(1). +# All of the methods in our circular data structure are of constant time complexity. +# +# Space Complexity: O(N). +# The overall space complexity of the data structure is linear, where N is the pre-assigned capacity of the queue. +# However, it is worth mentioning that the memory consumption of the data structure remains as its pre-assigned capacity during its entire life cycle. + class CircularQueue def initialize(max_size) @max_size = max_size @@ -69,4 +86,3 @@ queue.pop puts queue.peek # => 2 - From 2a1e59c362bfa69a45e5a80382ea37a38e94803b Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 1 May 2021 17:33:39 +0000 Subject: [PATCH 081/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4a418b5..15bcf9f 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -50,6 +50,7 @@ * [Doubly Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/doubly_linked_list.rb) * [Singly Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/singly_linked_list.rb) * Queues + * [Circular Queue](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/queues/circular_queue.rb) * [Queue](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/queues/queue.rb) * Stacks * [Stack](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/stacks/stack.rb) From d7f266aa8694a2069b8fe78a60b7c0b9776d3ebd Mon Sep 17 00:00:00 2001 From: Vijay Siva Date: Sat, 1 May 2021 17:38:17 -0400 Subject: [PATCH 082/121] Add bit_manipulation algorithms --- bit_manipulation/binary_and_operator.rb | 22 ++++++ bit_manipulation/binary_count_setbits.rb | 25 +++++++ .../binary_count_trailing_zeroes.rb | 35 +++++++++ bit_manipulation/binary_or_operator.rb | 23 ++++++ bit_manipulation/binary_xor_operator.rb | 43 +++++++++++ .../single_bit_binary_operations.rb | 71 +++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 bit_manipulation/binary_and_operator.rb create mode 100644 bit_manipulation/binary_count_setbits.rb create mode 100644 bit_manipulation/binary_count_trailing_zeroes.rb create mode 100644 bit_manipulation/binary_or_operator.rb create mode 100644 bit_manipulation/binary_xor_operator.rb create mode 100644 bit_manipulation/single_bit_binary_operations.rb diff --git a/bit_manipulation/binary_and_operator.rb b/bit_manipulation/binary_and_operator.rb new file mode 100644 index 0000000..be0acce --- /dev/null +++ b/bit_manipulation/binary_and_operator.rb @@ -0,0 +1,22 @@ +def binary_and(x, y) + raise 'Input must only contain positive integers' if x < 0 or x < 0 + + "0b" + (x & y).to_s(2) +end + +begin + binary_and(-1, 0) +rescue => e + puts e.message +end + +puts binary_and(1, 1) +# 0b1 +puts binary_and(0, 1) +# 0b0 +puts binary_and(1024, 1024) +# 0b10000000000 +puts binary_and(0, 1023) +# 0b0000000000 +puts binary_and(16, 58) +# 0b010000 diff --git a/bit_manipulation/binary_count_setbits.rb b/bit_manipulation/binary_count_setbits.rb new file mode 100644 index 0000000..3b33138 --- /dev/null +++ b/bit_manipulation/binary_count_setbits.rb @@ -0,0 +1,25 @@ +def binary_count_setbits(x) + raise 'Input must be a positive integer' if x < 0 + + binary = x.to_s(2) + + binary.chars.map { |c| c.to_i }.reduce(:+) +end + +begin + binary_count_setbits(-1) +rescue => e + puts e.message +end + +puts binary_count_setbits(0) +# 0 + +puts binary_count_setbits(1) +# 1 + +puts binary_count_setbits(1024) +# 1 + +puts binary_count_setbits(1023) +# 10 diff --git a/bit_manipulation/binary_count_trailing_zeroes.rb b/bit_manipulation/binary_count_trailing_zeroes.rb new file mode 100644 index 0000000..03abe1d --- /dev/null +++ b/bit_manipulation/binary_count_trailing_zeroes.rb @@ -0,0 +1,35 @@ +def binary_count_trailing_zeroes(x) + raise 'Input must be a positive integer' if x < 0 + + binary = x.to_s(2) + + count = 0 + binary.chars.reverse_each do |char| + break if char == "1" + + count += 1 + end + + count +end + +begin + binary_count_trailing_zeroes(-1) +rescue => e + puts e.message +end + +puts binary_count_trailing_zeroes(0) +# 1 + +puts binary_count_trailing_zeroes(1023) +# 0 + +puts binary_count_trailing_zeroes(1024) +# 10 + +puts binary_count_trailing_zeroes(54) +# 1 + +puts binary_count_trailing_zeroes(121024) +# 6 diff --git a/bit_manipulation/binary_or_operator.rb b/bit_manipulation/binary_or_operator.rb new file mode 100644 index 0000000..4b826cc --- /dev/null +++ b/bit_manipulation/binary_or_operator.rb @@ -0,0 +1,23 @@ +def binary_or(x, y) + raise 'Input must only contain positive integers' if x < 0 or y < 0 + + "0b" + (x | y).to_s(2) +end + +begin + binary_or(-1, 0) +rescue => e + puts e.message +end + +puts binary_or(1, 1) +# 0b1 +puts binary_or(0, 1) +# 0b1 +puts binary_or(1024, 1024) +# 0b10000000000 +puts binary_or(0, 1023) +# 0b1111111111 +puts binary_or(16, 58) +# 0b110010 + diff --git a/bit_manipulation/binary_xor_operator.rb b/bit_manipulation/binary_xor_operator.rb new file mode 100644 index 0000000..e939bfc --- /dev/null +++ b/bit_manipulation/binary_xor_operator.rb @@ -0,0 +1,43 @@ +def binary_xor(x, y) + raise 'Input must only contain positive integers' if x < 0 or y < 0 + + binary_x = x.to_s(2) + binary_y = y.to_s(2) + + if binary_x.length > binary_y.length + prefix = "0" * (binary_x.length - binary_y.length) + binary_y = prefix + binary_y + elsif binary_y.length > binary_x.length + prefix = "0" * (binary_y.length - binary_x.length) + binary_x = prefix + binary_x + end + result = "0b" + binary_x.each_char.with_index do |x_char, i| + y_char = binary_y[i] + + if (x_char == "1" && y_char != "1") || (x_char != "1" && y_char == "1") + result += "1" + else + result += "0" + end + end + + result +end + +begin + binary_xor(-1, 0) +rescue => e + puts e.message +end + +puts binary_xor(1, 1) +# 0b0 +puts binary_xor(0, 1) +# 0b1 +puts binary_xor(1024, 1024) +# 0b00000000000 +puts binary_xor(0, 1023) +# 0b1111111111 +puts binary_xor(16, 58) +# 0b101010 diff --git a/bit_manipulation/single_bit_binary_operations.rb b/bit_manipulation/single_bit_binary_operations.rb new file mode 100644 index 0000000..a8b5c45 --- /dev/null +++ b/bit_manipulation/single_bit_binary_operations.rb @@ -0,0 +1,71 @@ +def set_bit(x, position) + raise "position must be >= 0" if position < 0 + + x | (1 << position) +end + +puts set_bit(0, 0) +# 1 + +puts set_bit(0, 4) +# 16 + +puts set_bit(8, 3) +# 8 + +puts set_bit(8, 4) +# 24 + +def clear_bit(x, position) + raise "position must be > 0" if position < 0 + + x & ~(1 << position) +end + +puts clear_bit(0, 0) +# 0 + +puts clear_bit(0, 4) +# 0 + +puts clear_bit(8, 3) +# 0 + +puts clear_bit(24, 4) +# 8 + +def flip_bit(x, position) + raise "position must be > 0" if position < 0 + + x ^ (1 << position) +end + +puts flip_bit(0, 0) +# 1 + +puts flip_bit(0, 4) +# 16 + +puts flip_bit(8, 3) +# 0 + +puts flip_bit(24, 4) +# 8 + +def is_bit_set(x, position) + raise "position must be > 0" if position < 0 + + ((x >> position) & 1) == 1 +end + +puts is_bit_set(0, 0) +# false + +puts is_bit_set(1, 0) +# true + +puts is_bit_set(8, 3) +# true + +puts is_bit_set(24, 4) +# true From 170f90d1310343615b411b14afeef5265effa069 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 1 May 2021 19:40:07 -0700 Subject: [PATCH 083/121] move error handling to the bottom --- conversions/weight_conversions.rb | 108 +++++++++++++++--------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/conversions/weight_conversions.rb b/conversions/weight_conversions.rb index aa532b3..452d932 100644 --- a/conversions/weight_conversions.rb +++ b/conversions/weight_conversions.rb @@ -3,70 +3,47 @@ module WeightConversion # Kilogram -> Gram = (kilogram_value * 1000) grams def self.kilogram_to_gram(kilogram_input) - if Integer === kilogram_input - gram = kilogram_input * 1000 - "#{kilogram_input} kg = #{gram} g" - else - raise - end - rescue - "Error: Please provide number only!" + raise StandardError unless Integer === kilogram_input + + gram = kilogram_input * 1000 + "#{kilogram_input} kg = #{gram} g" end # Gram -> Kilogram = (gram_value / 1000) kilograms def self.gram_to_kilogram(gram_input) kilogram = gram_input / 1000 + "#{gram_input} g = #{kilogram} kg" - rescue - "Error: Please provide number only!" end # Pound -> Ounce = (pound_value * 16) oz def self.pound_to_ounce(pound_input) - if Integer === pound_input - ounce = pound_input * 16 - "#{pound_input} lb = #{ounce} oz" - else - raise - end - rescue - "Error: Please provide number only!" + ounce = pound_input * 16 + + "#{pound_input} lb = #{ounce} oz" end # Ounce -> Pound = (ounce_value / 16) lb def self.ounce_to_pound(ounce_input) - if Integer === ounce_input - pound = ounce_input / 16 - "#{ounce_input} oz = #{pound} lb" - else - raise - end - rescue - "Error: Please provide number only!" + pound = ounce_input / 16 + + "#{ounce_input} oz = #{pound} lb" end # Kilogram -> Pound = (kilogram_input * 2.205) lb def self.kilogram_to_pound(kilogram_input) - if Integer === kilogram_input - pound = (kilogram_input * 2.205).round(2) - "#{kilogram_input} kg = #{pound} lb" - else - raise - end - rescue - "Error: Please provide number only!" + pound = (kilogram_input * 2.205).round(2) + + "#{kilogram_input} kg = #{pound} lb" end # Pound -> Kilogram = (pound_input / 2.205) kg def self.pound_to_kilogram(pound_input) - if Integer === pound_input - kilogram = (pound_input / 2.205).round(2) - "#{pound_input} lb = #{kilogram} kg" - else - raise - end - rescue - "Error: Please provide number only!" + raise StandardError unless Integer === pound_input + + kilogram = (pound_input / 2.205).round(2) + + "#{pound_input} lb = #{kilogram} kg" end end @@ -85,15 +62,38 @@ puts WeightConversion.pound_to_kilogram(100) # 100 lb = 45.35 kg # Invalid inputs -puts WeightConversion.kilogram_to_gram("a") -# Error: Please provide number only! -puts WeightConversion.gram_to_kilogram("3000") -# Error: Please provide number only! -puts WeightConversion.pound_to_ounce("16") -# Error: Please provide number only! -puts WeightConversion.ounce_to_pound("x ") -# Error: Please provide number only! -puts WeightConversion.kilogram_to_pound("weight") -# Error: Please provide number only! -puts WeightConversion.pound_to_kilogram("100") -# Error: Please provide number only! +begin + puts WeightConversion.kilogram_to_gram("a") +rescue StandardError + puts "Error: Please provide number only!" +end + +begin + puts WeightConversion.kilogram_to_gram("3000") +rescue StandardError + puts "Error: Please provide number only!" +end + +begin + puts WeightConversion.kilogram_to_gram("16") +rescue StandardError + puts "Error: Please provide number only!" +end + +begin + puts WeightConversion.kilogram_to_gram("x ") +rescue StandardError + puts "Error: Please provide number only!" +end + +begin + puts WeightConversion.kilogram_to_gram("weight") +rescue StandardError + puts "Error: Please provide number only!" +end + +begin + puts WeightConversion.kilogram_to_gram("100") +rescue StandardError + puts "Error: Please provide number only!" +end From 66672b66ab9b3e538b2c4aa8a6025c8327420f4b Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 1 May 2021 19:40:57 -0700 Subject: [PATCH 084/121] minor changes --- conversions/weight_conversions.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/conversions/weight_conversions.rb b/conversions/weight_conversions.rb index 452d932..72f40a5 100644 --- a/conversions/weight_conversions.rb +++ b/conversions/weight_conversions.rb @@ -6,6 +6,7 @@ module WeightConversion raise StandardError unless Integer === kilogram_input gram = kilogram_input * 1000 + "#{kilogram_input} kg = #{gram} g" end @@ -46,8 +47,10 @@ module WeightConversion "#{pound_input} lb = #{kilogram} kg" end end - +# # Valid inputs +# + puts WeightConversion.kilogram_to_gram(2) # 2 kg = 2000 g puts WeightConversion.gram_to_kilogram(3000) @@ -61,7 +64,10 @@ puts WeightConversion.kilogram_to_pound(1) puts WeightConversion.pound_to_kilogram(100) # 100 lb = 45.35 kg +# # Invalid inputs +# + begin puts WeightConversion.kilogram_to_gram("a") rescue StandardError From fa96729b7250dc592b47b717d4fdd9366bdc87cd Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 1 May 2021 19:42:04 -0700 Subject: [PATCH 085/121] Update weight_conversions.rb --- conversions/weight_conversions.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/conversions/weight_conversions.rb b/conversions/weight_conversions.rb index 72f40a5..e1f86f1 100644 --- a/conversions/weight_conversions.rb +++ b/conversions/weight_conversions.rb @@ -47,6 +47,7 @@ module WeightConversion "#{pound_input} lb = #{kilogram} kg" end end + # # Valid inputs # From c78639dddec81504e21dce0e14f2d67358858cc1 Mon Sep 17 00:00:00 2001 From: Vijay Siva Date: Sun, 2 May 2021 11:49:20 -0400 Subject: [PATCH 086/121] add comments on output for the error cases --- bit_manipulation/binary_and_operator.rb | 3 +- bit_manipulation/binary_count_setbits.rb | 1 + .../binary_count_trailing_zeroes.rb | 1 + bit_manipulation/binary_or_operator.rb | 1 + bit_manipulation/binary_xor_operator.rb | 1 + .../single_bit_binary_operations.rb | 29 +++++++++++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/bit_manipulation/binary_and_operator.rb b/bit_manipulation/binary_and_operator.rb index be0acce..4cc0f5a 100644 --- a/bit_manipulation/binary_and_operator.rb +++ b/bit_manipulation/binary_and_operator.rb @@ -1,5 +1,5 @@ def binary_and(x, y) - raise 'Input must only contain positive integers' if x < 0 or x < 0 + raise 'Input must only contain positive integers' if x < 0 or y < 0 "0b" + (x & y).to_s(2) end @@ -9,6 +9,7 @@ begin rescue => e puts e.message end +# Input must only contain positive integers puts binary_and(1, 1) # 0b1 diff --git a/bit_manipulation/binary_count_setbits.rb b/bit_manipulation/binary_count_setbits.rb index 3b33138..4deab5a 100644 --- a/bit_manipulation/binary_count_setbits.rb +++ b/bit_manipulation/binary_count_setbits.rb @@ -11,6 +11,7 @@ begin rescue => e puts e.message end +# Input must be a positive integer puts binary_count_setbits(0) # 0 diff --git a/bit_manipulation/binary_count_trailing_zeroes.rb b/bit_manipulation/binary_count_trailing_zeroes.rb index 03abe1d..40eafad 100644 --- a/bit_manipulation/binary_count_trailing_zeroes.rb +++ b/bit_manipulation/binary_count_trailing_zeroes.rb @@ -18,6 +18,7 @@ begin rescue => e puts e.message end +# Input must be a positive integer puts binary_count_trailing_zeroes(0) # 1 diff --git a/bit_manipulation/binary_or_operator.rb b/bit_manipulation/binary_or_operator.rb index 4b826cc..43758b7 100644 --- a/bit_manipulation/binary_or_operator.rb +++ b/bit_manipulation/binary_or_operator.rb @@ -9,6 +9,7 @@ begin rescue => e puts e.message end +# Input must only contain positive integers puts binary_or(1, 1) # 0b1 diff --git a/bit_manipulation/binary_xor_operator.rb b/bit_manipulation/binary_xor_operator.rb index e939bfc..634e8df 100644 --- a/bit_manipulation/binary_xor_operator.rb +++ b/bit_manipulation/binary_xor_operator.rb @@ -30,6 +30,7 @@ begin rescue => e puts e.message end +# Input must only contain positive integers puts binary_xor(1, 1) # 0b0 diff --git a/bit_manipulation/single_bit_binary_operations.rb b/bit_manipulation/single_bit_binary_operations.rb index a8b5c45..b7da58e 100644 --- a/bit_manipulation/single_bit_binary_operations.rb +++ b/bit_manipulation/single_bit_binary_operations.rb @@ -16,6 +16,14 @@ puts set_bit(8, 3) puts set_bit(8, 4) # 24 +begin + puts set_bit(8, -4) +rescue => e + puts e.message +end +# position must be >= 0 + + def clear_bit(x, position) raise "position must be > 0" if position < 0 @@ -34,6 +42,13 @@ puts clear_bit(8, 3) puts clear_bit(24, 4) # 8 +begin + puts clear_bit(0, -4) +rescue => e + puts e.message +end +# position must be > 0 + def flip_bit(x, position) raise "position must be > 0" if position < 0 @@ -52,6 +67,13 @@ puts flip_bit(8, 3) puts flip_bit(24, 4) # 8 +begin + puts flip_bit(0, -4) +rescue => e + puts e.message +end +# position must be > 0 + def is_bit_set(x, position) raise "position must be > 0" if position < 0 @@ -69,3 +91,10 @@ puts is_bit_set(8, 3) puts is_bit_set(24, 4) # true + +begin + puts is_bit_set(0, -4) +rescue => e + puts e.message +end +# position must be > 0 From 8c26fd3dd189e27d3ce68d915400af3656e168c5 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 2 May 2021 15:51:26 +0000 Subject: [PATCH 087/121] updating DIRECTORY.md --- DIRECTORY.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index b3a7072..d91e56d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -3,7 +3,13 @@ * [Generate Paranthesis](https://github.com/TheAlgorithms/Ruby/blob/master/backtracking/generate_paranthesis.rb) ## Bit Manipulation + * [Binary And Operator](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/binary_and_operator.rb) + * [Binary Count Setbits](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/binary_count_setbits.rb) + * [Binary Count Trailing Zeroes](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/binary_count_trailing_zeroes.rb) + * [Binary Or Operator](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/binary_or_operator.rb) + * [Binary Xor Operator](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/binary_xor_operator.rb) * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/power_of_two.rb) + * [Single Bit Binary Operations](https://github.com/TheAlgorithms/Ruby/blob/master/bit_manipulation/single_bit_binary_operations.rb) ## Ciphers * [Merkle Hellman Cryptosystem](https://github.com/TheAlgorithms/Ruby/blob/master/ciphers/merkle_hellman_cryptosystem.rb) From 1f776fde12738be24e3f3dfe12108f136d5a6a7e Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Tue, 4 May 2021 07:45:50 -0700 Subject: [PATCH 088/121] Roman to Integer --- maths/roman_to_integer.rb | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 maths/roman_to_integer.rb diff --git a/maths/roman_to_integer.rb b/maths/roman_to_integer.rb new file mode 100644 index 0000000..c2f2d3d --- /dev/null +++ b/maths/roman_to_integer.rb @@ -0,0 +1,96 @@ +# Challenge name: Roman to Integer +# +# Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. +# +# Symbol Value +# I 1 +# V 5 +# X 10 +# L 50 +# C 100 +# D 500 +# M 1000 +# +# For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. +# +# Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used: +# +# I can be placed before V (5) and X (10) to make 4 and 9. +# X can be placed before L (50) and C (100) to make 40 and 90. +# C can be placed before D (500) and M (1000) to make 400 and 900. +# Given a roman numeral, convert it to an integer. +# +# + +# Approach 1: Left-to-Right Pass +# + +# Complexity Analysis +# +# Let n be the length of the input string (the total number of symbols in it). +# +# Time complexity: O(1). +# As there is a finite set of roman numerals. +# +# Space complexity: O(1). +# Because only a constant number of single-value variables are used, the space complexity is O(1). + +ROM_NUMS = { + "I" => 1, + "V" => 5, + "X" => 10, + "L" => 50, + "C" => 100, + "D" => 500, + "M" => 1000 +} + +# Now, recall that each symbol adds its own value, except for when a smaller +# valued symbol is before a larger valued symbol. In those cases, instead of +# adding both symbols to the total, we need to subtract the large from the +# small, adding that instead. + +# Therefore, the simplest algorithm is to use a pointer to scan through the +# string, at each step deciding whether to add the current symbol and +# go forward 1 place, or add the difference of the next 2 symbols and +# go forward 2 places. + +def roman_to_int(s) + res = 0 + temp = 0 + + s.chars.each_with_index do |el, i| + # subtractive case: if at least 2 symbols remaining AND value of s[i] < value of s[i + 1] + if ROM_NUMS[s[i + 1]] && ROM_NUMS[el] < ROM_NUMS[s[i+1]] + temp = ROM_NUMS[el] + else + # Else this is NOT the subtractive case. + res += (ROM_NUMS[el] - temp) + temp = 0 + end + end + + res +end + +s = "III" +puts roman_to_int(s) +# Output: 3 + +s = "IV" +puts roman_to_int(s) +# Output: 4 + +s = "IX" +puts roman_to_int(s) +# Output: 9 + +s = "LVIII" +puts roman_to_int(s) +# Output: 58 +# Explanation: L = 50, V= 5, III = 3. + +s = "MCMXCIV" +puts roman_to_int(s) +# Output: 1994 +# Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. From 9cc2e087c6801604cf303853efe3972521aa99a5 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 4 May 2021 14:46:10 +0000 Subject: [PATCH 089/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 15bcf9f..cd81998 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -87,6 +87,7 @@ * [Number Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/number_of_digits.rb) * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/maths/power_of_two.rb) * [Prime Number](https://github.com/TheAlgorithms/Ruby/blob/master/maths/prime_number.rb) + * [Roman To Integer](https://github.com/TheAlgorithms/Ruby/blob/master/maths/roman_to_integer.rb) * [Square Root](https://github.com/TheAlgorithms/Ruby/blob/master/maths/square_root.rb) * [Square Root Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/square_root_test.rb) * [Sum Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/sum_of_digits.rb) From 7623e08e488ca904afaa7997a4c867550154c399 Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 5 May 2021 13:58:43 -0300 Subject: [PATCH 090/121] add shortest word distance algorithm --- .../arrays/shortest_word_distance.rb | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data_structures/arrays/shortest_word_distance.rb diff --git a/data_structures/arrays/shortest_word_distance.rb b/data_structures/arrays/shortest_word_distance.rb new file mode 100644 index 0000000..6bf1697 --- /dev/null +++ b/data_structures/arrays/shortest_word_distance.rb @@ -0,0 +1,33 @@ +# Shortest Word Distance +# Given a list of words and two words word1 and word2, +# return the shortest distance between these two words in the list. +# @param {String[]} words +# @param {String} word1 +# @param {String} word2 +# @return {Integer} + +def shortest_distance(words, word1, word2) + return 0 if word1 == word2 + return 0 unless words.include?(word1) && words.include?(word2) + + minimum_distance = words.length + words.each_with_index do |outer_value, outer_index| + words.each_with_index do |inner_value, inner_index| + if ((inner_value == word1 && outer_value == word2) || (inner_value == word2 && outer_value == word1)) && (minimum_distance > (outer_index - inner_index).abs) + minimum_distance = (outer_index - inner_index).abs + end + end + end + minimum_distance +end + +words = %w[practice makes perfect coding makes] +word1 = 'coding' +word2 = 'practice' +puts(shortest_distance(words, word1, word2)) +# Output: 3 +words = %w[practice makes perfect coding makes] +word1 = 'makes' +word2 = 'coding' +puts(shortest_distance(words, word1, word2)) +# Output: 1 From 1baf4565fb3e06a2c9d1bdabd1c043194889319c Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 5 May 2021 23:18:30 +0000 Subject: [PATCH 091/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index b9b77a3..3b1eba2 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -29,6 +29,7 @@ * [Next Greater Element](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/next_greater_element.rb) * [Remove Elements](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/remove_elements.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/richest_customer_wealth.rb) + * [Shortest Word Distance](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/shortest_word_distance.rb) * [Shuffle Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/shuffle_array.rb) * [Single Number](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/single_number.rb) * [Sort Squares Of An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/sort_squares_of_an_array.rb) From cb35d346fd6c7b479311141a0f01039af6f60ed3 Mon Sep 17 00:00:00 2001 From: maxbarsukov Date: Thu, 6 May 2021 10:13:25 +0300 Subject: [PATCH 092/121] Several sorts added --- DIRECTORY.md | 8 ++++++++ sorting/bead_sort.rb | 24 ++++++++++++++++++++++++ sorting/bead_sort_test.rb | 11 +++++++++++ sorting/cocktail_sort.rb | 24 ++++++++++++++++++++++++ sorting/cocktail_sort_test.rb | 12 ++++++++++++ sorting/comb_sort.rb | 22 ++++++++++++++++++++++ sorting/comb_sort_test.rb | 11 +++++++++++ sorting/pancake_sort.rb | 18 ++++++++++++++++++ sorting/pancake_sort_test.rb | 11 +++++++++++ 9 files changed, 141 insertions(+) create mode 100644 sorting/bead_sort.rb create mode 100644 sorting/bead_sort_test.rb create mode 100644 sorting/cocktail_sort.rb create mode 100644 sorting/cocktail_sort_test.rb create mode 100644 sorting/comb_sort.rb create mode 100644 sorting/comb_sort_test.rb create mode 100644 sorting/pancake_sort.rb create mode 100644 sorting/pancake_sort_test.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index 3b1eba2..5450a1d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -134,18 +134,26 @@ * [Ternary Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/ternary_search.rb) ## Sorting + * [Bead Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bead_sort.rb) + * [Bead Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bead_sort_test.rb) * [Bogo Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bogo_sort.rb) * [Bogo Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bogo_sort_test.rb) * [Bubble Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb) * [Bubble Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort_test.rb) * [Bucket Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bucket_sort.rb) * [Bucket Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bucket_sort_test.rb) + * [Cocktail Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/cocktail_sort.rb) + * [Cocktail Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/cocktail_sort_test.rb) + * [Comb Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/comb_sort.rb) + * [Comb Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/comb_sort_test.rb) * [Heap Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort.rb) * [Heap Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort_test.rb) * [Insertion Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/insertion_sort.rb) * [Insertion Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/insertion_sort_test.rb) * [Merge Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/merge_sort.rb) * [Merge Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/merge_sort_test.rb) + * [Pancake Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/pancake_sort.rb) + * [Pancake Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/pancake_sort_test.rb) * [Quicksort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/quicksort.rb) * [Quicksort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/quicksort_test.rb) * [Radix Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/radix_sort.rb) diff --git a/sorting/bead_sort.rb b/sorting/bead_sort.rb new file mode 100644 index 0000000..e7f5f5f --- /dev/null +++ b/sorting/bead_sort.rb @@ -0,0 +1,24 @@ +class Array + def columns + x = map(&:length).max + Array.new(x) do |row| + Array.new(length) { |column| self[column][row] }.compact + end + end +end + +def bead_sort(array) + array + .map { |element| [1] * element } + .columns + .columns + .map(&:length) + .reverse +end + +if $0 == __FILE__ + puts 'Enter a list of numbers separated by space' + + list = gets.split.map(&:to_i) + p bead_sort(list) +end diff --git a/sorting/bead_sort_test.rb b/sorting/bead_sort_test.rb new file mode 100644 index 0000000..93bf030 --- /dev/null +++ b/sorting/bead_sort_test.rb @@ -0,0 +1,11 @@ +require 'minitest/autorun' +require_relative './sort_tests' +require_relative './bead_sort' + +class TestInsertionSort < Minitest::Test + include SortTests + + def sort(input) + bead_sort(input) + end +end diff --git a/sorting/cocktail_sort.rb b/sorting/cocktail_sort.rb new file mode 100644 index 0000000..fd83d23 --- /dev/null +++ b/sorting/cocktail_sort.rb @@ -0,0 +1,24 @@ +def cocktail_sort(array) + start = 0 + finish = array.length - 1 + way = 1 + loop do + swapped = false + start.step(finish - way, way) do |i| + if (array[i] <=> array[i + way]) == way + array[i], array[i + way] = array[i + way], array[i] + swapped = i + end + end + break unless swapped + start, finish, way = swapped, start, -way + end + array +end + +if $0 == __FILE__ + puts 'Enter a list of numbers separated by space' + + list = gets.split.map(&:to_i) + p cocktail_sort(list) +end diff --git a/sorting/cocktail_sort_test.rb b/sorting/cocktail_sort_test.rb new file mode 100644 index 0000000..ce669ba --- /dev/null +++ b/sorting/cocktail_sort_test.rb @@ -0,0 +1,12 @@ +require 'minitest/autorun' +require_relative './sort_tests' +require_relative './cocktail_sort' + +class TestInsertionSort < Minitest::Test + include SortTests + + def sort(input) + cocktail_sort(input) + end +end + diff --git a/sorting/comb_sort.rb b/sorting/comb_sort.rb new file mode 100644 index 0000000..3cb20ea --- /dev/null +++ b/sorting/comb_sort.rb @@ -0,0 +1,22 @@ +def comb_sort(array) + gap = array.length + swaps = true + while gap > 1 or swaps + gap = [1, (gap / 1.25).to_i].max + swaps = false + 0.upto(array.length - gap - 1) do |i| + if array[i] > array[i + gap] + array[i], array[i + gap] = array[i + gap], array[i] + swaps = true + end + end + end + array +end + +if $0 == __FILE__ + puts 'Enter a list of numbers separated by space' + + list = gets.split.map(&:to_i) + p insertion_sort(list) +end diff --git a/sorting/comb_sort_test.rb b/sorting/comb_sort_test.rb new file mode 100644 index 0000000..cedfbb6 --- /dev/null +++ b/sorting/comb_sort_test.rb @@ -0,0 +1,11 @@ +require 'minitest/autorun' +require_relative './sort_tests' +require_relative './comb_sort' + +class TestInsertionSort < Minitest::Test + include SortTests + + def sort(input) + comb_sort(input) + end +end diff --git a/sorting/pancake_sort.rb b/sorting/pancake_sort.rb new file mode 100644 index 0000000..3f07e0f --- /dev/null +++ b/sorting/pancake_sort.rb @@ -0,0 +1,18 @@ +def pancake_sort(array) + return array if array.length <= 1 + (array.length - 1).downto(1) do |index| + max_index = array[0..index].index(array[0..index].max) + next if max_index == index + + array[0..max_index] = array[0..max_index].reverse if max_index > 0 + array[0..index] = array[0..index].reverse + end + array +end + +if $0 == __FILE__ + puts 'Enter a list of numbers separated by space' + + list = gets.split.map(&:to_i) + p pancake_sort(list) +end diff --git a/sorting/pancake_sort_test.rb b/sorting/pancake_sort_test.rb new file mode 100644 index 0000000..bcebfc3 --- /dev/null +++ b/sorting/pancake_sort_test.rb @@ -0,0 +1,11 @@ +require 'minitest/autorun' +require_relative './sort_tests' +require_relative './pancake_sort' + +class TestInsertionSort < Minitest::Test + include SortTests + + def sort(input) + pancake_sort(input) + end +end From 2ea39679fc47a44e2e1f7d56eb18bbe65e66d45e Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Fri, 7 May 2021 20:14:06 +0530 Subject: [PATCH 093/121] armstrong number feature implementation --- DIRECTORY.md | 1 + maths/armstrong_number.rb | 57 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 maths/armstrong_number.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index bf86d5d..4c2cb0a 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -72,6 +72,7 @@ * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add_digits.rb) * [Aliquot Sum](https://github.com/TheAlgorithms/Ruby/blob/master/maths/aliquot_sum.rb) * [Aliquot Sum Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/aliquot_sum_test.rb) + * [Armstrong Number](https://github.com/TheAlgorithms/Ruby/blob/master/maths/armstrong_number.rb) * [Average Mean](https://github.com/TheAlgorithms/Ruby/blob/master/maths/average_mean.rb) * [Average Median](https://github.com/TheAlgorithms/Ruby/blob/master/maths/average_median.rb) * [Binary To Decimal](https://github.com/TheAlgorithms/Ruby/blob/master/maths/binary_to_decimal.rb) diff --git a/maths/armstrong_number.rb b/maths/armstrong_number.rb new file mode 100644 index 0000000..36aed4e --- /dev/null +++ b/maths/armstrong_number.rb @@ -0,0 +1,57 @@ +# A ruby program to find a given number is armstrong number or not +# Wiki url: https://en.wikipedia.org/wiki/Narcissistic_number +# other resources: https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/arms.html + +# +# Examples: -> 153 = (1 * 1 * 1) + (5 * 5 * 5) + (3 * 3 * 3) [Armstrong number] and -> 125 != (1 * 1 * 1) + (2 * 2 * 2) + (5 * 5 * 5) +# -> 1634 = (1 * 1 * 1 * 1) + (6 * 6 * 6 * 6) + (3 * 3 * 3 * 3) + (4 * 4 * 4 * 4) +# + +def armstrong_number(number) + num = number + sum = 0 + len = number.digits.count + while(number != 0) + remainder = number % 10 + sum += remainder ** len + number /= 10 + end + + if num == sum + "The number #{num} is an Armstrong number." + else + "The number #{num} is not an Armstrong number." + end + rescue + "Error: Please provide number only!" +end + +# +# Valid inputs +# +puts armstrong_number(153) +# The number 153 is an Armstrong number. + +puts armstrong_number(0) +# The number 0 is an Armstrong number. + +puts armstrong_number(370) +# The number 370 is an Armstrong number. + +puts armstrong_number(10) +# The number 10 is not an Armstrong number. + +puts armstrong_number(1634) +# The number 1634 is an Armstrong number. + +puts armstrong_number(123) +# The number 123 is not an Armstrong number. + +# +# Invalid inputs +# +puts armstrong_number("153") +# Error: Please provide number only! + +puts armstrong_number("a") +# Error: Please provide number only! From da897fe6ad83cf785dd52a4e94cc9a2f0d9dd6f7 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 7 May 2021 16:37:58 -0700 Subject: [PATCH 094/121] Add brute force approach --- data_structures/arrays/good_pairs.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/data_structures/arrays/good_pairs.rb b/data_structures/arrays/good_pairs.rb index 354382c..662b1aa 100644 --- a/data_structures/arrays/good_pairs.rb +++ b/data_structures/arrays/good_pairs.rb @@ -8,16 +8,35 @@ # @return {Integer} # +# +# Approach 1: Brute Force +# +# Time Complexity: O(n^2) +# def num_identical_pairs(nums) + count = 0 + nums.each_with_index do |num, i| + target = num + nums.each_with_index do |num, j| + next if i >= j + if num == target + count += 1 + end + end + end + count end + nums = [1, 2, 3, 1, 1, 3] puts(num_identical_pairs(nums)) # Output: 4 # Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed. + nums = [1, 1, 1, 1] puts(num_identical_pairs(nums)) # Output: 6 # Explanation: Each pair in the array are good. + nums = [1, 2, 3] puts(num_identical_pairs(nums)) # Output: 0 \ No newline at end of file From cdc053662d8553bf8332ab8be2cdb5c44146f922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Mon, 10 May 2021 18:24:01 +0200 Subject: [PATCH 095/121] remove `project_euler` --- CONTRIBUTING.md | 1 - DIRECTORY.md | 20 --------- project_euler/README.md | 20 --------- project_euler/problem_1/sol1.rb | 14 ------ project_euler/problem_2/sol1.rb | 17 -------- project_euler/problem_20/sol1.rb | 18 -------- project_euler/problem_21/sol1.rb | 57 ------------------------- project_euler/problem_22/p022_names.txt | 1 - project_euler/problem_22/sol1.rb | 40 ----------------- project_euler/problem_3/sol1.rb | 29 ------------- project_euler/problem_3/sol2.rb | 18 -------- project_euler/problem_4/sol1.rb | 11 ----- project_euler/problem_4/sol2.rb | 26 ----------- project_euler/problem_5/sol1.rb | 22 ---------- 14 files changed, 294 deletions(-) delete mode 100644 project_euler/README.md delete mode 100644 project_euler/problem_1/sol1.rb delete mode 100644 project_euler/problem_2/sol1.rb delete mode 100644 project_euler/problem_20/sol1.rb delete mode 100644 project_euler/problem_21/sol1.rb delete mode 100644 project_euler/problem_22/p022_names.txt delete mode 100644 project_euler/problem_22/sol1.rb delete mode 100644 project_euler/problem_3/sol1.rb delete mode 100644 project_euler/problem_3/sol2.rb delete mode 100644 project_euler/problem_4/sol1.rb delete mode 100644 project_euler/problem_4/sol2.rb delete mode 100644 project_euler/problem_5/sol1.rb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e66755c..b1081ec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,7 +50,6 @@ Algorithms in this repo should not be how-to examples for existing Ruby packages #### Other Requirements for Submissions -- If you are submitting code in the `project_euler/` directory, please also read [the dedicated Guideline](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/README.md) before contributing to our Project Euler library. - Strictly use snake_case (underscore_separated) in your file_name, as it will be easy to parse in future using scripts. - Please avoid creating new directories if at all possible. Try to fit your work into the existing directory structure. - If possible, follow the standard *within* the folder you are submitting to. diff --git a/DIRECTORY.md b/DIRECTORY.md index 3b1eba2..0993c62 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -103,26 +103,6 @@ ## Other * [Fisher Yates](https://github.com/TheAlgorithms/Ruby/blob/master/other/fisher_yates.rb) -## Project Euler - * Problem 1 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_1/sol1.rb) - * Problem 2 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_2/sol1.rb) - * Problem 20 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_20/sol1.rb) - * Problem 21 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_21/sol1.rb) - * Problem 22 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_22/sol1.rb) - * Problem 3 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_3/sol1.rb) - * [Sol2](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_3/sol2.rb) - * Problem 4 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_4/sol1.rb) - * [Sol2](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_4/sol2.rb) - * Problem 5 - * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_5/sol1.rb) - ## Searches * [Binary Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/binary_search.rb) * [Depth First Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/depth_first_search.rb) diff --git a/project_euler/README.md b/project_euler/README.md deleted file mode 100644 index a58bc64..0000000 --- a/project_euler/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Project Euler - -Problems are taken from https://projecteuler.net/, the Project Euler. [Problems are licensed under CC BY-NC-SA 4.0](https://projecteuler.net/copyright). - -Project Euler is a series of challenging mathematical/computer programming problems that require more than just mathematical -insights to solve. Project Euler is ideal for mathematicians who are learning to code. - -## Solution Guidelines - -Welcome to [TheAlgorithms/Ruby](https://github.com/TheAlgorithms/Ruby)! Before reading the solution guidelines, make sure you read the whole [Contributing Guidelines](https://github.com/TheAlgorithms/Ruby/blob/master/CONTRIBUTING.md) as it won't be repeated in here. If you have any doubt on the guidelines, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Ruby/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms). Be sure to read the [Coding Style](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/README.md#coding-style) before starting solution. - -### Coding Style - -* Please maintain consistency in project directory and solution file names. Keep the following points in mind: - * Create a new directory only for the problems which do not exist yet. - * Please name the project **directory** as `problem_` where `problem_number` should be filled with 0s so as to occupy 3 digits. Example: `problem_001`, `problem_002`, `problem_067`, `problem_145`, and so on. - -* You can have as many helper functions as you want but there should be one main function called `solution` which should satisfy the conditions as stated below: - * It should contain positional argument(s) whose default value is the question input. Example: Please take a look at [Problem 1](https://projecteuler.net/problem=1) where the question is to *Find the sum of all the multiples of 3 or 5 below 1000.* In this case the main solution function will be `solution(limit = 1000)`. - * When the `solution` function is called without any arguments like so: `solution()`, it should return the answer to the problem. diff --git a/project_euler/problem_1/sol1.rb b/project_euler/problem_1/sol1.rb deleted file mode 100644 index d08b820..0000000 --- a/project_euler/problem_1/sol1.rb +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - -def divisible_by_three_or_five?(number) - (number % 3).zero? || (number % 5).zero? -end - -sum = 0 -(1...1000).each do |i| - sum += i if divisible_by_three_or_five?(i) -end - -p sum diff --git a/project_euler/problem_2/sol1.rb b/project_euler/problem_2/sol1.rb deleted file mode 100644 index 17b6214..0000000 --- a/project_euler/problem_2/sol1.rb +++ /dev/null @@ -1,17 +0,0 @@ -# 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. - -even_fib_sum = 0 -fib_first = 1 -fib_second = 2 - -while fib_second < 4_000_000 - even_fib_sum += fib_second if fib_second.even? - fib_second += fib_first - fib_first = fib_second - fib_first -end - -p even_fib_sum diff --git a/project_euler/problem_20/sol1.rb b/project_euler/problem_20/sol1.rb deleted file mode 100644 index d144ad9..0000000 --- a/project_euler/problem_20/sol1.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -# n! means n x (n - 1) x ... x 3 x 2 x 1 - -# For example, 10! = 10 x 9 x ... x 3 x 2 x 1 = 3628800, -# and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. -# -# Find the sum of the digits in the number 100! - -# method to calculate factorial of a number -def factorial(number) - number.downto(1).reduce(:*) -end - -# fetch digits of factorial of `number` and find -# sum of all those digits, and prints the result on the console -number = 100 -puts factorial(number).digits.sum diff --git a/project_euler/problem_21/sol1.rb b/project_euler/problem_21/sol1.rb deleted file mode 100644 index bedadaf..0000000 --- a/project_euler/problem_21/sol1.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -# Let d(n) be defined as the sum of proper divisors of n -# (numbers less than n which divide evenly into n). -# If d(a) = b and d(b) = a, where a & b, then a and b are an amicable pair. -# and each of a and b are called amicable numbers. -# -# For example, -# -# The proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; -# therefore d(220) = 284. -# -# The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. -# -# Evaluate the sum of all the amicable numbers under 10000. - -# get list of all divisors of `number` -def get_divisors(number) - divisors = [] - (1..(Math.sqrt(number).to_i)).each do |num| - if (number % num).zero? - divisors << num - divisors << number / num - end - end - divisors -end - -# get list of all proper divisors of `number` i.e. removing `number` from -# the list of divisors -def get_proper_divisors(number) - divisors = get_divisors(number) - divisors.delete(number) - divisors -end - -# implementation of a method `d` as mentioned in the question -# i.e. finding sum of all proper divisors of `number` -def d(number) - get_proper_divisors(number).sum -end - -# given an upper `limit`, this method finds all amicable numbers -# under this `limit` -def find_amicable_numbers(limit) - result = [] - (1...limit).each do |a| - b = d(a) - res = d(b) - result.push(a) if (a == res) && (a != b) - end - result -end - -# calling `find_amicable_numbers` method and finding sum of all such numbers -# below 10000, and printing the result on the console -puts find_amicable_numbers(10_000).sum diff --git a/project_euler/problem_22/p022_names.txt b/project_euler/problem_22/p022_names.txt deleted file mode 100644 index 7b8986b..0000000 --- a/project_euler/problem_22/p022_names.txt +++ /dev/null @@ -1 +0,0 @@ -"MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN","BETTY","HELEN","SANDRA","DONNA","CAROL","RUTH","SHARON","MICHELLE","LAURA","SARAH","KIMBERLY","DEBORAH","JESSICA","SHIRLEY","CYNTHIA","ANGELA","MELISSA","BRENDA","AMY","ANNA","REBECCA","VIRGINIA","KATHLEEN","PAMELA","MARTHA","DEBRA","AMANDA","STEPHANIE","CAROLYN","CHRISTINE","MARIE","JANET","CATHERINE","FRANCES","ANN","JOYCE","DIANE","ALICE","JULIE","HEATHER","TERESA","DORIS","GLORIA","EVELYN","JEAN","CHERYL","MILDRED","KATHERINE","JOAN","ASHLEY","JUDITH","ROSE","JANICE","KELLY","NICOLE","JUDY","CHRISTINA","KATHY","THERESA","BEVERLY","DENISE","TAMMY","IRENE","JANE","LORI","RACHEL","MARILYN","ANDREA","KATHRYN","LOUISE","SARA","ANNE","JACQUELINE","WANDA","BONNIE","JULIA","RUBY","LOIS","TINA","PHYLLIS","NORMA","PAULA","DIANA","ANNIE","LILLIAN","EMILY","ROBIN","PEGGY","CRYSTAL","GLADYS","RITA","DAWN","CONNIE","FLORENCE","TRACY","EDNA","TIFFANY","CARMEN","ROSA","CINDY","GRACE","WENDY","VICTORIA","EDITH","KIM","SHERRY","SYLVIA","JOSEPHINE","THELMA","SHANNON","SHEILA","ETHEL","ELLEN","ELAINE","MARJORIE","CARRIE","CHARLOTTE","MONICA","ESTHER","PAULINE","EMMA","JUANITA","ANITA","RHONDA","HAZEL","AMBER","EVA","DEBBIE","APRIL","LESLIE","CLARA","LUCILLE","JAMIE","JOANNE","ELEANOR","VALERIE","DANIELLE","MEGAN","ALICIA","SUZANNE","MICHELE","GAIL","BERTHA","DARLENE","VERONICA","JILL","ERIN","GERALDINE","LAUREN","CATHY","JOANN","LORRAINE","LYNN","SALLY","REGINA","ERICA","BEATRICE","DOLORES","BERNICE","AUDREY","YVONNE","ANNETTE","JUNE","SAMANTHA","MARION","DANA","STACY","ANA","RENEE","IDA","VIVIAN","ROBERTA","HOLLY","BRITTANY","MELANIE","LORETTA","YOLANDA","JEANETTE","LAURIE","KATIE","KRISTEN","VANESSA","ALMA","SUE","ELSIE","BETH","JEANNE","VICKI","CARLA","TARA","ROSEMARY","EILEEN","TERRI","GERTRUDE","LUCY","TONYA","ELLA","STACEY","WILMA","GINA","KRISTIN","JESSIE","NATALIE","AGNES","VERA","WILLIE","CHARLENE","BESSIE","DELORES","MELINDA","PEARL","ARLENE","MAUREEN","COLLEEN","ALLISON","TAMARA","JOY","GEORGIA","CONSTANCE","LILLIE","CLAUDIA","JACKIE","MARCIA","TANYA","NELLIE","MINNIE","MARLENE","HEIDI","GLENDA","LYDIA","VIOLA","COURTNEY","MARIAN","STELLA","CAROLINE","DORA","JO","VICKIE","MATTIE","TERRY","MAXINE","IRMA","MABEL","MARSHA","MYRTLE","LENA","CHRISTY","DEANNA","PATSY","HILDA","GWENDOLYN","JENNIE","NORA","MARGIE","NINA","CASSANDRA","LEAH","PENNY","KAY","PRISCILLA","NAOMI","CAROLE","BRANDY","OLGA","BILLIE","DIANNE","TRACEY","LEONA","JENNY","FELICIA","SONIA","MIRIAM","VELMA","BECKY","BOBBIE","VIOLET","KRISTINA","TONI","MISTY","MAE","SHELLY","DAISY","RAMONA","SHERRI","ERIKA","KATRINA","CLAIRE","LINDSEY","LINDSAY","GENEVA","GUADALUPE","BELINDA","MARGARITA","SHERYL","CORA","FAYE","ADA","NATASHA","SABRINA","ISABEL","MARGUERITE","HATTIE","HARRIET","MOLLY","CECILIA","KRISTI","BRANDI","BLANCHE","SANDY","ROSIE","JOANNA","IRIS","EUNICE","ANGIE","INEZ","LYNDA","MADELINE","AMELIA","ALBERTA","GENEVIEVE","MONIQUE","JODI","JANIE","MAGGIE","KAYLA","SONYA","JAN","LEE","KRISTINE","CANDACE","FANNIE","MARYANN","OPAL","ALISON","YVETTE","MELODY","LUZ","SUSIE","OLIVIA","FLORA","SHELLEY","KRISTY","MAMIE","LULA","LOLA","VERNA","BEULAH","ANTOINETTE","CANDICE","JUANA","JEANNETTE","PAM","KELLI","HANNAH","WHITNEY","BRIDGET","KARLA","CELIA","LATOYA","PATTY","SHELIA","GAYLE","DELLA","VICKY","LYNNE","SHERI","MARIANNE","KARA","JACQUELYN","ERMA","BLANCA","MYRA","LETICIA","PAT","KRISTA","ROXANNE","ANGELICA","JOHNNIE","ROBYN","FRANCIS","ADRIENNE","ROSALIE","ALEXANDRA","BROOKE","BETHANY","SADIE","BERNADETTE","TRACI","JODY","KENDRA","JASMINE","NICHOLE","RACHAEL","CHELSEA","MABLE","ERNESTINE","MURIEL","MARCELLA","ELENA","KRYSTAL","ANGELINA","NADINE","KARI","ESTELLE","DIANNA","PAULETTE","LORA","MONA","DOREEN","ROSEMARIE","ANGEL","DESIREE","ANTONIA","HOPE","GINGER","JANIS","BETSY","CHRISTIE","FREDA","MERCEDES","MEREDITH","LYNETTE","TERI","CRISTINA","EULA","LEIGH","MEGHAN","SOPHIA","ELOISE","ROCHELLE","GRETCHEN","CECELIA","RAQUEL","HENRIETTA","ALYSSA","JANA","KELLEY","GWEN","KERRY","JENNA","TRICIA","LAVERNE","OLIVE","ALEXIS","TASHA","SILVIA","ELVIRA","CASEY","DELIA","SOPHIE","KATE","PATTI","LORENA","KELLIE","SONJA","LILA","LANA","DARLA","MAY","MINDY","ESSIE","MANDY","LORENE","ELSA","JOSEFINA","JEANNIE","MIRANDA","DIXIE","LUCIA","MARTA","FAITH","LELA","JOHANNA","SHARI","CAMILLE","TAMI","SHAWNA","ELISA","EBONY","MELBA","ORA","NETTIE","TABITHA","OLLIE","JAIME","WINIFRED","KRISTIE","MARINA","ALISHA","AIMEE","RENA","MYRNA","MARLA","TAMMIE","LATASHA","BONITA","PATRICE","RONDA","SHERRIE","ADDIE","FRANCINE","DELORIS","STACIE","ADRIANA","CHERI","SHELBY","ABIGAIL","CELESTE","JEWEL","CARA","ADELE","REBEKAH","LUCINDA","DORTHY","CHRIS","EFFIE","TRINA","REBA","SHAWN","SALLIE","AURORA","LENORA","ETTA","LOTTIE","KERRI","TRISHA","NIKKI","ESTELLA","FRANCISCA","JOSIE","TRACIE","MARISSA","KARIN","BRITTNEY","JANELLE","LOURDES","LAUREL","HELENE","FERN","ELVA","CORINNE","KELSEY","INA","BETTIE","ELISABETH","AIDA","CAITLIN","INGRID","IVA","EUGENIA","CHRISTA","GOLDIE","CASSIE","MAUDE","JENIFER","THERESE","FRANKIE","DENA","LORNA","JANETTE","LATONYA","CANDY","MORGAN","CONSUELO","TAMIKA","ROSETTA","DEBORA","CHERIE","POLLY","DINA","JEWELL","FAY","JILLIAN","DOROTHEA","NELL","TRUDY","ESPERANZA","PATRICA","KIMBERLEY","SHANNA","HELENA","CAROLINA","CLEO","STEFANIE","ROSARIO","OLA","JANINE","MOLLIE","LUPE","ALISA","LOU","MARIBEL","SUSANNE","BETTE","SUSANA","ELISE","CECILE","ISABELLE","LESLEY","JOCELYN","PAIGE","JONI","RACHELLE","LEOLA","DAPHNE","ALTA","ESTER","PETRA","GRACIELA","IMOGENE","JOLENE","KEISHA","LACEY","GLENNA","GABRIELA","KERI","URSULA","LIZZIE","KIRSTEN","SHANA","ADELINE","MAYRA","JAYNE","JACLYN","GRACIE","SONDRA","CARMELA","MARISA","ROSALIND","CHARITY","TONIA","BEATRIZ","MARISOL","CLARICE","JEANINE","SHEENA","ANGELINE","FRIEDA","LILY","ROBBIE","SHAUNA","MILLIE","CLAUDETTE","CATHLEEN","ANGELIA","GABRIELLE","AUTUMN","KATHARINE","SUMMER","JODIE","STACI","LEA","CHRISTI","JIMMIE","JUSTINE","ELMA","LUELLA","MARGRET","DOMINIQUE","SOCORRO","RENE","MARTINA","MARGO","MAVIS","CALLIE","BOBBI","MARITZA","LUCILE","LEANNE","JEANNINE","DEANA","AILEEN","LORIE","LADONNA","WILLA","MANUELA","GALE","SELMA","DOLLY","SYBIL","ABBY","LARA","DALE","IVY","DEE","WINNIE","MARCY","LUISA","JERI","MAGDALENA","OFELIA","MEAGAN","AUDRA","MATILDA","LEILA","CORNELIA","BIANCA","SIMONE","BETTYE","RANDI","VIRGIE","LATISHA","BARBRA","GEORGINA","ELIZA","LEANN","BRIDGETTE","RHODA","HALEY","ADELA","NOLA","BERNADINE","FLOSSIE","ILA","GRETA","RUTHIE","NELDA","MINERVA","LILLY","TERRIE","LETHA","HILARY","ESTELA","VALARIE","BRIANNA","ROSALYN","EARLINE","CATALINA","AVA","MIA","CLARISSA","LIDIA","CORRINE","ALEXANDRIA","CONCEPCION","TIA","SHARRON","RAE","DONA","ERICKA","JAMI","ELNORA","CHANDRA","LENORE","NEVA","MARYLOU","MELISA","TABATHA","SERENA","AVIS","ALLIE","SOFIA","JEANIE","ODESSA","NANNIE","HARRIETT","LORAINE","PENELOPE","MILAGROS","EMILIA","BENITA","ALLYSON","ASHLEE","TANIA","TOMMIE","ESMERALDA","KARINA","EVE","PEARLIE","ZELMA","MALINDA","NOREEN","TAMEKA","SAUNDRA","HILLARY","AMIE","ALTHEA","ROSALINDA","JORDAN","LILIA","ALANA","GAY","CLARE","ALEJANDRA","ELINOR","MICHAEL","LORRIE","JERRI","DARCY","EARNESTINE","CARMELLA","TAYLOR","NOEMI","MARCIE","LIZA","ANNABELLE","LOUISA","EARLENE","MALLORY","CARLENE","NITA","SELENA","TANISHA","KATY","JULIANNE","JOHN","LAKISHA","EDWINA","MARICELA","MARGERY","KENYA","DOLLIE","ROXIE","ROSLYN","KATHRINE","NANETTE","CHARMAINE","LAVONNE","ILENE","KRIS","TAMMI","SUZETTE","CORINE","KAYE","JERRY","MERLE","CHRYSTAL","LINA","DEANNE","LILIAN","JULIANA","ALINE","LUANN","KASEY","MARYANNE","EVANGELINE","COLETTE","MELVA","LAWANDA","YESENIA","NADIA","MADGE","KATHIE","EDDIE","OPHELIA","VALERIA","NONA","MITZI","MARI","GEORGETTE","CLAUDINE","FRAN","ALISSA","ROSEANN","LAKEISHA","SUSANNA","REVA","DEIDRE","CHASITY","SHEREE","CARLY","JAMES","ELVIA","ALYCE","DEIRDRE","GENA","BRIANA","ARACELI","KATELYN","ROSANNE","WENDI","TESSA","BERTA","MARVA","IMELDA","MARIETTA","MARCI","LEONOR","ARLINE","SASHA","MADELYN","JANNA","JULIETTE","DEENA","AURELIA","JOSEFA","AUGUSTA","LILIANA","YOUNG","CHRISTIAN","LESSIE","AMALIA","SAVANNAH","ANASTASIA","VILMA","NATALIA","ROSELLA","LYNNETTE","CORINA","ALFREDA","LEANNA","CAREY","AMPARO","COLEEN","TAMRA","AISHA","WILDA","KARYN","CHERRY","QUEEN","MAURA","MAI","EVANGELINA","ROSANNA","HALLIE","ERNA","ENID","MARIANA","LACY","JULIET","JACKLYN","FREIDA","MADELEINE","MARA","HESTER","CATHRYN","LELIA","CASANDRA","BRIDGETT","ANGELITA","JANNIE","DIONNE","ANNMARIE","KATINA","BERYL","PHOEBE","MILLICENT","KATHERYN","DIANN","CARISSA","MARYELLEN","LIZ","LAURI","HELGA","GILDA","ADRIAN","RHEA","MARQUITA","HOLLIE","TISHA","TAMERA","ANGELIQUE","FRANCESCA","BRITNEY","KAITLIN","LOLITA","FLORINE","ROWENA","REYNA","TWILA","FANNY","JANELL","INES","CONCETTA","BERTIE","ALBA","BRIGITTE","ALYSON","VONDA","PANSY","ELBA","NOELLE","LETITIA","KITTY","DEANN","BRANDIE","LOUELLA","LETA","FELECIA","SHARLENE","LESA","BEVERLEY","ROBERT","ISABELLA","HERMINIA","TERRA","CELINA","TORI","OCTAVIA","JADE","DENICE","GERMAINE","SIERRA","MICHELL","CORTNEY","NELLY","DORETHA","SYDNEY","DEIDRA","MONIKA","LASHONDA","JUDI","CHELSEY","ANTIONETTE","MARGOT","BOBBY","ADELAIDE","NAN","LEEANN","ELISHA","DESSIE","LIBBY","KATHI","GAYLA","LATANYA","MINA","MELLISA","KIMBERLEE","JASMIN","RENAE","ZELDA","ELDA","MA","JUSTINA","GUSSIE","EMILIE","CAMILLA","ABBIE","ROCIO","KAITLYN","JESSE","EDYTHE","ASHLEIGH","SELINA","LAKESHA","GERI","ALLENE","PAMALA","MICHAELA","DAYNA","CARYN","ROSALIA","SUN","JACQULINE","REBECA","MARYBETH","KRYSTLE","IOLA","DOTTIE","BENNIE","BELLE","AUBREY","GRISELDA","ERNESTINA","ELIDA","ADRIANNE","DEMETRIA","DELMA","CHONG","JAQUELINE","DESTINY","ARLEEN","VIRGINA","RETHA","FATIMA","TILLIE","ELEANORE","CARI","TREVA","BIRDIE","WILHELMINA","ROSALEE","MAURINE","LATRICE","YONG","JENA","TARYN","ELIA","DEBBY","MAUDIE","JEANNA","DELILAH","CATRINA","SHONDA","HORTENCIA","THEODORA","TERESITA","ROBBIN","DANETTE","MARYJANE","FREDDIE","DELPHINE","BRIANNE","NILDA","DANNA","CINDI","BESS","IONA","HANNA","ARIEL","WINONA","VIDA","ROSITA","MARIANNA","WILLIAM","RACHEAL","GUILLERMINA","ELOISA","CELESTINE","CAREN","MALISSA","LONA","CHANTEL","SHELLIE","MARISELA","LEORA","AGATHA","SOLEDAD","MIGDALIA","IVETTE","CHRISTEN","ATHENA","JANEL","CHLOE","VEDA","PATTIE","TESSIE","TERA","MARILYNN","LUCRETIA","KARRIE","DINAH","DANIELA","ALECIA","ADELINA","VERNICE","SHIELA","PORTIA","MERRY","LASHAWN","DEVON","DARA","TAWANA","OMA","VERDA","CHRISTIN","ALENE","ZELLA","SANDI","RAFAELA","MAYA","KIRA","CANDIDA","ALVINA","SUZAN","SHAYLA","LYN","LETTIE","ALVA","SAMATHA","ORALIA","MATILDE","MADONNA","LARISSA","VESTA","RENITA","INDIA","DELOIS","SHANDA","PHILLIS","LORRI","ERLINDA","CRUZ","CATHRINE","BARB","ZOE","ISABELL","IONE","GISELA","CHARLIE","VALENCIA","ROXANNA","MAYME","KISHA","ELLIE","MELLISSA","DORRIS","DALIA","BELLA","ANNETTA","ZOILA","RETA","REINA","LAURETTA","KYLIE","CHRISTAL","PILAR","CHARLA","ELISSA","TIFFANI","TANA","PAULINA","LEOTA","BREANNA","JAYME","CARMEL","VERNELL","TOMASA","MANDI","DOMINGA","SANTA","MELODIE","LURA","ALEXA","TAMELA","RYAN","MIRNA","KERRIE","VENUS","NOEL","FELICITA","CRISTY","CARMELITA","BERNIECE","ANNEMARIE","TIARA","ROSEANNE","MISSY","CORI","ROXANA","PRICILLA","KRISTAL","JUNG","ELYSE","HAYDEE","ALETHA","BETTINA","MARGE","GILLIAN","FILOMENA","CHARLES","ZENAIDA","HARRIETTE","CARIDAD","VADA","UNA","ARETHA","PEARLINE","MARJORY","MARCELA","FLOR","EVETTE","ELOUISE","ALINA","TRINIDAD","DAVID","DAMARIS","CATHARINE","CARROLL","BELVA","NAKIA","MARLENA","LUANNE","LORINE","KARON","DORENE","DANITA","BRENNA","TATIANA","SAMMIE","LOUANN","LOREN","JULIANNA","ANDRIA","PHILOMENA","LUCILA","LEONORA","DOVIE","ROMONA","MIMI","JACQUELIN","GAYE","TONJA","MISTI","JOE","GENE","CHASTITY","STACIA","ROXANN","MICAELA","NIKITA","MEI","VELDA","MARLYS","JOHNNA","AURA","LAVERN","IVONNE","HAYLEY","NICKI","MAJORIE","HERLINDA","GEORGE","ALPHA","YADIRA","PERLA","GREGORIA","DANIEL","ANTONETTE","SHELLI","MOZELLE","MARIAH","JOELLE","CORDELIA","JOSETTE","CHIQUITA","TRISTA","LOUIS","LAQUITA","GEORGIANA","CANDI","SHANON","LONNIE","HILDEGARD","CECIL","VALENTINA","STEPHANY","MAGDA","KAROL","GERRY","GABRIELLA","TIANA","ROMA","RICHELLE","RAY","PRINCESS","OLETA","JACQUE","IDELLA","ALAINA","SUZANNA","JOVITA","BLAIR","TOSHA","RAVEN","NEREIDA","MARLYN","KYLA","JOSEPH","DELFINA","TENA","STEPHENIE","SABINA","NATHALIE","MARCELLE","GERTIE","DARLEEN","THEA","SHARONDA","SHANTEL","BELEN","VENESSA","ROSALINA","ONA","GENOVEVA","COREY","CLEMENTINE","ROSALBA","RENATE","RENATA","MI","IVORY","GEORGIANNA","FLOY","DORCAS","ARIANA","TYRA","THEDA","MARIAM","JULI","JESICA","DONNIE","VIKKI","VERLA","ROSELYN","MELVINA","JANNETTE","GINNY","DEBRAH","CORRIE","ASIA","VIOLETA","MYRTIS","LATRICIA","COLLETTE","CHARLEEN","ANISSA","VIVIANA","TWYLA","PRECIOUS","NEDRA","LATONIA","LAN","HELLEN","FABIOLA","ANNAMARIE","ADELL","SHARYN","CHANTAL","NIKI","MAUD","LIZETTE","LINDY","KIA","KESHA","JEANA","DANELLE","CHARLINE","CHANEL","CARROL","VALORIE","LIA","DORTHA","CRISTAL","SUNNY","LEONE","LEILANI","GERRI","DEBI","ANDRA","KESHIA","IMA","EULALIA","EASTER","DULCE","NATIVIDAD","LINNIE","KAMI","GEORGIE","CATINA","BROOK","ALDA","WINNIFRED","SHARLA","RUTHANN","MEAGHAN","MAGDALENE","LISSETTE","ADELAIDA","VENITA","TRENA","SHIRLENE","SHAMEKA","ELIZEBETH","DIAN","SHANTA","MICKEY","LATOSHA","CARLOTTA","WINDY","SOON","ROSINA","MARIANN","LEISA","JONNIE","DAWNA","CATHIE","BILLY","ASTRID","SIDNEY","LAUREEN","JANEEN","HOLLI","FAWN","VICKEY","TERESSA","SHANTE","RUBYE","MARCELINA","CHANDA","CARY","TERESE","SCARLETT","MARTY","MARNIE","LULU","LISETTE","JENIFFER","ELENOR","DORINDA","DONITA","CARMAN","BERNITA","ALTAGRACIA","ALETA","ADRIANNA","ZORAIDA","RONNIE","NICOLA","LYNDSEY","KENDALL","JANINA","CHRISSY","AMI","STARLA","PHYLIS","PHUONG","KYRA","CHARISSE","BLANCH","SANJUANITA","RONA","NANCI","MARILEE","MARANDA","CORY","BRIGETTE","SANJUANA","MARITA","KASSANDRA","JOYCELYN","IRA","FELIPA","CHELSIE","BONNY","MIREYA","LORENZA","KYONG","ILEANA","CANDELARIA","TONY","TOBY","SHERIE","OK","MARK","LUCIE","LEATRICE","LAKESHIA","GERDA","EDIE","BAMBI","MARYLIN","LAVON","HORTENSE","GARNET","EVIE","TRESSA","SHAYNA","LAVINA","KYUNG","JEANETTA","SHERRILL","SHARA","PHYLISS","MITTIE","ANABEL","ALESIA","THUY","TAWANDA","RICHARD","JOANIE","TIFFANIE","LASHANDA","KARISSA","ENRIQUETA","DARIA","DANIELLA","CORINNA","ALANNA","ABBEY","ROXANE","ROSEANNA","MAGNOLIA","LIDA","KYLE","JOELLEN","ERA","CORAL","CARLEEN","TRESA","PEGGIE","NOVELLA","NILA","MAYBELLE","JENELLE","CARINA","NOVA","MELINA","MARQUERITE","MARGARETTE","JOSEPHINA","EVONNE","DEVIN","CINTHIA","ALBINA","TOYA","TAWNYA","SHERITA","SANTOS","MYRIAM","LIZABETH","LISE","KEELY","JENNI","GISELLE","CHERYLE","ARDITH","ARDIS","ALESHA","ADRIANE","SHAINA","LINNEA","KAROLYN","HONG","FLORIDA","FELISHA","DORI","DARCI","ARTIE","ARMIDA","ZOLA","XIOMARA","VERGIE","SHAMIKA","NENA","NANNETTE","MAXIE","LOVIE","JEANE","JAIMIE","INGE","FARRAH","ELAINA","CAITLYN","STARR","FELICITAS","CHERLY","CARYL","YOLONDA","YASMIN","TEENA","PRUDENCE","PENNIE","NYDIA","MACKENZIE","ORPHA","MARVEL","LIZBETH","LAURETTE","JERRIE","HERMELINDA","CAROLEE","TIERRA","MIRIAN","META","MELONY","KORI","JENNETTE","JAMILA","ENA","ANH","YOSHIKO","SUSANNAH","SALINA","RHIANNON","JOLEEN","CRISTINE","ASHTON","ARACELY","TOMEKA","SHALONDA","MARTI","LACIE","KALA","JADA","ILSE","HAILEY","BRITTANI","ZONA","SYBLE","SHERRYL","RANDY","NIDIA","MARLO","KANDICE","KANDI","DEB","DEAN","AMERICA","ALYCIA","TOMMY","RONNA","NORENE","MERCY","JOSE","INGEBORG","GIOVANNA","GEMMA","CHRISTEL","AUDRY","ZORA","VITA","VAN","TRISH","STEPHAINE","SHIRLEE","SHANIKA","MELONIE","MAZIE","JAZMIN","INGA","HOA","HETTIE","GERALYN","FONDA","ESTRELLA","ADELLA","SU","SARITA","RINA","MILISSA","MARIBETH","GOLDA","EVON","ETHELYN","ENEDINA","CHERISE","CHANA","VELVA","TAWANNA","SADE","MIRTA","LI","KARIE","JACINTA","ELNA","DAVINA","CIERRA","ASHLIE","ALBERTHA","TANESHA","STEPHANI","NELLE","MINDI","LU","LORINDA","LARUE","FLORENE","DEMETRA","DEDRA","CIARA","CHANTELLE","ASHLY","SUZY","ROSALVA","NOELIA","LYDA","LEATHA","KRYSTYNA","KRISTAN","KARRI","DARLINE","DARCIE","CINDA","CHEYENNE","CHERRIE","AWILDA","ALMEDA","ROLANDA","LANETTE","JERILYN","GISELE","EVALYN","CYNDI","CLETA","CARIN","ZINA","ZENA","VELIA","TANIKA","PAUL","CHARISSA","THOMAS","TALIA","MARGARETE","LAVONDA","KAYLEE","KATHLENE","JONNA","IRENA","ILONA","IDALIA","CANDIS","CANDANCE","BRANDEE","ANITRA","ALIDA","SIGRID","NICOLETTE","MARYJO","LINETTE","HEDWIG","CHRISTIANA","CASSIDY","ALEXIA","TRESSIE","MODESTA","LUPITA","LITA","GLADIS","EVELIA","DAVIDA","CHERRI","CECILY","ASHELY","ANNABEL","AGUSTINA","WANITA","SHIRLY","ROSAURA","HULDA","EUN","BAILEY","YETTA","VERONA","THOMASINA","SIBYL","SHANNAN","MECHELLE","LUE","LEANDRA","LANI","KYLEE","KANDY","JOLYNN","FERNE","EBONI","CORENE","ALYSIA","ZULA","NADA","MOIRA","LYNDSAY","LORRETTA","JUAN","JAMMIE","HORTENSIA","GAYNELL","CAMERON","ADRIA","VINA","VICENTA","TANGELA","STEPHINE","NORINE","NELLA","LIANA","LESLEE","KIMBERELY","ILIANA","GLORY","FELICA","EMOGENE","ELFRIEDE","EDEN","EARTHA","CARMA","BEA","OCIE","MARRY","LENNIE","KIARA","JACALYN","CARLOTA","ARIELLE","YU","STAR","OTILIA","KIRSTIN","KACEY","JOHNETTA","JOEY","JOETTA","JERALDINE","JAUNITA","ELANA","DORTHEA","CAMI","AMADA","ADELIA","VERNITA","TAMAR","SIOBHAN","RENEA","RASHIDA","OUIDA","ODELL","NILSA","MERYL","KRISTYN","JULIETA","DANICA","BREANNE","AUREA","ANGLEA","SHERRON","ODETTE","MALIA","LORELEI","LIN","LEESA","KENNA","KATHLYN","FIONA","CHARLETTE","SUZIE","SHANTELL","SABRA","RACQUEL","MYONG","MIRA","MARTINE","LUCIENNE","LAVADA","JULIANN","JOHNIE","ELVERA","DELPHIA","CLAIR","CHRISTIANE","CHAROLETTE","CARRI","AUGUSTINE","ASHA","ANGELLA","PAOLA","NINFA","LEDA","LAI","EDA","SUNSHINE","STEFANI","SHANELL","PALMA","MACHELLE","LISSA","KECIA","KATHRYNE","KARLENE","JULISSA","JETTIE","JENNIFFER","HUI","CORRINA","CHRISTOPHER","CAROLANN","ALENA","TESS","ROSARIA","MYRTICE","MARYLEE","LIANE","KENYATTA","JUDIE","JANEY","IN","ELMIRA","ELDORA","DENNA","CRISTI","CATHI","ZAIDA","VONNIE","VIVA","VERNIE","ROSALINE","MARIELA","LUCIANA","LESLI","KARAN","FELICE","DENEEN","ADINA","WYNONA","TARSHA","SHERON","SHASTA","SHANITA","SHANI","SHANDRA","RANDA","PINKIE","PARIS","NELIDA","MARILOU","LYLA","LAURENE","LACI","JOI","JANENE","DOROTHA","DANIELE","DANI","CAROLYNN","CARLYN","BERENICE","AYESHA","ANNELIESE","ALETHEA","THERSA","TAMIKO","RUFINA","OLIVA","MOZELL","MARYLYN","MADISON","KRISTIAN","KATHYRN","KASANDRA","KANDACE","JANAE","GABRIEL","DOMENICA","DEBBRA","DANNIELLE","CHUN","BUFFY","BARBIE","ARCELIA","AJA","ZENOBIA","SHAREN","SHAREE","PATRICK","PAGE","MY","LAVINIA","KUM","KACIE","JACKELINE","HUONG","FELISA","EMELIA","ELEANORA","CYTHIA","CRISTIN","CLYDE","CLARIBEL","CARON","ANASTACIA","ZULMA","ZANDRA","YOKO","TENISHA","SUSANN","SHERILYN","SHAY","SHAWANDA","SABINE","ROMANA","MATHILDA","LINSEY","KEIKO","JOANA","ISELA","GRETTA","GEORGETTA","EUGENIE","DUSTY","DESIRAE","DELORA","CORAZON","ANTONINA","ANIKA","WILLENE","TRACEE","TAMATHA","REGAN","NICHELLE","MICKIE","MAEGAN","LUANA","LANITA","KELSIE","EDELMIRA","BREE","AFTON","TEODORA","TAMIE","SHENA","MEG","LINH","KELI","KACI","DANYELLE","BRITT","ARLETTE","ALBERTINE","ADELLE","TIFFINY","STORMY","SIMONA","NUMBERS","NICOLASA","NICHOL","NIA","NAKISHA","MEE","MAIRA","LOREEN","KIZZY","JOHNNY","JAY","FALLON","CHRISTENE","BOBBYE","ANTHONY","YING","VINCENZA","TANJA","RUBIE","RONI","QUEENIE","MARGARETT","KIMBERLI","IRMGARD","IDELL","HILMA","EVELINA","ESTA","EMILEE","DENNISE","DANIA","CARL","CARIE","ANTONIO","WAI","SANG","RISA","RIKKI","PARTICIA","MUI","MASAKO","MARIO","LUVENIA","LOREE","LONI","LIEN","KEVIN","GIGI","FLORENCIA","DORIAN","DENITA","DALLAS","CHI","BILLYE","ALEXANDER","TOMIKA","SHARITA","RANA","NIKOLE","NEOMA","MARGARITE","MADALYN","LUCINA","LAILA","KALI","JENETTE","GABRIELE","EVELYNE","ELENORA","CLEMENTINA","ALEJANDRINA","ZULEMA","VIOLETTE","VANNESSA","THRESA","RETTA","PIA","PATIENCE","NOELLA","NICKIE","JONELL","DELTA","CHUNG","CHAYA","CAMELIA","BETHEL","ANYA","ANDREW","THANH","SUZANN","SPRING","SHU","MILA","LILLA","LAVERNA","KEESHA","KATTIE","GIA","GEORGENE","EVELINE","ESTELL","ELIZBETH","VIVIENNE","VALLIE","TRUDIE","STEPHANE","MICHEL","MAGALY","MADIE","KENYETTA","KARREN","JANETTA","HERMINE","HARMONY","DRUCILLA","DEBBI","CELESTINA","CANDIE","BRITNI","BECKIE","AMINA","ZITA","YUN","YOLANDE","VIVIEN","VERNETTA","TRUDI","SOMMER","PEARLE","PATRINA","OSSIE","NICOLLE","LOYCE","LETTY","LARISA","KATHARINA","JOSELYN","JONELLE","JENELL","IESHA","HEIDE","FLORINDA","FLORENTINA","FLO","ELODIA","DORINE","BRUNILDA","BRIGID","ASHLI","ARDELLA","TWANA","THU","TARAH","SUNG","SHEA","SHAVON","SHANE","SERINA","RAYNA","RAMONITA","NGA","MARGURITE","LUCRECIA","KOURTNEY","KATI","JESUS","JESENIA","DIAMOND","CRISTA","AYANA","ALICA","ALIA","VINNIE","SUELLEN","ROMELIA","RACHELL","PIPER","OLYMPIA","MICHIKO","KATHALEEN","JOLIE","JESSI","JANESSA","HANA","HA","ELEASE","CARLETTA","BRITANY","SHONA","SALOME","ROSAMOND","REGENA","RAINA","NGOC","NELIA","LOUVENIA","LESIA","LATRINA","LATICIA","LARHONDA","JINA","JACKI","HOLLIS","HOLLEY","EMMY","DEEANN","CORETTA","ARNETTA","VELVET","THALIA","SHANICE","NETA","MIKKI","MICKI","LONNA","LEANA","LASHUNDA","KILEY","JOYE","JACQULYN","IGNACIA","HYUN","HIROKO","HENRY","HENRIETTE","ELAYNE","DELINDA","DARNELL","DAHLIA","COREEN","CONSUELA","CONCHITA","CELINE","BABETTE","AYANNA","ANETTE","ALBERTINA","SKYE","SHAWNEE","SHANEKA","QUIANA","PAMELIA","MIN","MERRI","MERLENE","MARGIT","KIESHA","KIERA","KAYLENE","JODEE","JENISE","ERLENE","EMMIE","ELSE","DARYL","DALILA","DAISEY","CODY","CASIE","BELIA","BABARA","VERSIE","VANESA","SHELBA","SHAWNDA","SAM","NORMAN","NIKIA","NAOMA","MARNA","MARGERET","MADALINE","LAWANA","KINDRA","JUTTA","JAZMINE","JANETT","HANNELORE","GLENDORA","GERTRUD","GARNETT","FREEDA","FREDERICA","FLORANCE","FLAVIA","DENNIS","CARLINE","BEVERLEE","ANJANETTE","VALDA","TRINITY","TAMALA","STEVIE","SHONNA","SHA","SARINA","ONEIDA","MICAH","MERILYN","MARLEEN","LURLINE","LENNA","KATHERIN","JIN","JENI","HAE","GRACIA","GLADY","FARAH","ERIC","ENOLA","EMA","DOMINQUE","DEVONA","DELANA","CECILA","CAPRICE","ALYSHA","ALI","ALETHIA","VENA","THERESIA","TAWNY","SONG","SHAKIRA","SAMARA","SACHIKO","RACHELE","PAMELLA","NICKY","MARNI","MARIEL","MAREN","MALISA","LIGIA","LERA","LATORIA","LARAE","KIMBER","KATHERN","KAREY","JENNEFER","JANETH","HALINA","FREDIA","DELISA","DEBROAH","CIERA","CHIN","ANGELIKA","ANDREE","ALTHA","YEN","VIVAN","TERRESA","TANNA","SUK","SUDIE","SOO","SIGNE","SALENA","RONNI","REBBECCA","MYRTIE","MCKENZIE","MALIKA","MAIDA","LOAN","LEONARDA","KAYLEIGH","FRANCE","ETHYL","ELLYN","DAYLE","CAMMIE","BRITTNI","BIRGIT","AVELINA","ASUNCION","ARIANNA","AKIKO","VENICE","TYESHA","TONIE","TIESHA","TAKISHA","STEFFANIE","SINDY","SANTANA","MEGHANN","MANDA","MACIE","LADY","KELLYE","KELLEE","JOSLYN","JASON","INGER","INDIRA","GLINDA","GLENNIS","FERNANDA","FAUSTINA","ENEIDA","ELICIA","DOT","DIGNA","DELL","ARLETTA","ANDRE","WILLIA","TAMMARA","TABETHA","SHERRELL","SARI","REFUGIO","REBBECA","PAULETTA","NIEVES","NATOSHA","NAKITA","MAMMIE","KENISHA","KAZUKO","KASSIE","GARY","EARLEAN","DAPHINE","CORLISS","CLOTILDE","CAROLYNE","BERNETTA","AUGUSTINA","AUDREA","ANNIS","ANNABELL","YAN","TENNILLE","TAMICA","SELENE","SEAN","ROSANA","REGENIA","QIANA","MARKITA","MACY","LEEANNE","LAURINE","KYM","JESSENIA","JANITA","GEORGINE","GENIE","EMIKO","ELVIE","DEANDRA","DAGMAR","CORIE","COLLEN","CHERISH","ROMAINE","PORSHA","PEARLENE","MICHELINE","MERNA","MARGORIE","MARGARETTA","LORE","KENNETH","JENINE","HERMINA","FREDERICKA","ELKE","DRUSILLA","DORATHY","DIONE","DESIRE","CELENA","BRIGIDA","ANGELES","ALLEGRA","THEO","TAMEKIA","SYNTHIA","STEPHEN","SOOK","SLYVIA","ROSANN","REATHA","RAYE","MARQUETTA","MARGART","LING","LAYLA","KYMBERLY","KIANA","KAYLEEN","KATLYN","KARMEN","JOELLA","IRINA","EMELDA","ELENI","DETRA","CLEMMIE","CHERYLL","CHANTELL","CATHEY","ARNITA","ARLA","ANGLE","ANGELIC","ALYSE","ZOFIA","THOMASINE","TENNIE","SON","SHERLY","SHERLEY","SHARYL","REMEDIOS","PETRINA","NICKOLE","MYUNG","MYRLE","MOZELLA","LOUANNE","LISHA","LATIA","LANE","KRYSTA","JULIENNE","JOEL","JEANENE","JACQUALINE","ISAURA","GWENDA","EARLEEN","DONALD","CLEOPATRA","CARLIE","AUDIE","ANTONIETTA","ALISE","ALEX","VERDELL","VAL","TYLER","TOMOKO","THAO","TALISHA","STEVEN","SO","SHEMIKA","SHAUN","SCARLET","SAVANNA","SANTINA","ROSIA","RAEANN","ODILIA","NANA","MINNA","MAGAN","LYNELLE","LE","KARMA","JOEANN","IVANA","INELL","ILANA","HYE","HONEY","HEE","GUDRUN","FRANK","DREAMA","CRISSY","CHANTE","CARMELINA","ARVILLA","ARTHUR","ANNAMAE","ALVERA","ALEIDA","AARON","YEE","YANIRA","VANDA","TIANNA","TAM","STEFANIA","SHIRA","PERRY","NICOL","NANCIE","MONSERRATE","MINH","MELYNDA","MELANY","MATTHEW","LOVELLA","LAURE","KIRBY","KACY","JACQUELYNN","HYON","GERTHA","FRANCISCO","ELIANA","CHRISTENA","CHRISTEEN","CHARISE","CATERINA","CARLEY","CANDYCE","ARLENA","AMMIE","YANG","WILLETTE","VANITA","TUYET","TINY","SYREETA","SILVA","SCOTT","RONALD","PENNEY","NYLA","MICHAL","MAURICE","MARYAM","MARYA","MAGEN","LUDIE","LOMA","LIVIA","LANELL","KIMBERLIE","JULEE","DONETTA","DIEDRA","DENISHA","DEANE","DAWNE","CLARINE","CHERRYL","BRONWYN","BRANDON","ALLA","VALERY","TONDA","SUEANN","SORAYA","SHOSHANA","SHELA","SHARLEEN","SHANELLE","NERISSA","MICHEAL","MERIDITH","MELLIE","MAYE","MAPLE","MAGARET","LUIS","LILI","LEONILA","LEONIE","LEEANNA","LAVONIA","LAVERA","KRISTEL","KATHEY","KATHE","JUSTIN","JULIAN","JIMMY","JANN","ILDA","HILDRED","HILDEGARDE","GENIA","FUMIKO","EVELIN","ERMELINDA","ELLY","DUNG","DOLORIS","DIONNA","DANAE","BERNEICE","ANNICE","ALIX","VERENA","VERDIE","TRISTAN","SHAWNNA","SHAWANA","SHAUNNA","ROZELLA","RANDEE","RANAE","MILAGRO","LYNELL","LUISE","LOUIE","LOIDA","LISBETH","KARLEEN","JUNITA","JONA","ISIS","HYACINTH","HEDY","GWENN","ETHELENE","ERLINE","EDWARD","DONYA","DOMONIQUE","DELICIA","DANNETTE","CICELY","BRANDA","BLYTHE","BETHANN","ASHLYN","ANNALEE","ALLINE","YUKO","VELLA","TRANG","TOWANDA","TESHA","SHERLYN","NARCISA","MIGUELINA","MERI","MAYBELL","MARLANA","MARGUERITA","MADLYN","LUNA","LORY","LORIANN","LIBERTY","LEONORE","LEIGHANN","LAURICE","LATESHA","LARONDA","KATRICE","KASIE","KARL","KALEY","JADWIGA","GLENNIE","GEARLDINE","FRANCINA","EPIFANIA","DYAN","DORIE","DIEDRE","DENESE","DEMETRICE","DELENA","DARBY","CRISTIE","CLEORA","CATARINA","CARISA","BERNIE","BARBERA","ALMETA","TRULA","TEREASA","SOLANGE","SHEILAH","SHAVONNE","SANORA","ROCHELL","MATHILDE","MARGARETA","MAIA","LYNSEY","LAWANNA","LAUNA","KENA","KEENA","KATIA","JAMEY","GLYNDA","GAYLENE","ELVINA","ELANOR","DANUTA","DANIKA","CRISTEN","CORDIE","COLETTA","CLARITA","CARMON","BRYNN","AZUCENA","AUNDREA","ANGELE","YI","WALTER","VERLIE","VERLENE","TAMESHA","SILVANA","SEBRINA","SAMIRA","REDA","RAYLENE","PENNI","PANDORA","NORAH","NOMA","MIREILLE","MELISSIA","MARYALICE","LARAINE","KIMBERY","KARYL","KARINE","KAM","JOLANDA","JOHANA","JESUSA","JALEESA","JAE","JACQUELYNE","IRISH","ILUMINADA","HILARIA","HANH","GENNIE","FRANCIE","FLORETTA","EXIE","EDDA","DREMA","DELPHA","BEV","BARBAR","ASSUNTA","ARDELL","ANNALISA","ALISIA","YUKIKO","YOLANDO","WONDA","WEI","WALTRAUD","VETA","TEQUILA","TEMEKA","TAMEIKA","SHIRLEEN","SHENITA","PIEDAD","OZELLA","MIRTHA","MARILU","KIMIKO","JULIANE","JENICE","JEN","JANAY","JACQUILINE","HILDE","FE","FAE","EVAN","EUGENE","ELOIS","ECHO","DEVORAH","CHAU","BRINDA","BETSEY","ARMINDA","ARACELIS","APRYL","ANNETT","ALISHIA","VEOLA","USHA","TOSHIKO","THEOLA","TASHIA","TALITHA","SHERY","RUDY","RENETTA","REIKO","RASHEEDA","OMEGA","OBDULIA","MIKA","MELAINE","MEGGAN","MARTIN","MARLEN","MARGET","MARCELINE","MANA","MAGDALEN","LIBRADA","LEZLIE","LEXIE","LATASHIA","LASANDRA","KELLE","ISIDRA","ISA","INOCENCIA","GWYN","FRANCOISE","ERMINIA","ERINN","DIMPLE","DEVORA","CRISELDA","ARMANDA","ARIE","ARIANE","ANGELO","ANGELENA","ALLEN","ALIZA","ADRIENE","ADALINE","XOCHITL","TWANNA","TRAN","TOMIKO","TAMISHA","TAISHA","SUSY","SIU","RUTHA","ROXY","RHONA","RAYMOND","OTHA","NORIKO","NATASHIA","MERRIE","MELVIN","MARINDA","MARIKO","MARGERT","LORIS","LIZZETTE","LEISHA","KAILA","KA","JOANNIE","JERRICA","JENE","JANNET","JANEE","JACINDA","HERTA","ELENORE","DORETTA","DELAINE","DANIELL","CLAUDIE","CHINA","BRITTA","APOLONIA","AMBERLY","ALEASE","YURI","YUK","WEN","WANETA","UTE","TOMI","SHARRI","SANDIE","ROSELLE","REYNALDA","RAGUEL","PHYLICIA","PATRIA","OLIMPIA","ODELIA","MITZIE","MITCHELL","MISS","MINDA","MIGNON","MICA","MENDY","MARIVEL","MAILE","LYNETTA","LAVETTE","LAURYN","LATRISHA","LAKIESHA","KIERSTEN","KARY","JOSPHINE","JOLYN","JETTA","JANISE","JACQUIE","IVELISSE","GLYNIS","GIANNA","GAYNELLE","EMERALD","DEMETRIUS","DANYELL","DANILLE","DACIA","CORALEE","CHER","CEOLA","BRETT","BELL","ARIANNE","ALESHIA","YUNG","WILLIEMAE","TROY","TRINH","THORA","TAI","SVETLANA","SHERIKA","SHEMEKA","SHAUNDA","ROSELINE","RICKI","MELDA","MALLIE","LAVONNA","LATINA","LARRY","LAQUANDA","LALA","LACHELLE","KLARA","KANDIS","JOHNA","JEANMARIE","JAYE","HANG","GRAYCE","GERTUDE","EMERITA","EBONIE","CLORINDA","CHING","CHERY","CAROLA","BREANN","BLOSSOM","BERNARDINE","BECKI","ARLETHA","ARGELIA","ARA","ALITA","YULANDA","YON","YESSENIA","TOBI","TASIA","SYLVIE","SHIRL","SHIRELY","SHERIDAN","SHELLA","SHANTELLE","SACHA","ROYCE","REBECKA","REAGAN","PROVIDENCIA","PAULENE","MISHA","MIKI","MARLINE","MARICA","LORITA","LATOYIA","LASONYA","KERSTIN","KENDA","KEITHA","KATHRIN","JAYMIE","JACK","GRICELDA","GINETTE","ERYN","ELINA","ELFRIEDA","DANYEL","CHEREE","CHANELLE","BARRIE","AVERY","AURORE","ANNAMARIA","ALLEEN","AILENE","AIDE","YASMINE","VASHTI","VALENTINE","TREASA","TORY","TIFFANEY","SHERYLL","SHARIE","SHANAE","SAU","RAISA","PA","NEDA","MITSUKO","MIRELLA","MILDA","MARYANNA","MARAGRET","MABELLE","LUETTA","LORINA","LETISHA","LATARSHA","LANELLE","LAJUANA","KRISSY","KARLY","KARENA","JON","JESSIKA","JERICA","JEANELLE","JANUARY","JALISA","JACELYN","IZOLA","IVEY","GREGORY","EUNA","ETHA","DREW","DOMITILA","DOMINICA","DAINA","CREOLA","CARLI","CAMIE","BUNNY","BRITTNY","ASHANTI","ANISHA","ALEEN","ADAH","YASUKO","WINTER","VIKI","VALRIE","TONA","TINISHA","THI","TERISA","TATUM","TANEKA","SIMONNE","SHALANDA","SERITA","RESSIE","REFUGIA","PAZ","OLENE","NA","MERRILL","MARGHERITA","MANDIE","MAN","MAIRE","LYNDIA","LUCI","LORRIANE","LORETA","LEONIA","LAVONA","LASHAWNDA","LAKIA","KYOKO","KRYSTINA","KRYSTEN","KENIA","KELSI","JUDE","JEANICE","ISOBEL","GEORGIANN","GENNY","FELICIDAD","EILENE","DEON","DELOISE","DEEDEE","DANNIE","CONCEPTION","CLORA","CHERILYN","CHANG","CALANDRA","BERRY","ARMANDINA","ANISA","ULA","TIMOTHY","TIERA","THERESSA","STEPHANIA","SIMA","SHYLA","SHONTA","SHERA","SHAQUITA","SHALA","SAMMY","ROSSANA","NOHEMI","NERY","MORIAH","MELITA","MELIDA","MELANI","MARYLYNN","MARISHA","MARIETTE","MALORIE","MADELENE","LUDIVINA","LORIA","LORETTE","LORALEE","LIANNE","LEON","LAVENIA","LAURINDA","LASHON","KIT","KIMI","KEILA","KATELYNN","KAI","JONE","JOANE","JI","JAYNA","JANELLA","JA","HUE","HERTHA","FRANCENE","ELINORE","DESPINA","DELSIE","DEEDRA","CLEMENCIA","CARRY","CAROLIN","CARLOS","BULAH","BRITTANIE","BOK","BLONDELL","BIBI","BEAULAH","BEATA","ANNITA","AGRIPINA","VIRGEN","VALENE","UN","TWANDA","TOMMYE","TOI","TARRA","TARI","TAMMERA","SHAKIA","SADYE","RUTHANNE","ROCHEL","RIVKA","PURA","NENITA","NATISHA","MING","MERRILEE","MELODEE","MARVIS","LUCILLA","LEENA","LAVETA","LARITA","LANIE","KEREN","ILEEN","GEORGEANN","GENNA","GENESIS","FRIDA","EWA","EUFEMIA","EMELY","ELA","EDYTH","DEONNA","DEADRA","DARLENA","CHANELL","CHAN","CATHERN","CASSONDRA","CASSAUNDRA","BERNARDA","BERNA","ARLINDA","ANAMARIA","ALBERT","WESLEY","VERTIE","VALERI","TORRI","TATYANA","STASIA","SHERISE","SHERILL","SEASON","SCOTTIE","SANDA","RUTHE","ROSY","ROBERTO","ROBBI","RANEE","QUYEN","PEARLY","PALMIRA","ONITA","NISHA","NIESHA","NIDA","NEVADA","NAM","MERLYN","MAYOLA","MARYLOUISE","MARYLAND","MARX","MARTH","MARGENE","MADELAINE","LONDA","LEONTINE","LEOMA","LEIA","LAWRENCE","LAURALEE","LANORA","LAKITA","KIYOKO","KETURAH","KATELIN","KAREEN","JONIE","JOHNETTE","JENEE","JEANETT","IZETTA","HIEDI","HEIKE","HASSIE","HAROLD","GIUSEPPINA","GEORGANN","FIDELA","FERNANDE","ELWANDA","ELLAMAE","ELIZ","DUSTI","DOTTY","CYNDY","CORALIE","CELESTA","ARGENTINA","ALVERTA","XENIA","WAVA","VANETTA","TORRIE","TASHINA","TANDY","TAMBRA","TAMA","STEPANIE","SHILA","SHAUNTA","SHARAN","SHANIQUA","SHAE","SETSUKO","SERAFINA","SANDEE","ROSAMARIA","PRISCILA","OLINDA","NADENE","MUOI","MICHELINA","MERCEDEZ","MARYROSE","MARIN","MARCENE","MAO","MAGALI","MAFALDA","LOGAN","LINN","LANNIE","KAYCE","KAROLINE","KAMILAH","KAMALA","JUSTA","JOLINE","JENNINE","JACQUETTA","IRAIDA","GERALD","GEORGEANNA","FRANCHESCA","FAIRY","EMELINE","ELANE","EHTEL","EARLIE","DULCIE","DALENE","CRIS","CLASSIE","CHERE","CHARIS","CAROYLN","CARMINA","CARITA","BRIAN","BETHANIE","AYAKO","ARICA","AN","ALYSA","ALESSANDRA","AKILAH","ADRIEN","ZETTA","YOULANDA","YELENA","YAHAIRA","XUAN","WENDOLYN","VICTOR","TIJUANA","TERRELL","TERINA","TERESIA","SUZI","SUNDAY","SHERELL","SHAVONDA","SHAUNTE","SHARDA","SHAKITA","SENA","RYANN","RUBI","RIVA","REGINIA","REA","RACHAL","PARTHENIA","PAMULA","MONNIE","MONET","MICHAELE","MELIA","MARINE","MALKA","MAISHA","LISANDRA","LEO","LEKISHA","LEAN","LAURENCE","LAKENDRA","KRYSTIN","KORTNEY","KIZZIE","KITTIE","KERA","KENDAL","KEMBERLY","KANISHA","JULENE","JULE","JOSHUA","JOHANNE","JEFFREY","JAMEE","HAN","HALLEY","GIDGET","GALINA","FREDRICKA","FLETA","FATIMAH","EUSEBIA","ELZA","ELEONORE","DORTHEY","DORIA","DONELLA","DINORAH","DELORSE","CLARETHA","CHRISTINIA","CHARLYN","BONG","BELKIS","AZZIE","ANDERA","AIKO","ADENA","YER","YAJAIRA","WAN","VANIA","ULRIKE","TOSHIA","TIFANY","STEFANY","SHIZUE","SHENIKA","SHAWANNA","SHAROLYN","SHARILYN","SHAQUANA","SHANTAY","SEE","ROZANNE","ROSELEE","RICKIE","REMONA","REANNA","RAELENE","QUINN","PHUNG","PETRONILA","NATACHA","NANCEY","MYRL","MIYOKO","MIESHA","MERIDETH","MARVELLA","MARQUITTA","MARHTA","MARCHELLE","LIZETH","LIBBIE","LAHOMA","LADAWN","KINA","KATHELEEN","KATHARYN","KARISA","KALEIGH","JUNIE","JULIEANN","JOHNSIE","JANEAN","JAIMEE","JACKQUELINE","HISAKO","HERMA","HELAINE","GWYNETH","GLENN","GITA","EUSTOLIA","EMELINA","ELIN","EDRIS","DONNETTE","DONNETTA","DIERDRE","DENAE","DARCEL","CLAUDE","CLARISA","CINDERELLA","CHIA","CHARLESETTA","CHARITA","CELSA","CASSY","CASSI","CARLEE","BRUNA","BRITTANEY","BRANDE","BILLI","BAO","ANTONETTA","ANGLA","ANGELYN","ANALISA","ALANE","WENONA","WENDIE","VERONIQUE","VANNESA","TOBIE","TEMPIE","SUMIKO","SULEMA","SPARKLE","SOMER","SHEBA","SHAYNE","SHARICE","SHANEL","SHALON","SAGE","ROY","ROSIO","ROSELIA","RENAY","REMA","REENA","PORSCHE","PING","PEG","OZIE","ORETHA","ORALEE","ODA","NU","NGAN","NAKESHA","MILLY","MARYBELLE","MARLIN","MARIS","MARGRETT","MARAGARET","MANIE","LURLENE","LILLIA","LIESELOTTE","LAVELLE","LASHAUNDA","LAKEESHA","KEITH","KAYCEE","KALYN","JOYA","JOETTE","JENAE","JANIECE","ILLA","GRISEL","GLAYDS","GENEVIE","GALA","FREDDA","FRED","ELMER","ELEONOR","DEBERA","DEANDREA","DAN","CORRINNE","CORDIA","CONTESSA","COLENE","CLEOTILDE","CHARLOTT","CHANTAY","CECILLE","BEATRIS","AZALEE","ARLEAN","ARDATH","ANJELICA","ANJA","ALFREDIA","ALEISHA","ADAM","ZADA","YUONNE","XIAO","WILLODEAN","WHITLEY","VENNIE","VANNA","TYISHA","TOVA","TORIE","TONISHA","TILDA","TIEN","TEMPLE","SIRENA","SHERRIL","SHANTI","SHAN","SENAIDA","SAMELLA","ROBBYN","RENDA","REITA","PHEBE","PAULITA","NOBUKO","NGUYET","NEOMI","MOON","MIKAELA","MELANIA","MAXIMINA","MARG","MAISIE","LYNNA","LILLI","LAYNE","LASHAUN","LAKENYA","LAEL","KIRSTIE","KATHLINE","KASHA","KARLYN","KARIMA","JOVAN","JOSEFINE","JENNELL","JACQUI","JACKELYN","HYO","HIEN","GRAZYNA","FLORRIE","FLORIA","ELEONORA","DWANA","DORLA","DONG","DELMY","DEJA","DEDE","DANN","CRYSTA","CLELIA","CLARIS","CLARENCE","CHIEKO","CHERLYN","CHERELLE","CHARMAIN","CHARA","CAMMY","BEE","ARNETTE","ARDELLE","ANNIKA","AMIEE","AMEE","ALLENA","YVONE","YUKI","YOSHIE","YEVETTE","YAEL","WILLETTA","VONCILE","VENETTA","TULA","TONETTE","TIMIKA","TEMIKA","TELMA","TEISHA","TAREN","TA","STACEE","SHIN","SHAWNTA","SATURNINA","RICARDA","POK","PASTY","ONIE","NUBIA","MORA","MIKE","MARIELLE","MARIELLA","MARIANELA","MARDELL","MANY","LUANNA","LOISE","LISABETH","LINDSY","LILLIANA","LILLIAM","LELAH","LEIGHA","LEANORA","LANG","KRISTEEN","KHALILAH","KEELEY","KANDRA","JUNKO","JOAQUINA","JERLENE","JANI","JAMIKA","JAME","HSIU","HERMILA","GOLDEN","GENEVIVE","EVIA","EUGENA","EMMALINE","ELFREDA","ELENE","DONETTE","DELCIE","DEEANNA","DARCEY","CUC","CLARINDA","CIRA","CHAE","CELINDA","CATHERYN","CATHERIN","CASIMIRA","CARMELIA","CAMELLIA","BREANA","BOBETTE","BERNARDINA","BEBE","BASILIA","ARLYNE","AMAL","ALAYNA","ZONIA","ZENIA","YURIKO","YAEKO","WYNELL","WILLOW","WILLENA","VERNIA","TU","TRAVIS","TORA","TERRILYN","TERICA","TENESHA","TAWNA","TAJUANA","TAINA","STEPHNIE","SONA","SOL","SINA","SHONDRA","SHIZUKO","SHERLENE","SHERICE","SHARIKA","ROSSIE","ROSENA","RORY","RIMA","RIA","RHEBA","RENNA","PETER","NATALYA","NANCEE","MELODI","MEDA","MAXIMA","MATHA","MARKETTA","MARICRUZ","MARCELENE","MALVINA","LUBA","LOUETTA","LEIDA","LECIA","LAURAN","LASHAWNA","LAINE","KHADIJAH","KATERINE","KASI","KALLIE","JULIETTA","JESUSITA","JESTINE","JESSIA","JEREMY","JEFFIE","JANYCE","ISADORA","GEORGIANNE","FIDELIA","EVITA","EURA","EULAH","ESTEFANA","ELSY","ELIZABET","ELADIA","DODIE","DION","DIA","DENISSE","DELORAS","DELILA","DAYSI","DAKOTA","CURTIS","CRYSTLE","CONCHA","COLBY","CLARETTA","CHU","CHRISTIA","CHARLSIE","CHARLENA","CARYLON","BETTYANN","ASLEY","ASHLEA","AMIRA","AI","AGUEDA","AGNUS","YUETTE","VINITA","VICTORINA","TYNISHA","TREENA","TOCCARA","TISH","THOMASENA","TEGAN","SOILA","SHILOH","SHENNA","SHARMAINE","SHANTAE","SHANDI","SEPTEMBER","SARAN","SARAI","SANA","SAMUEL","SALLEY","ROSETTE","ROLANDE","REGINE","OTELIA","OSCAR","OLEVIA","NICHOLLE","NECOLE","NAIDA","MYRTA","MYESHA","MITSUE","MINTA","MERTIE","MARGY","MAHALIA","MADALENE","LOVE","LOURA","LOREAN","LEWIS","LESHA","LEONIDA","LENITA","LAVONE","LASHELL","LASHANDRA","LAMONICA","KIMBRA","KATHERINA","KARRY","KANESHA","JULIO","JONG","JENEVA","JAQUELYN","HWA","GILMA","GHISLAINE","GERTRUDIS","FRANSISCA","FERMINA","ETTIE","ETSUKO","ELLIS","ELLAN","ELIDIA","EDRA","DORETHEA","DOREATHA","DENYSE","DENNY","DEETTA","DAINE","CYRSTAL","CORRIN","CAYLA","CARLITA","CAMILA","BURMA","BULA","BUENA","BLAKE","BARABARA","AVRIL","AUSTIN","ALAINE","ZANA","WILHEMINA","WANETTA","VIRGIL","VI","VERONIKA","VERNON","VERLINE","VASILIKI","TONITA","TISA","TEOFILA","TAYNA","TAUNYA","TANDRA","TAKAKO","SUNNI","SUANNE","SIXTA","SHARELL","SEEMA","RUSSELL","ROSENDA","ROBENA","RAYMONDE","PEI","PAMILA","OZELL","NEIDA","NEELY","MISTIE","MICHA","MERISSA","MAURITA","MARYLN","MARYETTA","MARSHALL","MARCELL","MALENA","MAKEDA","MADDIE","LOVETTA","LOURIE","LORRINE","LORILEE","LESTER","LAURENA","LASHAY","LARRAINE","LAREE","LACRESHA","KRISTLE","KRISHNA","KEVA","KEIRA","KAROLE","JOIE","JINNY","JEANNETTA","JAMA","HEIDY","GILBERTE","GEMA","FAVIOLA","EVELYNN","ENDA","ELLI","ELLENA","DIVINA","DAGNY","COLLENE","CODI","CINDIE","CHASSIDY","CHASIDY","CATRICE","CATHERINA","CASSEY","CAROLL","CARLENA","CANDRA","CALISTA","BRYANNA","BRITTENY","BEULA","BARI","AUDRIE","AUDRIA","ARDELIA","ANNELLE","ANGILA","ALONA","ALLYN","DOUGLAS","ROGER","JONATHAN","RALPH","NICHOLAS","BENJAMIN","BRUCE","HARRY","WAYNE","STEVE","HOWARD","ERNEST","PHILLIP","TODD","CRAIG","ALAN","PHILIP","EARL","DANNY","BRYAN","STANLEY","LEONARD","NATHAN","MANUEL","RODNEY","MARVIN","VINCENT","JEFFERY","JEFF","CHAD","JACOB","ALFRED","BRADLEY","HERBERT","FREDERICK","EDWIN","DON","RICKY","RANDALL","BARRY","BERNARD","LEROY","MARCUS","THEODORE","CLIFFORD","MIGUEL","JIM","TOM","CALVIN","BILL","LLOYD","DEREK","WARREN","DARRELL","JEROME","FLOYD","ALVIN","TIM","GORDON","GREG","JORGE","DUSTIN","PEDRO","DERRICK","ZACHARY","HERMAN","GLEN","HECTOR","RICARDO","RICK","BRENT","RAMON","GILBERT","MARC","REGINALD","RUBEN","NATHANIEL","RAFAEL","EDGAR","MILTON","RAUL","BEN","CHESTER","DUANE","FRANKLIN","BRAD","RON","ROLAND","ARNOLD","HARVEY","JARED","ERIK","DARRYL","NEIL","JAVIER","FERNANDO","CLINTON","TED","MATHEW","TYRONE","DARREN","LANCE","KURT","ALLAN","NELSON","GUY","CLAYTON","HUGH","MAX","DWAYNE","DWIGHT","ARMANDO","FELIX","EVERETT","IAN","WALLACE","KEN","BOB","ALFREDO","ALBERTO","DAVE","IVAN","BYRON","ISAAC","MORRIS","CLIFTON","WILLARD","ROSS","ANDY","SALVADOR","KIRK","SERGIO","SETH","KENT","TERRANCE","EDUARDO","TERRENCE","ENRIQUE","WADE","STUART","FREDRICK","ARTURO","ALEJANDRO","NICK","LUTHER","WENDELL","JEREMIAH","JULIUS","OTIS","TREVOR","OLIVER","LUKE","HOMER","GERARD","DOUG","KENNY","HUBERT","LYLE","MATT","ALFONSO","ORLANDO","REX","CARLTON","ERNESTO","NEAL","PABLO","LORENZO","OMAR","WILBUR","GRANT","HORACE","RODERICK","ABRAHAM","WILLIS","RICKEY","ANDRES","CESAR","JOHNATHAN","MALCOLM","RUDOLPH","DAMON","KELVIN","PRESTON","ALTON","ARCHIE","MARCO","WM","PETE","RANDOLPH","GARRY","GEOFFREY","JONATHON","FELIPE","GERARDO","ED","DOMINIC","DELBERT","COLIN","GUILLERMO","EARNEST","LUCAS","BENNY","SPENCER","RODOLFO","MYRON","EDMUND","GARRETT","SALVATORE","CEDRIC","LOWELL","GREGG","SHERMAN","WILSON","SYLVESTER","ROOSEVELT","ISRAEL","JERMAINE","FORREST","WILBERT","LELAND","SIMON","CLARK","IRVING","BRYANT","OWEN","RUFUS","WOODROW","KRISTOPHER","MACK","LEVI","MARCOS","GUSTAVO","JAKE","LIONEL","GILBERTO","CLINT","NICOLAS","ISMAEL","ORVILLE","ERVIN","DEWEY","AL","WILFRED","JOSH","HUGO","IGNACIO","CALEB","TOMAS","SHELDON","ERICK","STEWART","DOYLE","DARREL","ROGELIO","TERENCE","SANTIAGO","ALONZO","ELIAS","BERT","ELBERT","RAMIRO","CONRAD","NOAH","GRADY","PHIL","CORNELIUS","LAMAR","ROLANDO","CLAY","PERCY","DEXTER","BRADFORD","DARIN","AMOS","MOSES","IRVIN","SAUL","ROMAN","RANDAL","TIMMY","DARRIN","WINSTON","BRENDAN","ABEL","DOMINICK","BOYD","EMILIO","ELIJAH","DOMINGO","EMMETT","MARLON","EMANUEL","JERALD","EDMOND","EMIL","DEWAYNE","WILL","OTTO","TEDDY","REYNALDO","BRET","JESS","TRENT","HUMBERTO","EMMANUEL","STEPHAN","VICENTE","LAMONT","GARLAND","MILES","EFRAIN","HEATH","RODGER","HARLEY","ETHAN","ELDON","ROCKY","PIERRE","JUNIOR","FREDDY","ELI","BRYCE","ANTOINE","STERLING","CHASE","GROVER","ELTON","CLEVELAND","DYLAN","CHUCK","DAMIAN","REUBEN","STAN","AUGUST","LEONARDO","JASPER","RUSSEL","ERWIN","BENITO","HANS","MONTE","BLAINE","ERNIE","CURT","QUENTIN","AGUSTIN","MURRAY","JAMAL","ADOLFO","HARRISON","TYSON","BURTON","BRADY","ELLIOTT","WILFREDO","BART","JARROD","VANCE","DENIS","DAMIEN","JOAQUIN","HARLAN","DESMOND","ELLIOT","DARWIN","GREGORIO","BUDDY","XAVIER","KERMIT","ROSCOE","ESTEBAN","ANTON","SOLOMON","SCOTTY","NORBERT","ELVIN","WILLIAMS","NOLAN","ROD","QUINTON","HAL","BRAIN","ROB","ELWOOD","KENDRICK","DARIUS","MOISES","FIDEL","THADDEUS","CLIFF","MARCEL","JACKSON","RAPHAEL","BRYON","ARMAND","ALVARO","JEFFRY","DANE","JOESPH","THURMAN","NED","RUSTY","MONTY","FABIAN","REGGIE","MASON","GRAHAM","ISAIAH","VAUGHN","GUS","LOYD","DIEGO","ADOLPH","NORRIS","MILLARD","ROCCO","GONZALO","DERICK","RODRIGO","WILEY","RIGOBERTO","ALPHONSO","TY","NOE","VERN","REED","JEFFERSON","ELVIS","BERNARDO","MAURICIO","HIRAM","DONOVAN","BASIL","RILEY","NICKOLAS","MAYNARD","SCOT","VINCE","QUINCY","EDDY","SEBASTIAN","FEDERICO","ULYSSES","HERIBERTO","DONNELL","COLE","DAVIS","GAVIN","EMERY","WARD","ROMEO","JAYSON","DANTE","CLEMENT","COY","MAXWELL","JARVIS","BRUNO","ISSAC","DUDLEY","BROCK","SANFORD","CARMELO","BARNEY","NESTOR","STEFAN","DONNY","ART","LINWOOD","BEAU","WELDON","GALEN","ISIDRO","TRUMAN","DELMAR","JOHNATHON","SILAS","FREDERIC","DICK","IRWIN","MERLIN","CHARLEY","MARCELINO","HARRIS","CARLO","TRENTON","KURTIS","HUNTER","AURELIO","WINFRED","VITO","COLLIN","DENVER","CARTER","LEONEL","EMORY","PASQUALE","MOHAMMAD","MARIANO","DANIAL","LANDON","DIRK","BRANDEN","ADAN","BUFORD","GERMAN","WILMER","EMERSON","ZACHERY","FLETCHER","JACQUES","ERROL","DALTON","MONROE","JOSUE","EDWARDO","BOOKER","WILFORD","SONNY","SHELTON","CARSON","THERON","RAYMUNDO","DAREN","HOUSTON","ROBBY","LINCOLN","GENARO","BENNETT","OCTAVIO","CORNELL","HUNG","ARRON","ANTONY","HERSCHEL","GIOVANNI","GARTH","CYRUS","CYRIL","RONNY","LON","FREEMAN","DUNCAN","KENNITH","CARMINE","ERICH","CHADWICK","WILBURN","RUSS","REID","MYLES","ANDERSON","MORTON","JONAS","FOREST","MITCHEL","MERVIN","ZANE","RICH","JAMEL","LAZARO","ALPHONSE","RANDELL","MAJOR","JARRETT","BROOKS","ABDUL","LUCIANO","SEYMOUR","EUGENIO","MOHAMMED","VALENTIN","CHANCE","ARNULFO","LUCIEN","FERDINAND","THAD","EZRA","ALDO","RUBIN","ROYAL","MITCH","EARLE","ABE","WYATT","MARQUIS","LANNY","KAREEM","JAMAR","BORIS","ISIAH","EMILE","ELMO","ARON","LEOPOLDO","EVERETTE","JOSEF","ELOY","RODRICK","REINALDO","LUCIO","JERROD","WESTON","HERSHEL","BARTON","PARKER","LEMUEL","BURT","JULES","GIL","ELISEO","AHMAD","NIGEL","EFREN","ANTWAN","ALDEN","MARGARITO","COLEMAN","DINO","OSVALDO","LES","DEANDRE","NORMAND","KIETH","TREY","NORBERTO","NAPOLEON","JEROLD","FRITZ","ROSENDO","MILFORD","CHRISTOPER","ALFONZO","LYMAN","JOSIAH","BRANT","WILTON","RICO","JAMAAL","DEWITT","BRENTON","OLIN","FOSTER","FAUSTINO","CLAUDIO","JUDSON","GINO","EDGARDO","ALEC","TANNER","JARRED","DONN","TAD","PRINCE","PORFIRIO","ODIS","LENARD","CHAUNCEY","TOD","MEL","MARCELO","KORY","AUGUSTUS","KEVEN","HILARIO","BUD","SAL","ORVAL","MAURO","ZACHARIAH","OLEN","ANIBAL","MILO","JED","DILLON","AMADO","NEWTON","LENNY","RICHIE","HORACIO","BRICE","MOHAMED","DELMER","DARIO","REYES","MAC","JONAH","JERROLD","ROBT","HANK","RUPERT","ROLLAND","KENTON","DAMION","ANTONE","WALDO","FREDRIC","BRADLY","KIP","BURL","WALKER","TYREE","JEFFEREY","AHMED","WILLY","STANFORD","OREN","NOBLE","MOSHE","MIKEL","ENOCH","BRENDON","QUINTIN","JAMISON","FLORENCIO","DARRICK","TOBIAS","HASSAN","GIUSEPPE","DEMARCUS","CLETUS","TYRELL","LYNDON","KEENAN","WERNER","GERALDO","COLUMBUS","CHET","BERTRAM","MARKUS","HUEY","HILTON","DWAIN","DONTE","TYRON","OMER","ISAIAS","HIPOLITO","FERMIN","ADALBERTO","BO","BARRETT","TEODORO","MCKINLEY","MAXIMO","GARFIELD","RALEIGH","LAWERENCE","ABRAM","RASHAD","KING","EMMITT","DARON","SAMUAL","MIQUEL","EUSEBIO","DOMENIC","DARRON","BUSTER","WILBER","RENATO","JC","HOYT","HAYWOOD","EZEKIEL","CHAS","FLORENTINO","ELROY","CLEMENTE","ARDEN","NEVILLE","EDISON","DESHAWN","NATHANIAL","JORDON","DANILO","CLAUD","SHERWOOD","RAYMON","RAYFORD","CRISTOBAL","AMBROSE","TITUS","HYMAN","FELTON","EZEQUIEL","ERASMO","STANTON","LONNY","LEN","IKE","MILAN","LINO","JAROD","HERB","ANDREAS","WALTON","RHETT","PALMER","DOUGLASS","CORDELL","OSWALDO","ELLSWORTH","VIRGILIO","TONEY","NATHANAEL","DEL","BENEDICT","MOSE","JOHNSON","ISREAL","GARRET","FAUSTO","ASA","ARLEN","ZACK","WARNER","MODESTO","FRANCESCO","MANUAL","GAYLORD","GASTON","FILIBERTO","DEANGELO","MICHALE","GRANVILLE","WES","MALIK","ZACKARY","TUAN","ELDRIDGE","CRISTOPHER","CORTEZ","ANTIONE","MALCOM","LONG","KOREY","JOSPEH","COLTON","WAYLON","VON","HOSEA","SHAD","SANTO","RUDOLF","ROLF","REY","RENALDO","MARCELLUS","LUCIUS","KRISTOFER","BOYCE","BENTON","HAYDEN","HARLAND","ARNOLDO","RUEBEN","LEANDRO","KRAIG","JERRELL","JEROMY","HOBERT","CEDRICK","ARLIE","WINFORD","WALLY","LUIGI","KENETH","JACINTO","GRAIG","FRANKLYN","EDMUNDO","SID","PORTER","LEIF","JERAMY","BUCK","WILLIAN","VINCENZO","SHON","LYNWOOD","JERE","HAI","ELDEN","DORSEY","DARELL","BRODERICK","ALONSO" \ No newline at end of file diff --git a/project_euler/problem_22/sol1.rb b/project_euler/problem_22/sol1.rb deleted file mode 100644 index 9a4a8a9..0000000 --- a/project_euler/problem_22/sol1.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -# Problem 22 -# Using names.txt (right click and 'Save Link/Target As...'), -# a 46K text file containing over five-thousand first names, -# begin by sorting it into alphabetical order. -# Then working out the alphabetical value for each name, -# multiply this value by its alphabetical position in the list to obtain a name score. - -# For example, when the list is sorted into alphabetical order, -# COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, -# is the 938th name in the list. So, COLIN would obtain a score of 938 * 53 = 49714. - -# What is the total of all the name scores in the file? - -# reading the contents of the file -file_contents = File.read('p022_names.txt') - -# replacing the occuerance of \" to '' and spliting the result by ',' -# to get an array of sorted words -words = file_contents.tr('\"', '').split(',').sort - -# this method calculates the worth of a word based on the ASCII -# values of the characters -def word_worth(word) - word.chars.sum { |char| char.ord - 'A'.ord + 1 } -end - -# this method takes the words as an input -# calls `word_worth` method on each word -# to that value multiply that with the index of the word in the array -# add the same to the result -def total_rank(words) - result = 0 - words.each_with_index { |word, index| result += word_worth(word) * (index + 1) } - result -end - -# outputs total rank on the console -puts total_rank(words) diff --git a/project_euler/problem_3/sol1.rb b/project_euler/problem_3/sol1.rb deleted file mode 100644 index df92cf0..0000000 --- a/project_euler/problem_3/sol1.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# The prime factors of 13195 are 5, 7, 13 and 29. -# What is the largest prime factor of the number 600851475143 - -# find all factors of the given number -def get_factors(number) - factors = [] - (1..Math.sqrt(number).to_i).each do |num| - if (number % num).zero? - factors << num - factors << number / num - end - end - factors -end - -# determine if a given number is a prime number -def prime?(number) - get_factors(number).length == 2 -end - -# find the largest prime -def largest_prime_factor(number) - prime_factors = get_factors(number).select { |factor| prime?(factor) } - prime_factors.max -end - -puts largest_prime_factor(600_851_475_143) diff --git a/project_euler/problem_3/sol2.rb b/project_euler/problem_3/sol2.rb deleted file mode 100644 index 0685de6..0000000 --- a/project_euler/problem_3/sol2.rb +++ /dev/null @@ -1,18 +0,0 @@ -# The prime factors of 13195 are 5, 7, 13 and 29. -# What is the largest prime factor of the number 600851475143 ? - -def solution(n) - prime = 1 - i = 2 - while i * i <= n - while (n % i).zero? - prime = i - n = n.fdiv i - end - i += 1 - end - prime = n if n > 1 - prime.to_i -end - -puts solution(600_851_475_143) diff --git a/project_euler/problem_4/sol1.rb b/project_euler/problem_4/sol1.rb deleted file mode 100644 index f3f52a2..0000000 --- a/project_euler/problem_4/sol1.rb +++ /dev/null @@ -1,11 +0,0 @@ -# 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. - -answer = 0 -999.downto(99) do |i| - 999.downto(99) do |j| - t = (i * j) - answer = i * j if (t.to_s == t.to_s.reverse) && (t > answer) && (t > answer) - end -end -puts answer diff --git a/project_euler/problem_4/sol2.rb b/project_euler/problem_4/sol2.rb deleted file mode 100644 index fd881e2..0000000 --- a/project_euler/problem_4/sol2.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -# 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. - -class Integer - def parindrome? - self == reverse - end - - # 123.reverse == 321 - # 100.reverse == 1 - def reverse - result = 0 - n = self - loop do - result = result * 10 + n % 10 - break if (n /= 10).zero? - end - result - end -end - -factors = (100..999).to_a -products = factors.product(factors).map { _1 * _2 } -puts products.select(&:parindrome?).max diff --git a/project_euler/problem_5/sol1.rb b/project_euler/problem_5/sol1.rb deleted file mode 100644 index e83cbfb..0000000 --- a/project_euler/problem_5/sol1.rb +++ /dev/null @@ -1,22 +0,0 @@ -# 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? - -# Euclid's algorithm for the greatest common divisor -def gcd(a, b) - b.zero? ? a : gcd(b, a % b) -end - -# Calculate the LCM using GCD -def lcm(a, b) - (a * b) / gcd(a, b) -end - -result = 1 - -20.times do |i| - result = lcm(result, i + 1) -end - -p result From 2ea0f9aacfd05eb1fd28c6bcbcddfb9df2cf09aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Tue, 11 May 2021 18:41:11 +0200 Subject: [PATCH 096/121] Revert "remove `project_euler`" This reverts commit cdc053662d8553bf8332ab8be2cdb5c44146f922. --- CONTRIBUTING.md | 1 + DIRECTORY.md | 20 +++++++++ project_euler/README.md | 20 +++++++++ project_euler/problem_1/sol1.rb | 14 ++++++ project_euler/problem_2/sol1.rb | 17 ++++++++ project_euler/problem_20/sol1.rb | 18 ++++++++ project_euler/problem_21/sol1.rb | 57 +++++++++++++++++++++++++ project_euler/problem_22/p022_names.txt | 1 + project_euler/problem_22/sol1.rb | 40 +++++++++++++++++ project_euler/problem_3/sol1.rb | 29 +++++++++++++ project_euler/problem_3/sol2.rb | 18 ++++++++ project_euler/problem_4/sol1.rb | 11 +++++ project_euler/problem_4/sol2.rb | 26 +++++++++++ project_euler/problem_5/sol1.rb | 22 ++++++++++ 14 files changed, 294 insertions(+) create mode 100644 project_euler/README.md create mode 100644 project_euler/problem_1/sol1.rb create mode 100644 project_euler/problem_2/sol1.rb create mode 100644 project_euler/problem_20/sol1.rb create mode 100644 project_euler/problem_21/sol1.rb create mode 100644 project_euler/problem_22/p022_names.txt create mode 100644 project_euler/problem_22/sol1.rb create mode 100644 project_euler/problem_3/sol1.rb create mode 100644 project_euler/problem_3/sol2.rb create mode 100644 project_euler/problem_4/sol1.rb create mode 100644 project_euler/problem_4/sol2.rb create mode 100644 project_euler/problem_5/sol1.rb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b1081ec..e66755c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,6 +50,7 @@ Algorithms in this repo should not be how-to examples for existing Ruby packages #### Other Requirements for Submissions +- If you are submitting code in the `project_euler/` directory, please also read [the dedicated Guideline](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/README.md) before contributing to our Project Euler library. - Strictly use snake_case (underscore_separated) in your file_name, as it will be easy to parse in future using scripts. - Please avoid creating new directories if at all possible. Try to fit your work into the existing directory structure. - If possible, follow the standard *within* the folder you are submitting to. diff --git a/DIRECTORY.md b/DIRECTORY.md index 0993c62..3b1eba2 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -103,6 +103,26 @@ ## Other * [Fisher Yates](https://github.com/TheAlgorithms/Ruby/blob/master/other/fisher_yates.rb) +## Project Euler + * Problem 1 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_1/sol1.rb) + * Problem 2 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_2/sol1.rb) + * Problem 20 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_20/sol1.rb) + * Problem 21 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_21/sol1.rb) + * Problem 22 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_22/sol1.rb) + * Problem 3 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_3/sol1.rb) + * [Sol2](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_3/sol2.rb) + * Problem 4 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_4/sol1.rb) + * [Sol2](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_4/sol2.rb) + * Problem 5 + * [Sol1](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/problem_5/sol1.rb) + ## Searches * [Binary Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/binary_search.rb) * [Depth First Search](https://github.com/TheAlgorithms/Ruby/blob/master/searches/depth_first_search.rb) diff --git a/project_euler/README.md b/project_euler/README.md new file mode 100644 index 0000000..a58bc64 --- /dev/null +++ b/project_euler/README.md @@ -0,0 +1,20 @@ +# Project Euler + +Problems are taken from https://projecteuler.net/, the Project Euler. [Problems are licensed under CC BY-NC-SA 4.0](https://projecteuler.net/copyright). + +Project Euler is a series of challenging mathematical/computer programming problems that require more than just mathematical +insights to solve. Project Euler is ideal for mathematicians who are learning to code. + +## Solution Guidelines + +Welcome to [TheAlgorithms/Ruby](https://github.com/TheAlgorithms/Ruby)! Before reading the solution guidelines, make sure you read the whole [Contributing Guidelines](https://github.com/TheAlgorithms/Ruby/blob/master/CONTRIBUTING.md) as it won't be repeated in here. If you have any doubt on the guidelines, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Ruby/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms). Be sure to read the [Coding Style](https://github.com/TheAlgorithms/Ruby/blob/master/project_euler/README.md#coding-style) before starting solution. + +### Coding Style + +* Please maintain consistency in project directory and solution file names. Keep the following points in mind: + * Create a new directory only for the problems which do not exist yet. + * Please name the project **directory** as `problem_` where `problem_number` should be filled with 0s so as to occupy 3 digits. Example: `problem_001`, `problem_002`, `problem_067`, `problem_145`, and so on. + +* You can have as many helper functions as you want but there should be one main function called `solution` which should satisfy the conditions as stated below: + * It should contain positional argument(s) whose default value is the question input. Example: Please take a look at [Problem 1](https://projecteuler.net/problem=1) where the question is to *Find the sum of all the multiples of 3 or 5 below 1000.* In this case the main solution function will be `solution(limit = 1000)`. + * When the `solution` function is called without any arguments like so: `solution()`, it should return the answer to the problem. diff --git a/project_euler/problem_1/sol1.rb b/project_euler/problem_1/sol1.rb new file mode 100644 index 0000000..d08b820 --- /dev/null +++ b/project_euler/problem_1/sol1.rb @@ -0,0 +1,14 @@ +# 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. + +def divisible_by_three_or_five?(number) + (number % 3).zero? || (number % 5).zero? +end + +sum = 0 +(1...1000).each do |i| + sum += i if divisible_by_three_or_five?(i) +end + +p sum diff --git a/project_euler/problem_2/sol1.rb b/project_euler/problem_2/sol1.rb new file mode 100644 index 0000000..17b6214 --- /dev/null +++ b/project_euler/problem_2/sol1.rb @@ -0,0 +1,17 @@ +# 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. + +even_fib_sum = 0 +fib_first = 1 +fib_second = 2 + +while fib_second < 4_000_000 + even_fib_sum += fib_second if fib_second.even? + fib_second += fib_first + fib_first = fib_second - fib_first +end + +p even_fib_sum diff --git a/project_euler/problem_20/sol1.rb b/project_euler/problem_20/sol1.rb new file mode 100644 index 0000000..d144ad9 --- /dev/null +++ b/project_euler/problem_20/sol1.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# n! means n x (n - 1) x ... x 3 x 2 x 1 + +# For example, 10! = 10 x 9 x ... x 3 x 2 x 1 = 3628800, +# and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. +# +# Find the sum of the digits in the number 100! + +# method to calculate factorial of a number +def factorial(number) + number.downto(1).reduce(:*) +end + +# fetch digits of factorial of `number` and find +# sum of all those digits, and prints the result on the console +number = 100 +puts factorial(number).digits.sum diff --git a/project_euler/problem_21/sol1.rb b/project_euler/problem_21/sol1.rb new file mode 100644 index 0000000..bedadaf --- /dev/null +++ b/project_euler/problem_21/sol1.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +# Let d(n) be defined as the sum of proper divisors of n +# (numbers less than n which divide evenly into n). +# If d(a) = b and d(b) = a, where a & b, then a and b are an amicable pair. +# and each of a and b are called amicable numbers. +# +# For example, +# +# The proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; +# therefore d(220) = 284. +# +# The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. +# +# Evaluate the sum of all the amicable numbers under 10000. + +# get list of all divisors of `number` +def get_divisors(number) + divisors = [] + (1..(Math.sqrt(number).to_i)).each do |num| + if (number % num).zero? + divisors << num + divisors << number / num + end + end + divisors +end + +# get list of all proper divisors of `number` i.e. removing `number` from +# the list of divisors +def get_proper_divisors(number) + divisors = get_divisors(number) + divisors.delete(number) + divisors +end + +# implementation of a method `d` as mentioned in the question +# i.e. finding sum of all proper divisors of `number` +def d(number) + get_proper_divisors(number).sum +end + +# given an upper `limit`, this method finds all amicable numbers +# under this `limit` +def find_amicable_numbers(limit) + result = [] + (1...limit).each do |a| + b = d(a) + res = d(b) + result.push(a) if (a == res) && (a != b) + end + result +end + +# calling `find_amicable_numbers` method and finding sum of all such numbers +# below 10000, and printing the result on the console +puts find_amicable_numbers(10_000).sum diff --git a/project_euler/problem_22/p022_names.txt b/project_euler/problem_22/p022_names.txt new file mode 100644 index 0000000..7b8986b --- /dev/null +++ b/project_euler/problem_22/p022_names.txt @@ -0,0 +1 @@ +"MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN","BETTY","HELEN","SANDRA","DONNA","CAROL","RUTH","SHARON","MICHELLE","LAURA","SARAH","KIMBERLY","DEBORAH","JESSICA","SHIRLEY","CYNTHIA","ANGELA","MELISSA","BRENDA","AMY","ANNA","REBECCA","VIRGINIA","KATHLEEN","PAMELA","MARTHA","DEBRA","AMANDA","STEPHANIE","CAROLYN","CHRISTINE","MARIE","JANET","CATHERINE","FRANCES","ANN","JOYCE","DIANE","ALICE","JULIE","HEATHER","TERESA","DORIS","GLORIA","EVELYN","JEAN","CHERYL","MILDRED","KATHERINE","JOAN","ASHLEY","JUDITH","ROSE","JANICE","KELLY","NICOLE","JUDY","CHRISTINA","KATHY","THERESA","BEVERLY","DENISE","TAMMY","IRENE","JANE","LORI","RACHEL","MARILYN","ANDREA","KATHRYN","LOUISE","SARA","ANNE","JACQUELINE","WANDA","BONNIE","JULIA","RUBY","LOIS","TINA","PHYLLIS","NORMA","PAULA","DIANA","ANNIE","LILLIAN","EMILY","ROBIN","PEGGY","CRYSTAL","GLADYS","RITA","DAWN","CONNIE","FLORENCE","TRACY","EDNA","TIFFANY","CARMEN","ROSA","CINDY","GRACE","WENDY","VICTORIA","EDITH","KIM","SHERRY","SYLVIA","JOSEPHINE","THELMA","SHANNON","SHEILA","ETHEL","ELLEN","ELAINE","MARJORIE","CARRIE","CHARLOTTE","MONICA","ESTHER","PAULINE","EMMA","JUANITA","ANITA","RHONDA","HAZEL","AMBER","EVA","DEBBIE","APRIL","LESLIE","CLARA","LUCILLE","JAMIE","JOANNE","ELEANOR","VALERIE","DANIELLE","MEGAN","ALICIA","SUZANNE","MICHELE","GAIL","BERTHA","DARLENE","VERONICA","JILL","ERIN","GERALDINE","LAUREN","CATHY","JOANN","LORRAINE","LYNN","SALLY","REGINA","ERICA","BEATRICE","DOLORES","BERNICE","AUDREY","YVONNE","ANNETTE","JUNE","SAMANTHA","MARION","DANA","STACY","ANA","RENEE","IDA","VIVIAN","ROBERTA","HOLLY","BRITTANY","MELANIE","LORETTA","YOLANDA","JEANETTE","LAURIE","KATIE","KRISTEN","VANESSA","ALMA","SUE","ELSIE","BETH","JEANNE","VICKI","CARLA","TARA","ROSEMARY","EILEEN","TERRI","GERTRUDE","LUCY","TONYA","ELLA","STACEY","WILMA","GINA","KRISTIN","JESSIE","NATALIE","AGNES","VERA","WILLIE","CHARLENE","BESSIE","DELORES","MELINDA","PEARL","ARLENE","MAUREEN","COLLEEN","ALLISON","TAMARA","JOY","GEORGIA","CONSTANCE","LILLIE","CLAUDIA","JACKIE","MARCIA","TANYA","NELLIE","MINNIE","MARLENE","HEIDI","GLENDA","LYDIA","VIOLA","COURTNEY","MARIAN","STELLA","CAROLINE","DORA","JO","VICKIE","MATTIE","TERRY","MAXINE","IRMA","MABEL","MARSHA","MYRTLE","LENA","CHRISTY","DEANNA","PATSY","HILDA","GWENDOLYN","JENNIE","NORA","MARGIE","NINA","CASSANDRA","LEAH","PENNY","KAY","PRISCILLA","NAOMI","CAROLE","BRANDY","OLGA","BILLIE","DIANNE","TRACEY","LEONA","JENNY","FELICIA","SONIA","MIRIAM","VELMA","BECKY","BOBBIE","VIOLET","KRISTINA","TONI","MISTY","MAE","SHELLY","DAISY","RAMONA","SHERRI","ERIKA","KATRINA","CLAIRE","LINDSEY","LINDSAY","GENEVA","GUADALUPE","BELINDA","MARGARITA","SHERYL","CORA","FAYE","ADA","NATASHA","SABRINA","ISABEL","MARGUERITE","HATTIE","HARRIET","MOLLY","CECILIA","KRISTI","BRANDI","BLANCHE","SANDY","ROSIE","JOANNA","IRIS","EUNICE","ANGIE","INEZ","LYNDA","MADELINE","AMELIA","ALBERTA","GENEVIEVE","MONIQUE","JODI","JANIE","MAGGIE","KAYLA","SONYA","JAN","LEE","KRISTINE","CANDACE","FANNIE","MARYANN","OPAL","ALISON","YVETTE","MELODY","LUZ","SUSIE","OLIVIA","FLORA","SHELLEY","KRISTY","MAMIE","LULA","LOLA","VERNA","BEULAH","ANTOINETTE","CANDICE","JUANA","JEANNETTE","PAM","KELLI","HANNAH","WHITNEY","BRIDGET","KARLA","CELIA","LATOYA","PATTY","SHELIA","GAYLE","DELLA","VICKY","LYNNE","SHERI","MARIANNE","KARA","JACQUELYN","ERMA","BLANCA","MYRA","LETICIA","PAT","KRISTA","ROXANNE","ANGELICA","JOHNNIE","ROBYN","FRANCIS","ADRIENNE","ROSALIE","ALEXANDRA","BROOKE","BETHANY","SADIE","BERNADETTE","TRACI","JODY","KENDRA","JASMINE","NICHOLE","RACHAEL","CHELSEA","MABLE","ERNESTINE","MURIEL","MARCELLA","ELENA","KRYSTAL","ANGELINA","NADINE","KARI","ESTELLE","DIANNA","PAULETTE","LORA","MONA","DOREEN","ROSEMARIE","ANGEL","DESIREE","ANTONIA","HOPE","GINGER","JANIS","BETSY","CHRISTIE","FREDA","MERCEDES","MEREDITH","LYNETTE","TERI","CRISTINA","EULA","LEIGH","MEGHAN","SOPHIA","ELOISE","ROCHELLE","GRETCHEN","CECELIA","RAQUEL","HENRIETTA","ALYSSA","JANA","KELLEY","GWEN","KERRY","JENNA","TRICIA","LAVERNE","OLIVE","ALEXIS","TASHA","SILVIA","ELVIRA","CASEY","DELIA","SOPHIE","KATE","PATTI","LORENA","KELLIE","SONJA","LILA","LANA","DARLA","MAY","MINDY","ESSIE","MANDY","LORENE","ELSA","JOSEFINA","JEANNIE","MIRANDA","DIXIE","LUCIA","MARTA","FAITH","LELA","JOHANNA","SHARI","CAMILLE","TAMI","SHAWNA","ELISA","EBONY","MELBA","ORA","NETTIE","TABITHA","OLLIE","JAIME","WINIFRED","KRISTIE","MARINA","ALISHA","AIMEE","RENA","MYRNA","MARLA","TAMMIE","LATASHA","BONITA","PATRICE","RONDA","SHERRIE","ADDIE","FRANCINE","DELORIS","STACIE","ADRIANA","CHERI","SHELBY","ABIGAIL","CELESTE","JEWEL","CARA","ADELE","REBEKAH","LUCINDA","DORTHY","CHRIS","EFFIE","TRINA","REBA","SHAWN","SALLIE","AURORA","LENORA","ETTA","LOTTIE","KERRI","TRISHA","NIKKI","ESTELLA","FRANCISCA","JOSIE","TRACIE","MARISSA","KARIN","BRITTNEY","JANELLE","LOURDES","LAUREL","HELENE","FERN","ELVA","CORINNE","KELSEY","INA","BETTIE","ELISABETH","AIDA","CAITLIN","INGRID","IVA","EUGENIA","CHRISTA","GOLDIE","CASSIE","MAUDE","JENIFER","THERESE","FRANKIE","DENA","LORNA","JANETTE","LATONYA","CANDY","MORGAN","CONSUELO","TAMIKA","ROSETTA","DEBORA","CHERIE","POLLY","DINA","JEWELL","FAY","JILLIAN","DOROTHEA","NELL","TRUDY","ESPERANZA","PATRICA","KIMBERLEY","SHANNA","HELENA","CAROLINA","CLEO","STEFANIE","ROSARIO","OLA","JANINE","MOLLIE","LUPE","ALISA","LOU","MARIBEL","SUSANNE","BETTE","SUSANA","ELISE","CECILE","ISABELLE","LESLEY","JOCELYN","PAIGE","JONI","RACHELLE","LEOLA","DAPHNE","ALTA","ESTER","PETRA","GRACIELA","IMOGENE","JOLENE","KEISHA","LACEY","GLENNA","GABRIELA","KERI","URSULA","LIZZIE","KIRSTEN","SHANA","ADELINE","MAYRA","JAYNE","JACLYN","GRACIE","SONDRA","CARMELA","MARISA","ROSALIND","CHARITY","TONIA","BEATRIZ","MARISOL","CLARICE","JEANINE","SHEENA","ANGELINE","FRIEDA","LILY","ROBBIE","SHAUNA","MILLIE","CLAUDETTE","CATHLEEN","ANGELIA","GABRIELLE","AUTUMN","KATHARINE","SUMMER","JODIE","STACI","LEA","CHRISTI","JIMMIE","JUSTINE","ELMA","LUELLA","MARGRET","DOMINIQUE","SOCORRO","RENE","MARTINA","MARGO","MAVIS","CALLIE","BOBBI","MARITZA","LUCILE","LEANNE","JEANNINE","DEANA","AILEEN","LORIE","LADONNA","WILLA","MANUELA","GALE","SELMA","DOLLY","SYBIL","ABBY","LARA","DALE","IVY","DEE","WINNIE","MARCY","LUISA","JERI","MAGDALENA","OFELIA","MEAGAN","AUDRA","MATILDA","LEILA","CORNELIA","BIANCA","SIMONE","BETTYE","RANDI","VIRGIE","LATISHA","BARBRA","GEORGINA","ELIZA","LEANN","BRIDGETTE","RHODA","HALEY","ADELA","NOLA","BERNADINE","FLOSSIE","ILA","GRETA","RUTHIE","NELDA","MINERVA","LILLY","TERRIE","LETHA","HILARY","ESTELA","VALARIE","BRIANNA","ROSALYN","EARLINE","CATALINA","AVA","MIA","CLARISSA","LIDIA","CORRINE","ALEXANDRIA","CONCEPCION","TIA","SHARRON","RAE","DONA","ERICKA","JAMI","ELNORA","CHANDRA","LENORE","NEVA","MARYLOU","MELISA","TABATHA","SERENA","AVIS","ALLIE","SOFIA","JEANIE","ODESSA","NANNIE","HARRIETT","LORAINE","PENELOPE","MILAGROS","EMILIA","BENITA","ALLYSON","ASHLEE","TANIA","TOMMIE","ESMERALDA","KARINA","EVE","PEARLIE","ZELMA","MALINDA","NOREEN","TAMEKA","SAUNDRA","HILLARY","AMIE","ALTHEA","ROSALINDA","JORDAN","LILIA","ALANA","GAY","CLARE","ALEJANDRA","ELINOR","MICHAEL","LORRIE","JERRI","DARCY","EARNESTINE","CARMELLA","TAYLOR","NOEMI","MARCIE","LIZA","ANNABELLE","LOUISA","EARLENE","MALLORY","CARLENE","NITA","SELENA","TANISHA","KATY","JULIANNE","JOHN","LAKISHA","EDWINA","MARICELA","MARGERY","KENYA","DOLLIE","ROXIE","ROSLYN","KATHRINE","NANETTE","CHARMAINE","LAVONNE","ILENE","KRIS","TAMMI","SUZETTE","CORINE","KAYE","JERRY","MERLE","CHRYSTAL","LINA","DEANNE","LILIAN","JULIANA","ALINE","LUANN","KASEY","MARYANNE","EVANGELINE","COLETTE","MELVA","LAWANDA","YESENIA","NADIA","MADGE","KATHIE","EDDIE","OPHELIA","VALERIA","NONA","MITZI","MARI","GEORGETTE","CLAUDINE","FRAN","ALISSA","ROSEANN","LAKEISHA","SUSANNA","REVA","DEIDRE","CHASITY","SHEREE","CARLY","JAMES","ELVIA","ALYCE","DEIRDRE","GENA","BRIANA","ARACELI","KATELYN","ROSANNE","WENDI","TESSA","BERTA","MARVA","IMELDA","MARIETTA","MARCI","LEONOR","ARLINE","SASHA","MADELYN","JANNA","JULIETTE","DEENA","AURELIA","JOSEFA","AUGUSTA","LILIANA","YOUNG","CHRISTIAN","LESSIE","AMALIA","SAVANNAH","ANASTASIA","VILMA","NATALIA","ROSELLA","LYNNETTE","CORINA","ALFREDA","LEANNA","CAREY","AMPARO","COLEEN","TAMRA","AISHA","WILDA","KARYN","CHERRY","QUEEN","MAURA","MAI","EVANGELINA","ROSANNA","HALLIE","ERNA","ENID","MARIANA","LACY","JULIET","JACKLYN","FREIDA","MADELEINE","MARA","HESTER","CATHRYN","LELIA","CASANDRA","BRIDGETT","ANGELITA","JANNIE","DIONNE","ANNMARIE","KATINA","BERYL","PHOEBE","MILLICENT","KATHERYN","DIANN","CARISSA","MARYELLEN","LIZ","LAURI","HELGA","GILDA","ADRIAN","RHEA","MARQUITA","HOLLIE","TISHA","TAMERA","ANGELIQUE","FRANCESCA","BRITNEY","KAITLIN","LOLITA","FLORINE","ROWENA","REYNA","TWILA","FANNY","JANELL","INES","CONCETTA","BERTIE","ALBA","BRIGITTE","ALYSON","VONDA","PANSY","ELBA","NOELLE","LETITIA","KITTY","DEANN","BRANDIE","LOUELLA","LETA","FELECIA","SHARLENE","LESA","BEVERLEY","ROBERT","ISABELLA","HERMINIA","TERRA","CELINA","TORI","OCTAVIA","JADE","DENICE","GERMAINE","SIERRA","MICHELL","CORTNEY","NELLY","DORETHA","SYDNEY","DEIDRA","MONIKA","LASHONDA","JUDI","CHELSEY","ANTIONETTE","MARGOT","BOBBY","ADELAIDE","NAN","LEEANN","ELISHA","DESSIE","LIBBY","KATHI","GAYLA","LATANYA","MINA","MELLISA","KIMBERLEE","JASMIN","RENAE","ZELDA","ELDA","MA","JUSTINA","GUSSIE","EMILIE","CAMILLA","ABBIE","ROCIO","KAITLYN","JESSE","EDYTHE","ASHLEIGH","SELINA","LAKESHA","GERI","ALLENE","PAMALA","MICHAELA","DAYNA","CARYN","ROSALIA","SUN","JACQULINE","REBECA","MARYBETH","KRYSTLE","IOLA","DOTTIE","BENNIE","BELLE","AUBREY","GRISELDA","ERNESTINA","ELIDA","ADRIANNE","DEMETRIA","DELMA","CHONG","JAQUELINE","DESTINY","ARLEEN","VIRGINA","RETHA","FATIMA","TILLIE","ELEANORE","CARI","TREVA","BIRDIE","WILHELMINA","ROSALEE","MAURINE","LATRICE","YONG","JENA","TARYN","ELIA","DEBBY","MAUDIE","JEANNA","DELILAH","CATRINA","SHONDA","HORTENCIA","THEODORA","TERESITA","ROBBIN","DANETTE","MARYJANE","FREDDIE","DELPHINE","BRIANNE","NILDA","DANNA","CINDI","BESS","IONA","HANNA","ARIEL","WINONA","VIDA","ROSITA","MARIANNA","WILLIAM","RACHEAL","GUILLERMINA","ELOISA","CELESTINE","CAREN","MALISSA","LONA","CHANTEL","SHELLIE","MARISELA","LEORA","AGATHA","SOLEDAD","MIGDALIA","IVETTE","CHRISTEN","ATHENA","JANEL","CHLOE","VEDA","PATTIE","TESSIE","TERA","MARILYNN","LUCRETIA","KARRIE","DINAH","DANIELA","ALECIA","ADELINA","VERNICE","SHIELA","PORTIA","MERRY","LASHAWN","DEVON","DARA","TAWANA","OMA","VERDA","CHRISTIN","ALENE","ZELLA","SANDI","RAFAELA","MAYA","KIRA","CANDIDA","ALVINA","SUZAN","SHAYLA","LYN","LETTIE","ALVA","SAMATHA","ORALIA","MATILDE","MADONNA","LARISSA","VESTA","RENITA","INDIA","DELOIS","SHANDA","PHILLIS","LORRI","ERLINDA","CRUZ","CATHRINE","BARB","ZOE","ISABELL","IONE","GISELA","CHARLIE","VALENCIA","ROXANNA","MAYME","KISHA","ELLIE","MELLISSA","DORRIS","DALIA","BELLA","ANNETTA","ZOILA","RETA","REINA","LAURETTA","KYLIE","CHRISTAL","PILAR","CHARLA","ELISSA","TIFFANI","TANA","PAULINA","LEOTA","BREANNA","JAYME","CARMEL","VERNELL","TOMASA","MANDI","DOMINGA","SANTA","MELODIE","LURA","ALEXA","TAMELA","RYAN","MIRNA","KERRIE","VENUS","NOEL","FELICITA","CRISTY","CARMELITA","BERNIECE","ANNEMARIE","TIARA","ROSEANNE","MISSY","CORI","ROXANA","PRICILLA","KRISTAL","JUNG","ELYSE","HAYDEE","ALETHA","BETTINA","MARGE","GILLIAN","FILOMENA","CHARLES","ZENAIDA","HARRIETTE","CARIDAD","VADA","UNA","ARETHA","PEARLINE","MARJORY","MARCELA","FLOR","EVETTE","ELOUISE","ALINA","TRINIDAD","DAVID","DAMARIS","CATHARINE","CARROLL","BELVA","NAKIA","MARLENA","LUANNE","LORINE","KARON","DORENE","DANITA","BRENNA","TATIANA","SAMMIE","LOUANN","LOREN","JULIANNA","ANDRIA","PHILOMENA","LUCILA","LEONORA","DOVIE","ROMONA","MIMI","JACQUELIN","GAYE","TONJA","MISTI","JOE","GENE","CHASTITY","STACIA","ROXANN","MICAELA","NIKITA","MEI","VELDA","MARLYS","JOHNNA","AURA","LAVERN","IVONNE","HAYLEY","NICKI","MAJORIE","HERLINDA","GEORGE","ALPHA","YADIRA","PERLA","GREGORIA","DANIEL","ANTONETTE","SHELLI","MOZELLE","MARIAH","JOELLE","CORDELIA","JOSETTE","CHIQUITA","TRISTA","LOUIS","LAQUITA","GEORGIANA","CANDI","SHANON","LONNIE","HILDEGARD","CECIL","VALENTINA","STEPHANY","MAGDA","KAROL","GERRY","GABRIELLA","TIANA","ROMA","RICHELLE","RAY","PRINCESS","OLETA","JACQUE","IDELLA","ALAINA","SUZANNA","JOVITA","BLAIR","TOSHA","RAVEN","NEREIDA","MARLYN","KYLA","JOSEPH","DELFINA","TENA","STEPHENIE","SABINA","NATHALIE","MARCELLE","GERTIE","DARLEEN","THEA","SHARONDA","SHANTEL","BELEN","VENESSA","ROSALINA","ONA","GENOVEVA","COREY","CLEMENTINE","ROSALBA","RENATE","RENATA","MI","IVORY","GEORGIANNA","FLOY","DORCAS","ARIANA","TYRA","THEDA","MARIAM","JULI","JESICA","DONNIE","VIKKI","VERLA","ROSELYN","MELVINA","JANNETTE","GINNY","DEBRAH","CORRIE","ASIA","VIOLETA","MYRTIS","LATRICIA","COLLETTE","CHARLEEN","ANISSA","VIVIANA","TWYLA","PRECIOUS","NEDRA","LATONIA","LAN","HELLEN","FABIOLA","ANNAMARIE","ADELL","SHARYN","CHANTAL","NIKI","MAUD","LIZETTE","LINDY","KIA","KESHA","JEANA","DANELLE","CHARLINE","CHANEL","CARROL","VALORIE","LIA","DORTHA","CRISTAL","SUNNY","LEONE","LEILANI","GERRI","DEBI","ANDRA","KESHIA","IMA","EULALIA","EASTER","DULCE","NATIVIDAD","LINNIE","KAMI","GEORGIE","CATINA","BROOK","ALDA","WINNIFRED","SHARLA","RUTHANN","MEAGHAN","MAGDALENE","LISSETTE","ADELAIDA","VENITA","TRENA","SHIRLENE","SHAMEKA","ELIZEBETH","DIAN","SHANTA","MICKEY","LATOSHA","CARLOTTA","WINDY","SOON","ROSINA","MARIANN","LEISA","JONNIE","DAWNA","CATHIE","BILLY","ASTRID","SIDNEY","LAUREEN","JANEEN","HOLLI","FAWN","VICKEY","TERESSA","SHANTE","RUBYE","MARCELINA","CHANDA","CARY","TERESE","SCARLETT","MARTY","MARNIE","LULU","LISETTE","JENIFFER","ELENOR","DORINDA","DONITA","CARMAN","BERNITA","ALTAGRACIA","ALETA","ADRIANNA","ZORAIDA","RONNIE","NICOLA","LYNDSEY","KENDALL","JANINA","CHRISSY","AMI","STARLA","PHYLIS","PHUONG","KYRA","CHARISSE","BLANCH","SANJUANITA","RONA","NANCI","MARILEE","MARANDA","CORY","BRIGETTE","SANJUANA","MARITA","KASSANDRA","JOYCELYN","IRA","FELIPA","CHELSIE","BONNY","MIREYA","LORENZA","KYONG","ILEANA","CANDELARIA","TONY","TOBY","SHERIE","OK","MARK","LUCIE","LEATRICE","LAKESHIA","GERDA","EDIE","BAMBI","MARYLIN","LAVON","HORTENSE","GARNET","EVIE","TRESSA","SHAYNA","LAVINA","KYUNG","JEANETTA","SHERRILL","SHARA","PHYLISS","MITTIE","ANABEL","ALESIA","THUY","TAWANDA","RICHARD","JOANIE","TIFFANIE","LASHANDA","KARISSA","ENRIQUETA","DARIA","DANIELLA","CORINNA","ALANNA","ABBEY","ROXANE","ROSEANNA","MAGNOLIA","LIDA","KYLE","JOELLEN","ERA","CORAL","CARLEEN","TRESA","PEGGIE","NOVELLA","NILA","MAYBELLE","JENELLE","CARINA","NOVA","MELINA","MARQUERITE","MARGARETTE","JOSEPHINA","EVONNE","DEVIN","CINTHIA","ALBINA","TOYA","TAWNYA","SHERITA","SANTOS","MYRIAM","LIZABETH","LISE","KEELY","JENNI","GISELLE","CHERYLE","ARDITH","ARDIS","ALESHA","ADRIANE","SHAINA","LINNEA","KAROLYN","HONG","FLORIDA","FELISHA","DORI","DARCI","ARTIE","ARMIDA","ZOLA","XIOMARA","VERGIE","SHAMIKA","NENA","NANNETTE","MAXIE","LOVIE","JEANE","JAIMIE","INGE","FARRAH","ELAINA","CAITLYN","STARR","FELICITAS","CHERLY","CARYL","YOLONDA","YASMIN","TEENA","PRUDENCE","PENNIE","NYDIA","MACKENZIE","ORPHA","MARVEL","LIZBETH","LAURETTE","JERRIE","HERMELINDA","CAROLEE","TIERRA","MIRIAN","META","MELONY","KORI","JENNETTE","JAMILA","ENA","ANH","YOSHIKO","SUSANNAH","SALINA","RHIANNON","JOLEEN","CRISTINE","ASHTON","ARACELY","TOMEKA","SHALONDA","MARTI","LACIE","KALA","JADA","ILSE","HAILEY","BRITTANI","ZONA","SYBLE","SHERRYL","RANDY","NIDIA","MARLO","KANDICE","KANDI","DEB","DEAN","AMERICA","ALYCIA","TOMMY","RONNA","NORENE","MERCY","JOSE","INGEBORG","GIOVANNA","GEMMA","CHRISTEL","AUDRY","ZORA","VITA","VAN","TRISH","STEPHAINE","SHIRLEE","SHANIKA","MELONIE","MAZIE","JAZMIN","INGA","HOA","HETTIE","GERALYN","FONDA","ESTRELLA","ADELLA","SU","SARITA","RINA","MILISSA","MARIBETH","GOLDA","EVON","ETHELYN","ENEDINA","CHERISE","CHANA","VELVA","TAWANNA","SADE","MIRTA","LI","KARIE","JACINTA","ELNA","DAVINA","CIERRA","ASHLIE","ALBERTHA","TANESHA","STEPHANI","NELLE","MINDI","LU","LORINDA","LARUE","FLORENE","DEMETRA","DEDRA","CIARA","CHANTELLE","ASHLY","SUZY","ROSALVA","NOELIA","LYDA","LEATHA","KRYSTYNA","KRISTAN","KARRI","DARLINE","DARCIE","CINDA","CHEYENNE","CHERRIE","AWILDA","ALMEDA","ROLANDA","LANETTE","JERILYN","GISELE","EVALYN","CYNDI","CLETA","CARIN","ZINA","ZENA","VELIA","TANIKA","PAUL","CHARISSA","THOMAS","TALIA","MARGARETE","LAVONDA","KAYLEE","KATHLENE","JONNA","IRENA","ILONA","IDALIA","CANDIS","CANDANCE","BRANDEE","ANITRA","ALIDA","SIGRID","NICOLETTE","MARYJO","LINETTE","HEDWIG","CHRISTIANA","CASSIDY","ALEXIA","TRESSIE","MODESTA","LUPITA","LITA","GLADIS","EVELIA","DAVIDA","CHERRI","CECILY","ASHELY","ANNABEL","AGUSTINA","WANITA","SHIRLY","ROSAURA","HULDA","EUN","BAILEY","YETTA","VERONA","THOMASINA","SIBYL","SHANNAN","MECHELLE","LUE","LEANDRA","LANI","KYLEE","KANDY","JOLYNN","FERNE","EBONI","CORENE","ALYSIA","ZULA","NADA","MOIRA","LYNDSAY","LORRETTA","JUAN","JAMMIE","HORTENSIA","GAYNELL","CAMERON","ADRIA","VINA","VICENTA","TANGELA","STEPHINE","NORINE","NELLA","LIANA","LESLEE","KIMBERELY","ILIANA","GLORY","FELICA","EMOGENE","ELFRIEDE","EDEN","EARTHA","CARMA","BEA","OCIE","MARRY","LENNIE","KIARA","JACALYN","CARLOTA","ARIELLE","YU","STAR","OTILIA","KIRSTIN","KACEY","JOHNETTA","JOEY","JOETTA","JERALDINE","JAUNITA","ELANA","DORTHEA","CAMI","AMADA","ADELIA","VERNITA","TAMAR","SIOBHAN","RENEA","RASHIDA","OUIDA","ODELL","NILSA","MERYL","KRISTYN","JULIETA","DANICA","BREANNE","AUREA","ANGLEA","SHERRON","ODETTE","MALIA","LORELEI","LIN","LEESA","KENNA","KATHLYN","FIONA","CHARLETTE","SUZIE","SHANTELL","SABRA","RACQUEL","MYONG","MIRA","MARTINE","LUCIENNE","LAVADA","JULIANN","JOHNIE","ELVERA","DELPHIA","CLAIR","CHRISTIANE","CHAROLETTE","CARRI","AUGUSTINE","ASHA","ANGELLA","PAOLA","NINFA","LEDA","LAI","EDA","SUNSHINE","STEFANI","SHANELL","PALMA","MACHELLE","LISSA","KECIA","KATHRYNE","KARLENE","JULISSA","JETTIE","JENNIFFER","HUI","CORRINA","CHRISTOPHER","CAROLANN","ALENA","TESS","ROSARIA","MYRTICE","MARYLEE","LIANE","KENYATTA","JUDIE","JANEY","IN","ELMIRA","ELDORA","DENNA","CRISTI","CATHI","ZAIDA","VONNIE","VIVA","VERNIE","ROSALINE","MARIELA","LUCIANA","LESLI","KARAN","FELICE","DENEEN","ADINA","WYNONA","TARSHA","SHERON","SHASTA","SHANITA","SHANI","SHANDRA","RANDA","PINKIE","PARIS","NELIDA","MARILOU","LYLA","LAURENE","LACI","JOI","JANENE","DOROTHA","DANIELE","DANI","CAROLYNN","CARLYN","BERENICE","AYESHA","ANNELIESE","ALETHEA","THERSA","TAMIKO","RUFINA","OLIVA","MOZELL","MARYLYN","MADISON","KRISTIAN","KATHYRN","KASANDRA","KANDACE","JANAE","GABRIEL","DOMENICA","DEBBRA","DANNIELLE","CHUN","BUFFY","BARBIE","ARCELIA","AJA","ZENOBIA","SHAREN","SHAREE","PATRICK","PAGE","MY","LAVINIA","KUM","KACIE","JACKELINE","HUONG","FELISA","EMELIA","ELEANORA","CYTHIA","CRISTIN","CLYDE","CLARIBEL","CARON","ANASTACIA","ZULMA","ZANDRA","YOKO","TENISHA","SUSANN","SHERILYN","SHAY","SHAWANDA","SABINE","ROMANA","MATHILDA","LINSEY","KEIKO","JOANA","ISELA","GRETTA","GEORGETTA","EUGENIE","DUSTY","DESIRAE","DELORA","CORAZON","ANTONINA","ANIKA","WILLENE","TRACEE","TAMATHA","REGAN","NICHELLE","MICKIE","MAEGAN","LUANA","LANITA","KELSIE","EDELMIRA","BREE","AFTON","TEODORA","TAMIE","SHENA","MEG","LINH","KELI","KACI","DANYELLE","BRITT","ARLETTE","ALBERTINE","ADELLE","TIFFINY","STORMY","SIMONA","NUMBERS","NICOLASA","NICHOL","NIA","NAKISHA","MEE","MAIRA","LOREEN","KIZZY","JOHNNY","JAY","FALLON","CHRISTENE","BOBBYE","ANTHONY","YING","VINCENZA","TANJA","RUBIE","RONI","QUEENIE","MARGARETT","KIMBERLI","IRMGARD","IDELL","HILMA","EVELINA","ESTA","EMILEE","DENNISE","DANIA","CARL","CARIE","ANTONIO","WAI","SANG","RISA","RIKKI","PARTICIA","MUI","MASAKO","MARIO","LUVENIA","LOREE","LONI","LIEN","KEVIN","GIGI","FLORENCIA","DORIAN","DENITA","DALLAS","CHI","BILLYE","ALEXANDER","TOMIKA","SHARITA","RANA","NIKOLE","NEOMA","MARGARITE","MADALYN","LUCINA","LAILA","KALI","JENETTE","GABRIELE","EVELYNE","ELENORA","CLEMENTINA","ALEJANDRINA","ZULEMA","VIOLETTE","VANNESSA","THRESA","RETTA","PIA","PATIENCE","NOELLA","NICKIE","JONELL","DELTA","CHUNG","CHAYA","CAMELIA","BETHEL","ANYA","ANDREW","THANH","SUZANN","SPRING","SHU","MILA","LILLA","LAVERNA","KEESHA","KATTIE","GIA","GEORGENE","EVELINE","ESTELL","ELIZBETH","VIVIENNE","VALLIE","TRUDIE","STEPHANE","MICHEL","MAGALY","MADIE","KENYETTA","KARREN","JANETTA","HERMINE","HARMONY","DRUCILLA","DEBBI","CELESTINA","CANDIE","BRITNI","BECKIE","AMINA","ZITA","YUN","YOLANDE","VIVIEN","VERNETTA","TRUDI","SOMMER","PEARLE","PATRINA","OSSIE","NICOLLE","LOYCE","LETTY","LARISA","KATHARINA","JOSELYN","JONELLE","JENELL","IESHA","HEIDE","FLORINDA","FLORENTINA","FLO","ELODIA","DORINE","BRUNILDA","BRIGID","ASHLI","ARDELLA","TWANA","THU","TARAH","SUNG","SHEA","SHAVON","SHANE","SERINA","RAYNA","RAMONITA","NGA","MARGURITE","LUCRECIA","KOURTNEY","KATI","JESUS","JESENIA","DIAMOND","CRISTA","AYANA","ALICA","ALIA","VINNIE","SUELLEN","ROMELIA","RACHELL","PIPER","OLYMPIA","MICHIKO","KATHALEEN","JOLIE","JESSI","JANESSA","HANA","HA","ELEASE","CARLETTA","BRITANY","SHONA","SALOME","ROSAMOND","REGENA","RAINA","NGOC","NELIA","LOUVENIA","LESIA","LATRINA","LATICIA","LARHONDA","JINA","JACKI","HOLLIS","HOLLEY","EMMY","DEEANN","CORETTA","ARNETTA","VELVET","THALIA","SHANICE","NETA","MIKKI","MICKI","LONNA","LEANA","LASHUNDA","KILEY","JOYE","JACQULYN","IGNACIA","HYUN","HIROKO","HENRY","HENRIETTE","ELAYNE","DELINDA","DARNELL","DAHLIA","COREEN","CONSUELA","CONCHITA","CELINE","BABETTE","AYANNA","ANETTE","ALBERTINA","SKYE","SHAWNEE","SHANEKA","QUIANA","PAMELIA","MIN","MERRI","MERLENE","MARGIT","KIESHA","KIERA","KAYLENE","JODEE","JENISE","ERLENE","EMMIE","ELSE","DARYL","DALILA","DAISEY","CODY","CASIE","BELIA","BABARA","VERSIE","VANESA","SHELBA","SHAWNDA","SAM","NORMAN","NIKIA","NAOMA","MARNA","MARGERET","MADALINE","LAWANA","KINDRA","JUTTA","JAZMINE","JANETT","HANNELORE","GLENDORA","GERTRUD","GARNETT","FREEDA","FREDERICA","FLORANCE","FLAVIA","DENNIS","CARLINE","BEVERLEE","ANJANETTE","VALDA","TRINITY","TAMALA","STEVIE","SHONNA","SHA","SARINA","ONEIDA","MICAH","MERILYN","MARLEEN","LURLINE","LENNA","KATHERIN","JIN","JENI","HAE","GRACIA","GLADY","FARAH","ERIC","ENOLA","EMA","DOMINQUE","DEVONA","DELANA","CECILA","CAPRICE","ALYSHA","ALI","ALETHIA","VENA","THERESIA","TAWNY","SONG","SHAKIRA","SAMARA","SACHIKO","RACHELE","PAMELLA","NICKY","MARNI","MARIEL","MAREN","MALISA","LIGIA","LERA","LATORIA","LARAE","KIMBER","KATHERN","KAREY","JENNEFER","JANETH","HALINA","FREDIA","DELISA","DEBROAH","CIERA","CHIN","ANGELIKA","ANDREE","ALTHA","YEN","VIVAN","TERRESA","TANNA","SUK","SUDIE","SOO","SIGNE","SALENA","RONNI","REBBECCA","MYRTIE","MCKENZIE","MALIKA","MAIDA","LOAN","LEONARDA","KAYLEIGH","FRANCE","ETHYL","ELLYN","DAYLE","CAMMIE","BRITTNI","BIRGIT","AVELINA","ASUNCION","ARIANNA","AKIKO","VENICE","TYESHA","TONIE","TIESHA","TAKISHA","STEFFANIE","SINDY","SANTANA","MEGHANN","MANDA","MACIE","LADY","KELLYE","KELLEE","JOSLYN","JASON","INGER","INDIRA","GLINDA","GLENNIS","FERNANDA","FAUSTINA","ENEIDA","ELICIA","DOT","DIGNA","DELL","ARLETTA","ANDRE","WILLIA","TAMMARA","TABETHA","SHERRELL","SARI","REFUGIO","REBBECA","PAULETTA","NIEVES","NATOSHA","NAKITA","MAMMIE","KENISHA","KAZUKO","KASSIE","GARY","EARLEAN","DAPHINE","CORLISS","CLOTILDE","CAROLYNE","BERNETTA","AUGUSTINA","AUDREA","ANNIS","ANNABELL","YAN","TENNILLE","TAMICA","SELENE","SEAN","ROSANA","REGENIA","QIANA","MARKITA","MACY","LEEANNE","LAURINE","KYM","JESSENIA","JANITA","GEORGINE","GENIE","EMIKO","ELVIE","DEANDRA","DAGMAR","CORIE","COLLEN","CHERISH","ROMAINE","PORSHA","PEARLENE","MICHELINE","MERNA","MARGORIE","MARGARETTA","LORE","KENNETH","JENINE","HERMINA","FREDERICKA","ELKE","DRUSILLA","DORATHY","DIONE","DESIRE","CELENA","BRIGIDA","ANGELES","ALLEGRA","THEO","TAMEKIA","SYNTHIA","STEPHEN","SOOK","SLYVIA","ROSANN","REATHA","RAYE","MARQUETTA","MARGART","LING","LAYLA","KYMBERLY","KIANA","KAYLEEN","KATLYN","KARMEN","JOELLA","IRINA","EMELDA","ELENI","DETRA","CLEMMIE","CHERYLL","CHANTELL","CATHEY","ARNITA","ARLA","ANGLE","ANGELIC","ALYSE","ZOFIA","THOMASINE","TENNIE","SON","SHERLY","SHERLEY","SHARYL","REMEDIOS","PETRINA","NICKOLE","MYUNG","MYRLE","MOZELLA","LOUANNE","LISHA","LATIA","LANE","KRYSTA","JULIENNE","JOEL","JEANENE","JACQUALINE","ISAURA","GWENDA","EARLEEN","DONALD","CLEOPATRA","CARLIE","AUDIE","ANTONIETTA","ALISE","ALEX","VERDELL","VAL","TYLER","TOMOKO","THAO","TALISHA","STEVEN","SO","SHEMIKA","SHAUN","SCARLET","SAVANNA","SANTINA","ROSIA","RAEANN","ODILIA","NANA","MINNA","MAGAN","LYNELLE","LE","KARMA","JOEANN","IVANA","INELL","ILANA","HYE","HONEY","HEE","GUDRUN","FRANK","DREAMA","CRISSY","CHANTE","CARMELINA","ARVILLA","ARTHUR","ANNAMAE","ALVERA","ALEIDA","AARON","YEE","YANIRA","VANDA","TIANNA","TAM","STEFANIA","SHIRA","PERRY","NICOL","NANCIE","MONSERRATE","MINH","MELYNDA","MELANY","MATTHEW","LOVELLA","LAURE","KIRBY","KACY","JACQUELYNN","HYON","GERTHA","FRANCISCO","ELIANA","CHRISTENA","CHRISTEEN","CHARISE","CATERINA","CARLEY","CANDYCE","ARLENA","AMMIE","YANG","WILLETTE","VANITA","TUYET","TINY","SYREETA","SILVA","SCOTT","RONALD","PENNEY","NYLA","MICHAL","MAURICE","MARYAM","MARYA","MAGEN","LUDIE","LOMA","LIVIA","LANELL","KIMBERLIE","JULEE","DONETTA","DIEDRA","DENISHA","DEANE","DAWNE","CLARINE","CHERRYL","BRONWYN","BRANDON","ALLA","VALERY","TONDA","SUEANN","SORAYA","SHOSHANA","SHELA","SHARLEEN","SHANELLE","NERISSA","MICHEAL","MERIDITH","MELLIE","MAYE","MAPLE","MAGARET","LUIS","LILI","LEONILA","LEONIE","LEEANNA","LAVONIA","LAVERA","KRISTEL","KATHEY","KATHE","JUSTIN","JULIAN","JIMMY","JANN","ILDA","HILDRED","HILDEGARDE","GENIA","FUMIKO","EVELIN","ERMELINDA","ELLY","DUNG","DOLORIS","DIONNA","DANAE","BERNEICE","ANNICE","ALIX","VERENA","VERDIE","TRISTAN","SHAWNNA","SHAWANA","SHAUNNA","ROZELLA","RANDEE","RANAE","MILAGRO","LYNELL","LUISE","LOUIE","LOIDA","LISBETH","KARLEEN","JUNITA","JONA","ISIS","HYACINTH","HEDY","GWENN","ETHELENE","ERLINE","EDWARD","DONYA","DOMONIQUE","DELICIA","DANNETTE","CICELY","BRANDA","BLYTHE","BETHANN","ASHLYN","ANNALEE","ALLINE","YUKO","VELLA","TRANG","TOWANDA","TESHA","SHERLYN","NARCISA","MIGUELINA","MERI","MAYBELL","MARLANA","MARGUERITA","MADLYN","LUNA","LORY","LORIANN","LIBERTY","LEONORE","LEIGHANN","LAURICE","LATESHA","LARONDA","KATRICE","KASIE","KARL","KALEY","JADWIGA","GLENNIE","GEARLDINE","FRANCINA","EPIFANIA","DYAN","DORIE","DIEDRE","DENESE","DEMETRICE","DELENA","DARBY","CRISTIE","CLEORA","CATARINA","CARISA","BERNIE","BARBERA","ALMETA","TRULA","TEREASA","SOLANGE","SHEILAH","SHAVONNE","SANORA","ROCHELL","MATHILDE","MARGARETA","MAIA","LYNSEY","LAWANNA","LAUNA","KENA","KEENA","KATIA","JAMEY","GLYNDA","GAYLENE","ELVINA","ELANOR","DANUTA","DANIKA","CRISTEN","CORDIE","COLETTA","CLARITA","CARMON","BRYNN","AZUCENA","AUNDREA","ANGELE","YI","WALTER","VERLIE","VERLENE","TAMESHA","SILVANA","SEBRINA","SAMIRA","REDA","RAYLENE","PENNI","PANDORA","NORAH","NOMA","MIREILLE","MELISSIA","MARYALICE","LARAINE","KIMBERY","KARYL","KARINE","KAM","JOLANDA","JOHANA","JESUSA","JALEESA","JAE","JACQUELYNE","IRISH","ILUMINADA","HILARIA","HANH","GENNIE","FRANCIE","FLORETTA","EXIE","EDDA","DREMA","DELPHA","BEV","BARBAR","ASSUNTA","ARDELL","ANNALISA","ALISIA","YUKIKO","YOLANDO","WONDA","WEI","WALTRAUD","VETA","TEQUILA","TEMEKA","TAMEIKA","SHIRLEEN","SHENITA","PIEDAD","OZELLA","MIRTHA","MARILU","KIMIKO","JULIANE","JENICE","JEN","JANAY","JACQUILINE","HILDE","FE","FAE","EVAN","EUGENE","ELOIS","ECHO","DEVORAH","CHAU","BRINDA","BETSEY","ARMINDA","ARACELIS","APRYL","ANNETT","ALISHIA","VEOLA","USHA","TOSHIKO","THEOLA","TASHIA","TALITHA","SHERY","RUDY","RENETTA","REIKO","RASHEEDA","OMEGA","OBDULIA","MIKA","MELAINE","MEGGAN","MARTIN","MARLEN","MARGET","MARCELINE","MANA","MAGDALEN","LIBRADA","LEZLIE","LEXIE","LATASHIA","LASANDRA","KELLE","ISIDRA","ISA","INOCENCIA","GWYN","FRANCOISE","ERMINIA","ERINN","DIMPLE","DEVORA","CRISELDA","ARMANDA","ARIE","ARIANE","ANGELO","ANGELENA","ALLEN","ALIZA","ADRIENE","ADALINE","XOCHITL","TWANNA","TRAN","TOMIKO","TAMISHA","TAISHA","SUSY","SIU","RUTHA","ROXY","RHONA","RAYMOND","OTHA","NORIKO","NATASHIA","MERRIE","MELVIN","MARINDA","MARIKO","MARGERT","LORIS","LIZZETTE","LEISHA","KAILA","KA","JOANNIE","JERRICA","JENE","JANNET","JANEE","JACINDA","HERTA","ELENORE","DORETTA","DELAINE","DANIELL","CLAUDIE","CHINA","BRITTA","APOLONIA","AMBERLY","ALEASE","YURI","YUK","WEN","WANETA","UTE","TOMI","SHARRI","SANDIE","ROSELLE","REYNALDA","RAGUEL","PHYLICIA","PATRIA","OLIMPIA","ODELIA","MITZIE","MITCHELL","MISS","MINDA","MIGNON","MICA","MENDY","MARIVEL","MAILE","LYNETTA","LAVETTE","LAURYN","LATRISHA","LAKIESHA","KIERSTEN","KARY","JOSPHINE","JOLYN","JETTA","JANISE","JACQUIE","IVELISSE","GLYNIS","GIANNA","GAYNELLE","EMERALD","DEMETRIUS","DANYELL","DANILLE","DACIA","CORALEE","CHER","CEOLA","BRETT","BELL","ARIANNE","ALESHIA","YUNG","WILLIEMAE","TROY","TRINH","THORA","TAI","SVETLANA","SHERIKA","SHEMEKA","SHAUNDA","ROSELINE","RICKI","MELDA","MALLIE","LAVONNA","LATINA","LARRY","LAQUANDA","LALA","LACHELLE","KLARA","KANDIS","JOHNA","JEANMARIE","JAYE","HANG","GRAYCE","GERTUDE","EMERITA","EBONIE","CLORINDA","CHING","CHERY","CAROLA","BREANN","BLOSSOM","BERNARDINE","BECKI","ARLETHA","ARGELIA","ARA","ALITA","YULANDA","YON","YESSENIA","TOBI","TASIA","SYLVIE","SHIRL","SHIRELY","SHERIDAN","SHELLA","SHANTELLE","SACHA","ROYCE","REBECKA","REAGAN","PROVIDENCIA","PAULENE","MISHA","MIKI","MARLINE","MARICA","LORITA","LATOYIA","LASONYA","KERSTIN","KENDA","KEITHA","KATHRIN","JAYMIE","JACK","GRICELDA","GINETTE","ERYN","ELINA","ELFRIEDA","DANYEL","CHEREE","CHANELLE","BARRIE","AVERY","AURORE","ANNAMARIA","ALLEEN","AILENE","AIDE","YASMINE","VASHTI","VALENTINE","TREASA","TORY","TIFFANEY","SHERYLL","SHARIE","SHANAE","SAU","RAISA","PA","NEDA","MITSUKO","MIRELLA","MILDA","MARYANNA","MARAGRET","MABELLE","LUETTA","LORINA","LETISHA","LATARSHA","LANELLE","LAJUANA","KRISSY","KARLY","KARENA","JON","JESSIKA","JERICA","JEANELLE","JANUARY","JALISA","JACELYN","IZOLA","IVEY","GREGORY","EUNA","ETHA","DREW","DOMITILA","DOMINICA","DAINA","CREOLA","CARLI","CAMIE","BUNNY","BRITTNY","ASHANTI","ANISHA","ALEEN","ADAH","YASUKO","WINTER","VIKI","VALRIE","TONA","TINISHA","THI","TERISA","TATUM","TANEKA","SIMONNE","SHALANDA","SERITA","RESSIE","REFUGIA","PAZ","OLENE","NA","MERRILL","MARGHERITA","MANDIE","MAN","MAIRE","LYNDIA","LUCI","LORRIANE","LORETA","LEONIA","LAVONA","LASHAWNDA","LAKIA","KYOKO","KRYSTINA","KRYSTEN","KENIA","KELSI","JUDE","JEANICE","ISOBEL","GEORGIANN","GENNY","FELICIDAD","EILENE","DEON","DELOISE","DEEDEE","DANNIE","CONCEPTION","CLORA","CHERILYN","CHANG","CALANDRA","BERRY","ARMANDINA","ANISA","ULA","TIMOTHY","TIERA","THERESSA","STEPHANIA","SIMA","SHYLA","SHONTA","SHERA","SHAQUITA","SHALA","SAMMY","ROSSANA","NOHEMI","NERY","MORIAH","MELITA","MELIDA","MELANI","MARYLYNN","MARISHA","MARIETTE","MALORIE","MADELENE","LUDIVINA","LORIA","LORETTE","LORALEE","LIANNE","LEON","LAVENIA","LAURINDA","LASHON","KIT","KIMI","KEILA","KATELYNN","KAI","JONE","JOANE","JI","JAYNA","JANELLA","JA","HUE","HERTHA","FRANCENE","ELINORE","DESPINA","DELSIE","DEEDRA","CLEMENCIA","CARRY","CAROLIN","CARLOS","BULAH","BRITTANIE","BOK","BLONDELL","BIBI","BEAULAH","BEATA","ANNITA","AGRIPINA","VIRGEN","VALENE","UN","TWANDA","TOMMYE","TOI","TARRA","TARI","TAMMERA","SHAKIA","SADYE","RUTHANNE","ROCHEL","RIVKA","PURA","NENITA","NATISHA","MING","MERRILEE","MELODEE","MARVIS","LUCILLA","LEENA","LAVETA","LARITA","LANIE","KEREN","ILEEN","GEORGEANN","GENNA","GENESIS","FRIDA","EWA","EUFEMIA","EMELY","ELA","EDYTH","DEONNA","DEADRA","DARLENA","CHANELL","CHAN","CATHERN","CASSONDRA","CASSAUNDRA","BERNARDA","BERNA","ARLINDA","ANAMARIA","ALBERT","WESLEY","VERTIE","VALERI","TORRI","TATYANA","STASIA","SHERISE","SHERILL","SEASON","SCOTTIE","SANDA","RUTHE","ROSY","ROBERTO","ROBBI","RANEE","QUYEN","PEARLY","PALMIRA","ONITA","NISHA","NIESHA","NIDA","NEVADA","NAM","MERLYN","MAYOLA","MARYLOUISE","MARYLAND","MARX","MARTH","MARGENE","MADELAINE","LONDA","LEONTINE","LEOMA","LEIA","LAWRENCE","LAURALEE","LANORA","LAKITA","KIYOKO","KETURAH","KATELIN","KAREEN","JONIE","JOHNETTE","JENEE","JEANETT","IZETTA","HIEDI","HEIKE","HASSIE","HAROLD","GIUSEPPINA","GEORGANN","FIDELA","FERNANDE","ELWANDA","ELLAMAE","ELIZ","DUSTI","DOTTY","CYNDY","CORALIE","CELESTA","ARGENTINA","ALVERTA","XENIA","WAVA","VANETTA","TORRIE","TASHINA","TANDY","TAMBRA","TAMA","STEPANIE","SHILA","SHAUNTA","SHARAN","SHANIQUA","SHAE","SETSUKO","SERAFINA","SANDEE","ROSAMARIA","PRISCILA","OLINDA","NADENE","MUOI","MICHELINA","MERCEDEZ","MARYROSE","MARIN","MARCENE","MAO","MAGALI","MAFALDA","LOGAN","LINN","LANNIE","KAYCE","KAROLINE","KAMILAH","KAMALA","JUSTA","JOLINE","JENNINE","JACQUETTA","IRAIDA","GERALD","GEORGEANNA","FRANCHESCA","FAIRY","EMELINE","ELANE","EHTEL","EARLIE","DULCIE","DALENE","CRIS","CLASSIE","CHERE","CHARIS","CAROYLN","CARMINA","CARITA","BRIAN","BETHANIE","AYAKO","ARICA","AN","ALYSA","ALESSANDRA","AKILAH","ADRIEN","ZETTA","YOULANDA","YELENA","YAHAIRA","XUAN","WENDOLYN","VICTOR","TIJUANA","TERRELL","TERINA","TERESIA","SUZI","SUNDAY","SHERELL","SHAVONDA","SHAUNTE","SHARDA","SHAKITA","SENA","RYANN","RUBI","RIVA","REGINIA","REA","RACHAL","PARTHENIA","PAMULA","MONNIE","MONET","MICHAELE","MELIA","MARINE","MALKA","MAISHA","LISANDRA","LEO","LEKISHA","LEAN","LAURENCE","LAKENDRA","KRYSTIN","KORTNEY","KIZZIE","KITTIE","KERA","KENDAL","KEMBERLY","KANISHA","JULENE","JULE","JOSHUA","JOHANNE","JEFFREY","JAMEE","HAN","HALLEY","GIDGET","GALINA","FREDRICKA","FLETA","FATIMAH","EUSEBIA","ELZA","ELEONORE","DORTHEY","DORIA","DONELLA","DINORAH","DELORSE","CLARETHA","CHRISTINIA","CHARLYN","BONG","BELKIS","AZZIE","ANDERA","AIKO","ADENA","YER","YAJAIRA","WAN","VANIA","ULRIKE","TOSHIA","TIFANY","STEFANY","SHIZUE","SHENIKA","SHAWANNA","SHAROLYN","SHARILYN","SHAQUANA","SHANTAY","SEE","ROZANNE","ROSELEE","RICKIE","REMONA","REANNA","RAELENE","QUINN","PHUNG","PETRONILA","NATACHA","NANCEY","MYRL","MIYOKO","MIESHA","MERIDETH","MARVELLA","MARQUITTA","MARHTA","MARCHELLE","LIZETH","LIBBIE","LAHOMA","LADAWN","KINA","KATHELEEN","KATHARYN","KARISA","KALEIGH","JUNIE","JULIEANN","JOHNSIE","JANEAN","JAIMEE","JACKQUELINE","HISAKO","HERMA","HELAINE","GWYNETH","GLENN","GITA","EUSTOLIA","EMELINA","ELIN","EDRIS","DONNETTE","DONNETTA","DIERDRE","DENAE","DARCEL","CLAUDE","CLARISA","CINDERELLA","CHIA","CHARLESETTA","CHARITA","CELSA","CASSY","CASSI","CARLEE","BRUNA","BRITTANEY","BRANDE","BILLI","BAO","ANTONETTA","ANGLA","ANGELYN","ANALISA","ALANE","WENONA","WENDIE","VERONIQUE","VANNESA","TOBIE","TEMPIE","SUMIKO","SULEMA","SPARKLE","SOMER","SHEBA","SHAYNE","SHARICE","SHANEL","SHALON","SAGE","ROY","ROSIO","ROSELIA","RENAY","REMA","REENA","PORSCHE","PING","PEG","OZIE","ORETHA","ORALEE","ODA","NU","NGAN","NAKESHA","MILLY","MARYBELLE","MARLIN","MARIS","MARGRETT","MARAGARET","MANIE","LURLENE","LILLIA","LIESELOTTE","LAVELLE","LASHAUNDA","LAKEESHA","KEITH","KAYCEE","KALYN","JOYA","JOETTE","JENAE","JANIECE","ILLA","GRISEL","GLAYDS","GENEVIE","GALA","FREDDA","FRED","ELMER","ELEONOR","DEBERA","DEANDREA","DAN","CORRINNE","CORDIA","CONTESSA","COLENE","CLEOTILDE","CHARLOTT","CHANTAY","CECILLE","BEATRIS","AZALEE","ARLEAN","ARDATH","ANJELICA","ANJA","ALFREDIA","ALEISHA","ADAM","ZADA","YUONNE","XIAO","WILLODEAN","WHITLEY","VENNIE","VANNA","TYISHA","TOVA","TORIE","TONISHA","TILDA","TIEN","TEMPLE","SIRENA","SHERRIL","SHANTI","SHAN","SENAIDA","SAMELLA","ROBBYN","RENDA","REITA","PHEBE","PAULITA","NOBUKO","NGUYET","NEOMI","MOON","MIKAELA","MELANIA","MAXIMINA","MARG","MAISIE","LYNNA","LILLI","LAYNE","LASHAUN","LAKENYA","LAEL","KIRSTIE","KATHLINE","KASHA","KARLYN","KARIMA","JOVAN","JOSEFINE","JENNELL","JACQUI","JACKELYN","HYO","HIEN","GRAZYNA","FLORRIE","FLORIA","ELEONORA","DWANA","DORLA","DONG","DELMY","DEJA","DEDE","DANN","CRYSTA","CLELIA","CLARIS","CLARENCE","CHIEKO","CHERLYN","CHERELLE","CHARMAIN","CHARA","CAMMY","BEE","ARNETTE","ARDELLE","ANNIKA","AMIEE","AMEE","ALLENA","YVONE","YUKI","YOSHIE","YEVETTE","YAEL","WILLETTA","VONCILE","VENETTA","TULA","TONETTE","TIMIKA","TEMIKA","TELMA","TEISHA","TAREN","TA","STACEE","SHIN","SHAWNTA","SATURNINA","RICARDA","POK","PASTY","ONIE","NUBIA","MORA","MIKE","MARIELLE","MARIELLA","MARIANELA","MARDELL","MANY","LUANNA","LOISE","LISABETH","LINDSY","LILLIANA","LILLIAM","LELAH","LEIGHA","LEANORA","LANG","KRISTEEN","KHALILAH","KEELEY","KANDRA","JUNKO","JOAQUINA","JERLENE","JANI","JAMIKA","JAME","HSIU","HERMILA","GOLDEN","GENEVIVE","EVIA","EUGENA","EMMALINE","ELFREDA","ELENE","DONETTE","DELCIE","DEEANNA","DARCEY","CUC","CLARINDA","CIRA","CHAE","CELINDA","CATHERYN","CATHERIN","CASIMIRA","CARMELIA","CAMELLIA","BREANA","BOBETTE","BERNARDINA","BEBE","BASILIA","ARLYNE","AMAL","ALAYNA","ZONIA","ZENIA","YURIKO","YAEKO","WYNELL","WILLOW","WILLENA","VERNIA","TU","TRAVIS","TORA","TERRILYN","TERICA","TENESHA","TAWNA","TAJUANA","TAINA","STEPHNIE","SONA","SOL","SINA","SHONDRA","SHIZUKO","SHERLENE","SHERICE","SHARIKA","ROSSIE","ROSENA","RORY","RIMA","RIA","RHEBA","RENNA","PETER","NATALYA","NANCEE","MELODI","MEDA","MAXIMA","MATHA","MARKETTA","MARICRUZ","MARCELENE","MALVINA","LUBA","LOUETTA","LEIDA","LECIA","LAURAN","LASHAWNA","LAINE","KHADIJAH","KATERINE","KASI","KALLIE","JULIETTA","JESUSITA","JESTINE","JESSIA","JEREMY","JEFFIE","JANYCE","ISADORA","GEORGIANNE","FIDELIA","EVITA","EURA","EULAH","ESTEFANA","ELSY","ELIZABET","ELADIA","DODIE","DION","DIA","DENISSE","DELORAS","DELILA","DAYSI","DAKOTA","CURTIS","CRYSTLE","CONCHA","COLBY","CLARETTA","CHU","CHRISTIA","CHARLSIE","CHARLENA","CARYLON","BETTYANN","ASLEY","ASHLEA","AMIRA","AI","AGUEDA","AGNUS","YUETTE","VINITA","VICTORINA","TYNISHA","TREENA","TOCCARA","TISH","THOMASENA","TEGAN","SOILA","SHILOH","SHENNA","SHARMAINE","SHANTAE","SHANDI","SEPTEMBER","SARAN","SARAI","SANA","SAMUEL","SALLEY","ROSETTE","ROLANDE","REGINE","OTELIA","OSCAR","OLEVIA","NICHOLLE","NECOLE","NAIDA","MYRTA","MYESHA","MITSUE","MINTA","MERTIE","MARGY","MAHALIA","MADALENE","LOVE","LOURA","LOREAN","LEWIS","LESHA","LEONIDA","LENITA","LAVONE","LASHELL","LASHANDRA","LAMONICA","KIMBRA","KATHERINA","KARRY","KANESHA","JULIO","JONG","JENEVA","JAQUELYN","HWA","GILMA","GHISLAINE","GERTRUDIS","FRANSISCA","FERMINA","ETTIE","ETSUKO","ELLIS","ELLAN","ELIDIA","EDRA","DORETHEA","DOREATHA","DENYSE","DENNY","DEETTA","DAINE","CYRSTAL","CORRIN","CAYLA","CARLITA","CAMILA","BURMA","BULA","BUENA","BLAKE","BARABARA","AVRIL","AUSTIN","ALAINE","ZANA","WILHEMINA","WANETTA","VIRGIL","VI","VERONIKA","VERNON","VERLINE","VASILIKI","TONITA","TISA","TEOFILA","TAYNA","TAUNYA","TANDRA","TAKAKO","SUNNI","SUANNE","SIXTA","SHARELL","SEEMA","RUSSELL","ROSENDA","ROBENA","RAYMONDE","PEI","PAMILA","OZELL","NEIDA","NEELY","MISTIE","MICHA","MERISSA","MAURITA","MARYLN","MARYETTA","MARSHALL","MARCELL","MALENA","MAKEDA","MADDIE","LOVETTA","LOURIE","LORRINE","LORILEE","LESTER","LAURENA","LASHAY","LARRAINE","LAREE","LACRESHA","KRISTLE","KRISHNA","KEVA","KEIRA","KAROLE","JOIE","JINNY","JEANNETTA","JAMA","HEIDY","GILBERTE","GEMA","FAVIOLA","EVELYNN","ENDA","ELLI","ELLENA","DIVINA","DAGNY","COLLENE","CODI","CINDIE","CHASSIDY","CHASIDY","CATRICE","CATHERINA","CASSEY","CAROLL","CARLENA","CANDRA","CALISTA","BRYANNA","BRITTENY","BEULA","BARI","AUDRIE","AUDRIA","ARDELIA","ANNELLE","ANGILA","ALONA","ALLYN","DOUGLAS","ROGER","JONATHAN","RALPH","NICHOLAS","BENJAMIN","BRUCE","HARRY","WAYNE","STEVE","HOWARD","ERNEST","PHILLIP","TODD","CRAIG","ALAN","PHILIP","EARL","DANNY","BRYAN","STANLEY","LEONARD","NATHAN","MANUEL","RODNEY","MARVIN","VINCENT","JEFFERY","JEFF","CHAD","JACOB","ALFRED","BRADLEY","HERBERT","FREDERICK","EDWIN","DON","RICKY","RANDALL","BARRY","BERNARD","LEROY","MARCUS","THEODORE","CLIFFORD","MIGUEL","JIM","TOM","CALVIN","BILL","LLOYD","DEREK","WARREN","DARRELL","JEROME","FLOYD","ALVIN","TIM","GORDON","GREG","JORGE","DUSTIN","PEDRO","DERRICK","ZACHARY","HERMAN","GLEN","HECTOR","RICARDO","RICK","BRENT","RAMON","GILBERT","MARC","REGINALD","RUBEN","NATHANIEL","RAFAEL","EDGAR","MILTON","RAUL","BEN","CHESTER","DUANE","FRANKLIN","BRAD","RON","ROLAND","ARNOLD","HARVEY","JARED","ERIK","DARRYL","NEIL","JAVIER","FERNANDO","CLINTON","TED","MATHEW","TYRONE","DARREN","LANCE","KURT","ALLAN","NELSON","GUY","CLAYTON","HUGH","MAX","DWAYNE","DWIGHT","ARMANDO","FELIX","EVERETT","IAN","WALLACE","KEN","BOB","ALFREDO","ALBERTO","DAVE","IVAN","BYRON","ISAAC","MORRIS","CLIFTON","WILLARD","ROSS","ANDY","SALVADOR","KIRK","SERGIO","SETH","KENT","TERRANCE","EDUARDO","TERRENCE","ENRIQUE","WADE","STUART","FREDRICK","ARTURO","ALEJANDRO","NICK","LUTHER","WENDELL","JEREMIAH","JULIUS","OTIS","TREVOR","OLIVER","LUKE","HOMER","GERARD","DOUG","KENNY","HUBERT","LYLE","MATT","ALFONSO","ORLANDO","REX","CARLTON","ERNESTO","NEAL","PABLO","LORENZO","OMAR","WILBUR","GRANT","HORACE","RODERICK","ABRAHAM","WILLIS","RICKEY","ANDRES","CESAR","JOHNATHAN","MALCOLM","RUDOLPH","DAMON","KELVIN","PRESTON","ALTON","ARCHIE","MARCO","WM","PETE","RANDOLPH","GARRY","GEOFFREY","JONATHON","FELIPE","GERARDO","ED","DOMINIC","DELBERT","COLIN","GUILLERMO","EARNEST","LUCAS","BENNY","SPENCER","RODOLFO","MYRON","EDMUND","GARRETT","SALVATORE","CEDRIC","LOWELL","GREGG","SHERMAN","WILSON","SYLVESTER","ROOSEVELT","ISRAEL","JERMAINE","FORREST","WILBERT","LELAND","SIMON","CLARK","IRVING","BRYANT","OWEN","RUFUS","WOODROW","KRISTOPHER","MACK","LEVI","MARCOS","GUSTAVO","JAKE","LIONEL","GILBERTO","CLINT","NICOLAS","ISMAEL","ORVILLE","ERVIN","DEWEY","AL","WILFRED","JOSH","HUGO","IGNACIO","CALEB","TOMAS","SHELDON","ERICK","STEWART","DOYLE","DARREL","ROGELIO","TERENCE","SANTIAGO","ALONZO","ELIAS","BERT","ELBERT","RAMIRO","CONRAD","NOAH","GRADY","PHIL","CORNELIUS","LAMAR","ROLANDO","CLAY","PERCY","DEXTER","BRADFORD","DARIN","AMOS","MOSES","IRVIN","SAUL","ROMAN","RANDAL","TIMMY","DARRIN","WINSTON","BRENDAN","ABEL","DOMINICK","BOYD","EMILIO","ELIJAH","DOMINGO","EMMETT","MARLON","EMANUEL","JERALD","EDMOND","EMIL","DEWAYNE","WILL","OTTO","TEDDY","REYNALDO","BRET","JESS","TRENT","HUMBERTO","EMMANUEL","STEPHAN","VICENTE","LAMONT","GARLAND","MILES","EFRAIN","HEATH","RODGER","HARLEY","ETHAN","ELDON","ROCKY","PIERRE","JUNIOR","FREDDY","ELI","BRYCE","ANTOINE","STERLING","CHASE","GROVER","ELTON","CLEVELAND","DYLAN","CHUCK","DAMIAN","REUBEN","STAN","AUGUST","LEONARDO","JASPER","RUSSEL","ERWIN","BENITO","HANS","MONTE","BLAINE","ERNIE","CURT","QUENTIN","AGUSTIN","MURRAY","JAMAL","ADOLFO","HARRISON","TYSON","BURTON","BRADY","ELLIOTT","WILFREDO","BART","JARROD","VANCE","DENIS","DAMIEN","JOAQUIN","HARLAN","DESMOND","ELLIOT","DARWIN","GREGORIO","BUDDY","XAVIER","KERMIT","ROSCOE","ESTEBAN","ANTON","SOLOMON","SCOTTY","NORBERT","ELVIN","WILLIAMS","NOLAN","ROD","QUINTON","HAL","BRAIN","ROB","ELWOOD","KENDRICK","DARIUS","MOISES","FIDEL","THADDEUS","CLIFF","MARCEL","JACKSON","RAPHAEL","BRYON","ARMAND","ALVARO","JEFFRY","DANE","JOESPH","THURMAN","NED","RUSTY","MONTY","FABIAN","REGGIE","MASON","GRAHAM","ISAIAH","VAUGHN","GUS","LOYD","DIEGO","ADOLPH","NORRIS","MILLARD","ROCCO","GONZALO","DERICK","RODRIGO","WILEY","RIGOBERTO","ALPHONSO","TY","NOE","VERN","REED","JEFFERSON","ELVIS","BERNARDO","MAURICIO","HIRAM","DONOVAN","BASIL","RILEY","NICKOLAS","MAYNARD","SCOT","VINCE","QUINCY","EDDY","SEBASTIAN","FEDERICO","ULYSSES","HERIBERTO","DONNELL","COLE","DAVIS","GAVIN","EMERY","WARD","ROMEO","JAYSON","DANTE","CLEMENT","COY","MAXWELL","JARVIS","BRUNO","ISSAC","DUDLEY","BROCK","SANFORD","CARMELO","BARNEY","NESTOR","STEFAN","DONNY","ART","LINWOOD","BEAU","WELDON","GALEN","ISIDRO","TRUMAN","DELMAR","JOHNATHON","SILAS","FREDERIC","DICK","IRWIN","MERLIN","CHARLEY","MARCELINO","HARRIS","CARLO","TRENTON","KURTIS","HUNTER","AURELIO","WINFRED","VITO","COLLIN","DENVER","CARTER","LEONEL","EMORY","PASQUALE","MOHAMMAD","MARIANO","DANIAL","LANDON","DIRK","BRANDEN","ADAN","BUFORD","GERMAN","WILMER","EMERSON","ZACHERY","FLETCHER","JACQUES","ERROL","DALTON","MONROE","JOSUE","EDWARDO","BOOKER","WILFORD","SONNY","SHELTON","CARSON","THERON","RAYMUNDO","DAREN","HOUSTON","ROBBY","LINCOLN","GENARO","BENNETT","OCTAVIO","CORNELL","HUNG","ARRON","ANTONY","HERSCHEL","GIOVANNI","GARTH","CYRUS","CYRIL","RONNY","LON","FREEMAN","DUNCAN","KENNITH","CARMINE","ERICH","CHADWICK","WILBURN","RUSS","REID","MYLES","ANDERSON","MORTON","JONAS","FOREST","MITCHEL","MERVIN","ZANE","RICH","JAMEL","LAZARO","ALPHONSE","RANDELL","MAJOR","JARRETT","BROOKS","ABDUL","LUCIANO","SEYMOUR","EUGENIO","MOHAMMED","VALENTIN","CHANCE","ARNULFO","LUCIEN","FERDINAND","THAD","EZRA","ALDO","RUBIN","ROYAL","MITCH","EARLE","ABE","WYATT","MARQUIS","LANNY","KAREEM","JAMAR","BORIS","ISIAH","EMILE","ELMO","ARON","LEOPOLDO","EVERETTE","JOSEF","ELOY","RODRICK","REINALDO","LUCIO","JERROD","WESTON","HERSHEL","BARTON","PARKER","LEMUEL","BURT","JULES","GIL","ELISEO","AHMAD","NIGEL","EFREN","ANTWAN","ALDEN","MARGARITO","COLEMAN","DINO","OSVALDO","LES","DEANDRE","NORMAND","KIETH","TREY","NORBERTO","NAPOLEON","JEROLD","FRITZ","ROSENDO","MILFORD","CHRISTOPER","ALFONZO","LYMAN","JOSIAH","BRANT","WILTON","RICO","JAMAAL","DEWITT","BRENTON","OLIN","FOSTER","FAUSTINO","CLAUDIO","JUDSON","GINO","EDGARDO","ALEC","TANNER","JARRED","DONN","TAD","PRINCE","PORFIRIO","ODIS","LENARD","CHAUNCEY","TOD","MEL","MARCELO","KORY","AUGUSTUS","KEVEN","HILARIO","BUD","SAL","ORVAL","MAURO","ZACHARIAH","OLEN","ANIBAL","MILO","JED","DILLON","AMADO","NEWTON","LENNY","RICHIE","HORACIO","BRICE","MOHAMED","DELMER","DARIO","REYES","MAC","JONAH","JERROLD","ROBT","HANK","RUPERT","ROLLAND","KENTON","DAMION","ANTONE","WALDO","FREDRIC","BRADLY","KIP","BURL","WALKER","TYREE","JEFFEREY","AHMED","WILLY","STANFORD","OREN","NOBLE","MOSHE","MIKEL","ENOCH","BRENDON","QUINTIN","JAMISON","FLORENCIO","DARRICK","TOBIAS","HASSAN","GIUSEPPE","DEMARCUS","CLETUS","TYRELL","LYNDON","KEENAN","WERNER","GERALDO","COLUMBUS","CHET","BERTRAM","MARKUS","HUEY","HILTON","DWAIN","DONTE","TYRON","OMER","ISAIAS","HIPOLITO","FERMIN","ADALBERTO","BO","BARRETT","TEODORO","MCKINLEY","MAXIMO","GARFIELD","RALEIGH","LAWERENCE","ABRAM","RASHAD","KING","EMMITT","DARON","SAMUAL","MIQUEL","EUSEBIO","DOMENIC","DARRON","BUSTER","WILBER","RENATO","JC","HOYT","HAYWOOD","EZEKIEL","CHAS","FLORENTINO","ELROY","CLEMENTE","ARDEN","NEVILLE","EDISON","DESHAWN","NATHANIAL","JORDON","DANILO","CLAUD","SHERWOOD","RAYMON","RAYFORD","CRISTOBAL","AMBROSE","TITUS","HYMAN","FELTON","EZEQUIEL","ERASMO","STANTON","LONNY","LEN","IKE","MILAN","LINO","JAROD","HERB","ANDREAS","WALTON","RHETT","PALMER","DOUGLASS","CORDELL","OSWALDO","ELLSWORTH","VIRGILIO","TONEY","NATHANAEL","DEL","BENEDICT","MOSE","JOHNSON","ISREAL","GARRET","FAUSTO","ASA","ARLEN","ZACK","WARNER","MODESTO","FRANCESCO","MANUAL","GAYLORD","GASTON","FILIBERTO","DEANGELO","MICHALE","GRANVILLE","WES","MALIK","ZACKARY","TUAN","ELDRIDGE","CRISTOPHER","CORTEZ","ANTIONE","MALCOM","LONG","KOREY","JOSPEH","COLTON","WAYLON","VON","HOSEA","SHAD","SANTO","RUDOLF","ROLF","REY","RENALDO","MARCELLUS","LUCIUS","KRISTOFER","BOYCE","BENTON","HAYDEN","HARLAND","ARNOLDO","RUEBEN","LEANDRO","KRAIG","JERRELL","JEROMY","HOBERT","CEDRICK","ARLIE","WINFORD","WALLY","LUIGI","KENETH","JACINTO","GRAIG","FRANKLYN","EDMUNDO","SID","PORTER","LEIF","JERAMY","BUCK","WILLIAN","VINCENZO","SHON","LYNWOOD","JERE","HAI","ELDEN","DORSEY","DARELL","BRODERICK","ALONSO" \ No newline at end of file diff --git a/project_euler/problem_22/sol1.rb b/project_euler/problem_22/sol1.rb new file mode 100644 index 0000000..9a4a8a9 --- /dev/null +++ b/project_euler/problem_22/sol1.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# Problem 22 +# Using names.txt (right click and 'Save Link/Target As...'), +# a 46K text file containing over five-thousand first names, +# begin by sorting it into alphabetical order. +# Then working out the alphabetical value for each name, +# multiply this value by its alphabetical position in the list to obtain a name score. + +# For example, when the list is sorted into alphabetical order, +# COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, +# is the 938th name in the list. So, COLIN would obtain a score of 938 * 53 = 49714. + +# What is the total of all the name scores in the file? + +# reading the contents of the file +file_contents = File.read('p022_names.txt') + +# replacing the occuerance of \" to '' and spliting the result by ',' +# to get an array of sorted words +words = file_contents.tr('\"', '').split(',').sort + +# this method calculates the worth of a word based on the ASCII +# values of the characters +def word_worth(word) + word.chars.sum { |char| char.ord - 'A'.ord + 1 } +end + +# this method takes the words as an input +# calls `word_worth` method on each word +# to that value multiply that with the index of the word in the array +# add the same to the result +def total_rank(words) + result = 0 + words.each_with_index { |word, index| result += word_worth(word) * (index + 1) } + result +end + +# outputs total rank on the console +puts total_rank(words) diff --git a/project_euler/problem_3/sol1.rb b/project_euler/problem_3/sol1.rb new file mode 100644 index 0000000..df92cf0 --- /dev/null +++ b/project_euler/problem_3/sol1.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +# The prime factors of 13195 are 5, 7, 13 and 29. +# What is the largest prime factor of the number 600851475143 + +# find all factors of the given number +def get_factors(number) + factors = [] + (1..Math.sqrt(number).to_i).each do |num| + if (number % num).zero? + factors << num + factors << number / num + end + end + factors +end + +# determine if a given number is a prime number +def prime?(number) + get_factors(number).length == 2 +end + +# find the largest prime +def largest_prime_factor(number) + prime_factors = get_factors(number).select { |factor| prime?(factor) } + prime_factors.max +end + +puts largest_prime_factor(600_851_475_143) diff --git a/project_euler/problem_3/sol2.rb b/project_euler/problem_3/sol2.rb new file mode 100644 index 0000000..0685de6 --- /dev/null +++ b/project_euler/problem_3/sol2.rb @@ -0,0 +1,18 @@ +# The prime factors of 13195 are 5, 7, 13 and 29. +# What is the largest prime factor of the number 600851475143 ? + +def solution(n) + prime = 1 + i = 2 + while i * i <= n + while (n % i).zero? + prime = i + n = n.fdiv i + end + i += 1 + end + prime = n if n > 1 + prime.to_i +end + +puts solution(600_851_475_143) diff --git a/project_euler/problem_4/sol1.rb b/project_euler/problem_4/sol1.rb new file mode 100644 index 0000000..f3f52a2 --- /dev/null +++ b/project_euler/problem_4/sol1.rb @@ -0,0 +1,11 @@ +# 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. + +answer = 0 +999.downto(99) do |i| + 999.downto(99) do |j| + t = (i * j) + answer = i * j if (t.to_s == t.to_s.reverse) && (t > answer) && (t > answer) + end +end +puts answer diff --git a/project_euler/problem_4/sol2.rb b/project_euler/problem_4/sol2.rb new file mode 100644 index 0000000..fd881e2 --- /dev/null +++ b/project_euler/problem_4/sol2.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +# 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. + +class Integer + def parindrome? + self == reverse + end + + # 123.reverse == 321 + # 100.reverse == 1 + def reverse + result = 0 + n = self + loop do + result = result * 10 + n % 10 + break if (n /= 10).zero? + end + result + end +end + +factors = (100..999).to_a +products = factors.product(factors).map { _1 * _2 } +puts products.select(&:parindrome?).max diff --git a/project_euler/problem_5/sol1.rb b/project_euler/problem_5/sol1.rb new file mode 100644 index 0000000..e83cbfb --- /dev/null +++ b/project_euler/problem_5/sol1.rb @@ -0,0 +1,22 @@ +# 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? + +# Euclid's algorithm for the greatest common divisor +def gcd(a, b) + b.zero? ? a : gcd(b, a % b) +end + +# Calculate the LCM using GCD +def lcm(a, b) + (a * b) / gcd(a, b) +end + +result = 1 + +20.times do |i| + result = lcm(result, i + 1) +end + +p result From 8e3ec5a9ddf0857ee0a97a43c80ae6e4a511e4b3 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Wed, 12 May 2021 08:37:08 -0700 Subject: [PATCH 097/121] Add hash approach --- data_structures/arrays/good_pairs.rb | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/data_structures/arrays/good_pairs.rb b/data_structures/arrays/good_pairs.rb index 662b1aa..91f4c65 100644 --- a/data_structures/arrays/good_pairs.rb +++ b/data_structures/arrays/good_pairs.rb @@ -37,6 +37,39 @@ puts(num_identical_pairs(nums)) # Output: 6 # Explanation: Each pair in the array are good. +nums = [1, 2, 3] +puts(num_identical_pairs(nums)) +# Output: 0 + +# +# Approach 2: Hash +# +def num_identical_pairs(nums) + hash = Hash.new(0) + + nums.each do |num| + hash[num] = hash[num] + 1 + end + + counter = 0 + # Count how many times each number appears. + # If a number appears n times, then n * (n – 1) / 2 good pairs + # can be made with this number. + hash.values.each do |val| + counter += (val * (val - 1) / 2) + end + + counter +end + +nums = [1, 2, 3, 1, 1, 3] +puts(num_identical_pairs(nums)) +# Output: 4 + +nums = [1, 1, 1, 1] +puts(num_identical_pairs(nums)) +# Output: 6 + nums = [1, 2, 3] puts(num_identical_pairs(nums)) # Output: 0 \ No newline at end of file From 33e3d2b456d04d6cafe7f89c8bd36646d2afa8e6 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Wed, 12 May 2021 08:37:08 -0700 Subject: [PATCH 098/121] Add hash approach --- data_structures/arrays/good_pairs.rb | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/data_structures/arrays/good_pairs.rb b/data_structures/arrays/good_pairs.rb index 662b1aa..32dc626 100644 --- a/data_structures/arrays/good_pairs.rb +++ b/data_structures/arrays/good_pairs.rb @@ -37,6 +37,40 @@ puts(num_identical_pairs(nums)) # Output: 6 # Explanation: Each pair in the array are good. +nums = [1, 2, 3] +puts(num_identical_pairs(nums)) +# Output: 0 + +# +# Approach 2: Hash +# +# Time Complexity: O(n) +def num_identical_pairs(nums) + hash = Hash.new(0) + + nums.each do |num| + hash[num] = hash[num] + 1 + end + + counter = 0 + # Count how many times each number appears. + # If a number appears n times, then n * (n – 1) / 2 good pairs + # can be made with this number. + hash.values.each do |val| + counter += (val * (val - 1) / 2) + end + + counter +end + +nums = [1, 2, 3, 1, 1, 3] +puts(num_identical_pairs(nums)) +# Output: 4 + +nums = [1, 1, 1, 1] +puts(num_identical_pairs(nums)) +# Output: 6 + nums = [1, 2, 3] puts(num_identical_pairs(nums)) # Output: 0 \ No newline at end of file From 0386dfd0d1b86dd7bf4bf7b99be88f7847f0aecd Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Thu, 13 May 2021 12:09:01 -0700 Subject: [PATCH 099/121] Add uncommon words challenge --- DIRECTORY.md | 1 + .../arrays/strings/uncommon_words.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 data_structures/arrays/strings/uncommon_words.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index d0c4469..115e65c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -24,6 +24,7 @@ * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb) * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) * [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb) + * [Uncommon Words](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/uncommon_words.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb) * [Two Sum Ii](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum_ii.rb) * Binary Trees diff --git a/data_structures/arrays/strings/uncommon_words.rb b/data_structures/arrays/strings/uncommon_words.rb new file mode 100644 index 0000000..32fa391 --- /dev/null +++ b/data_structures/arrays/strings/uncommon_words.rb @@ -0,0 +1,19 @@ +# Challenge name: Uncommon words from two sentences +# +# We are given two sentences A and B. +# (A sentence is a string of space separated words. +# Each word consists only of lowercase letters.) +# +# A word is uncommon if it appears exactly once in one of the sentences, +# and does not appear in the other sentence. +# +# Return a list of all uncommon words. +# You may return the list in any order. +# +# Example 1: +# Input: A = "this apple is sweet", B = "this apple is sour" +# Output: ["sweet","sour"] +# +# Example 2: +# Input: A = "apple apple", B = "banana" +# Output: ["banana"] \ No newline at end of file From b4c2e2e6b0c68a02ee2888f29dd818bb4248176a Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 14 May 2021 09:30:49 -0700 Subject: [PATCH 100/121] Add good pairs hash solution into hash_table section and directory --- DIRECTORY.md | 1 + data_structures/hash_table/good_pairs.rb | 43 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 data_structures/hash_table/good_pairs.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index a13d235..7ae27cd 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -52,6 +52,7 @@ * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/anagram_checker.rb) * [Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/arrays_intersection.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/find_all_duplicates_in_an_array.rb) + * [Good Pairs](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/good_pairs.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/richest_customer_wealth.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/two_sum.rb) * Linked Lists diff --git a/data_structures/hash_table/good_pairs.rb b/data_structures/hash_table/good_pairs.rb new file mode 100644 index 0000000..9f7beeb --- /dev/null +++ b/data_structures/hash_table/good_pairs.rb @@ -0,0 +1,43 @@ +# Challenge name: Number of good pairs +# +# Given an array of integers nums. +# A pair (i,j) is called good if nums[i] == nums[j] and i < j. +# Return the number of good pairs. +# +# @param {Integer[]} nums +# @return {Integer} +# + +# +# Approach 1: Hash +# +# Time Complexity: O(n) +def num_identical_pairs(nums) + hash = Hash.new(0) + + nums.each do |num| + hash[num] = hash[num] + 1 + end + + counter = 0 + # Count how many times each number appears. + # If a number appears n times, then n * (n – 1) / 2 good pairs + # can be made with this number. + hash.values.each do |val| + counter += (val * (val - 1) / 2) + end + + counter +end + +nums = [1, 2, 3, 1, 1, 3] +puts(num_identical_pairs(nums)) +# Output: 4 + +nums = [1, 1, 1, 1] +puts(num_identical_pairs(nums)) +# Output: 6 + +nums = [1, 2, 3] +puts(num_identical_pairs(nums)) +# Output: 0 \ No newline at end of file From 0a83001a2a5f0982a425ab465651822054e558d8 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Fri, 14 May 2021 09:44:08 -0700 Subject: [PATCH 101/121] remove hash from /arrays folder --- data_structures/arrays/good_pairs.rb | 34 ---------------------------- 1 file changed, 34 deletions(-) diff --git a/data_structures/arrays/good_pairs.rb b/data_structures/arrays/good_pairs.rb index 32dc626..b62572d 100644 --- a/data_structures/arrays/good_pairs.rb +++ b/data_structures/arrays/good_pairs.rb @@ -40,37 +40,3 @@ puts(num_identical_pairs(nums)) nums = [1, 2, 3] puts(num_identical_pairs(nums)) # Output: 0 - -# -# Approach 2: Hash -# -# Time Complexity: O(n) -def num_identical_pairs(nums) - hash = Hash.new(0) - - nums.each do |num| - hash[num] = hash[num] + 1 - end - - counter = 0 - # Count how many times each number appears. - # If a number appears n times, then n * (n – 1) / 2 good pairs - # can be made with this number. - hash.values.each do |val| - counter += (val * (val - 1) / 2) - end - - counter -end - -nums = [1, 2, 3, 1, 1, 3] -puts(num_identical_pairs(nums)) -# Output: 4 - -nums = [1, 1, 1, 1] -puts(num_identical_pairs(nums)) -# Output: 6 - -nums = [1, 2, 3] -puts(num_identical_pairs(nums)) -# Output: 0 \ No newline at end of file From 4bd9206f018fd6693775aa1b5ac2ab002b008515 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 14 May 2021 16:36:04 -0700 Subject: [PATCH 102/121] Add hash solution --- DIRECTORY.md | 2 +- .../strings => hash_table}/uncommon_words.rb | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) rename data_structures/{arrays/strings => hash_table}/uncommon_words.rb (55%) diff --git a/DIRECTORY.md b/DIRECTORY.md index 115e65c..a3bafbe 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -24,7 +24,6 @@ * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb) * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) * [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb) - * [Uncommon Words](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/uncommon_words.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb) * [Two Sum Ii](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum_ii.rb) * Binary Trees @@ -36,6 +35,7 @@ * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/find_all_duplicates_in_an_array.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/richest_customer_wealth.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/two_sum.rb) + * [Uncommon Words](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/uncommon_words.rb) * Linked Lists * [Circular Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/circular_linked_list.rb) * [Doubly Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/doubly_linked_list.rb) diff --git a/data_structures/arrays/strings/uncommon_words.rb b/data_structures/hash_table/uncommon_words.rb similarity index 55% rename from data_structures/arrays/strings/uncommon_words.rb rename to data_structures/hash_table/uncommon_words.rb index 32fa391..e3e8d2f 100644 --- a/data_structures/arrays/strings/uncommon_words.rb +++ b/data_structures/hash_table/uncommon_words.rb @@ -16,4 +16,33 @@ # # Example 2: # Input: A = "apple apple", B = "banana" -# Output: ["banana"] \ No newline at end of file +# Output: ["banana"] + +# +# Approach 1: Hash +# +# Time Complexitiy: O(n) + +def find_uncommon_words(strA, strB) + array = strA.concat(" ", strB).split(" ") + hash = Hash.new(0) + result = [] + + array.each do |word| + if hash[word] + hash[word] += 1 + else + hash[word] = 1 + end + end + + hash.each do |k, v| + if v < 2 + result.push(k) + end + end + + result +end + +puts find_uncommon_words("this apple is sweet", "this apple is sour") \ No newline at end of file From a591b2fd5626c6fabfa8e5a56f6fb6b5d54c5cef Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 14 May 2021 16:53:05 -0700 Subject: [PATCH 103/121] Add examples --- data_structures/hash_table/uncommon_words.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data_structures/hash_table/uncommon_words.rb b/data_structures/hash_table/uncommon_words.rb index e3e8d2f..9e17b61 100644 --- a/data_structures/hash_table/uncommon_words.rb +++ b/data_structures/hash_table/uncommon_words.rb @@ -45,4 +45,8 @@ def find_uncommon_words(strA, strB) result end -puts find_uncommon_words("this apple is sweet", "this apple is sour") \ No newline at end of file +puts find_uncommon_words("this apple is sweet", "this apple is sour") +# => ["sweet", "sour"] + +puts find_uncommon_words("apple apple", "banana") +# => ["banana"] \ No newline at end of file From 2032eef8242b6db31f97f892fa832a73cd767111 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Fri, 14 May 2021 16:56:07 -0700 Subject: [PATCH 104/121] Add common characters challenge --- DIRECTORY.md | 1 + .../arrays/strings/common_characters.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 data_structures/arrays/strings/common_characters.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index d0c4469..fcd790b 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -22,6 +22,7 @@ * [Sort Squares Of An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/sort_squares_of_an_array.rb) * Strings * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb) + * [Common Characters](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/common_characters.rb) * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) * [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb) diff --git a/data_structures/arrays/strings/common_characters.rb b/data_structures/arrays/strings/common_characters.rb new file mode 100644 index 0000000..42205aa --- /dev/null +++ b/data_structures/arrays/strings/common_characters.rb @@ -0,0 +1,19 @@ +# Challenge name: Find Common Characters +# +# Given an array A of strings made only from lowercase letters, return a list +# of all characters that show up in all strings within the list +# (including duplicates). For example, if a character occurs 3 times in all +# strings but not 4 times, you need to include that character three times in +# the final answer. +# +# You may return the answer in any order. +# +# Example 1: +# +# Input: ["bella","label","roller"] +# Output: ["e","l","l"] +# +# Example 2: +# +# Input: ["cool","lock","cook"] +# Output: ["c","o"] \ No newline at end of file From a5e3a0f2b442c9d653766e72aadfe2bf0c85f374 Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Sat, 15 May 2021 11:10:22 +0530 Subject: [PATCH 105/121] Update maths/armstrong_number.rb Co-authored-by: Jessica Kwok <60627484+jsca-kwok@users.noreply.github.com> --- maths/armstrong_number.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/armstrong_number.rb b/maths/armstrong_number.rb index 36aed4e..b312891 100644 --- a/maths/armstrong_number.rb +++ b/maths/armstrong_number.rb @@ -1,4 +1,4 @@ -# A ruby program to find a given number is armstrong number or not +# A ruby program to determine whether a given number is an Armstrong number # Wiki url: https://en.wikipedia.org/wiki/Narcissistic_number # other resources: https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/arms.html From c923b270c359195a15661f8827a568123d7d102b Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Sat, 15 May 2021 20:13:21 +0530 Subject: [PATCH 106/121] lucas series feature implementation --- DIRECTORY.md | 1 + maths/lucas_series.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 maths/lucas_series.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index 4c2cb0a..bff4ebc 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -84,6 +84,7 @@ * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/maths/fibonacci.rb) * [Find Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) * [Find Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_min.rb) + * [Lucas Series](https://github.com/TheAlgorithms/Ruby/blob/master/maths/lucas_series.rb) * [Number Of Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/number_of_digits.rb) * [Power Of Two](https://github.com/TheAlgorithms/Ruby/blob/master/maths/power_of_two.rb) * [Prime Number](https://github.com/TheAlgorithms/Ruby/blob/master/maths/prime_number.rb) diff --git a/maths/lucas_series.rb b/maths/lucas_series.rb new file mode 100644 index 0000000..85fb41f --- /dev/null +++ b/maths/lucas_series.rb @@ -0,0 +1,31 @@ +# A ruby program for Lucas series +# +# The Lucas numbers, commonly denoted L(n) form a sequence, +# called the Lucas series, such that each number is the sum +# of the two preceding ones, starting from 2 and 1. That is, +# +# L(0) = 2, L(1) = 1 +# L(n) = L(n - 1) + L(n - 2), for n > 1. +# +# Given n, calculate L(n). +# Example: 2 1 3 4 7 11 18... +# Resource: https://en.wikipedia.org/wiki/Lucas_number + +def lucas(number) + golden_ratio = (1 + 5**0.5) / 2 + ((golden_ratio**number).round()).to_i + rescue + "Error: Provide number only!" +end + +puts lucas(4) +# 7 + +puts lucas(3) +# 4 + +puts lucas("3") +# Error: Provide number only! + +puts lucas(2) +# 3 From 787eb8888b4af0670f234824c4905ecb81e0217b Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 16 May 2021 21:43:53 -0700 Subject: [PATCH 107/121] Count sorted vowel strings: math approach --- maths/count_sorted_vowel_strings.rb | 65 +++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 maths/count_sorted_vowel_strings.rb diff --git a/maths/count_sorted_vowel_strings.rb b/maths/count_sorted_vowel_strings.rb new file mode 100644 index 0000000..33128b7 --- /dev/null +++ b/maths/count_sorted_vowel_strings.rb @@ -0,0 +1,65 @@ +# Challenge name: Count Sorted Vowel Strings +# +# Given an integer n, return the number of strings of length n that consist only +# of vowels (a, e, i, o, u) and are lexicographically sorted. +# +# A string s is lexicographically sorted if for all valid i, s[i] is the same as +# or comes before s[i+1] in the alphabet. +# +# +# Example 1: +# +# Input: n = 1 +# Output: 5 +# Explanation: The 5 sorted strings that consist of vowels only are ["a","e","i","o","u"]. +# +# Example 2: +# +# Input: n = 2 +# Output: 15 +# Explanation: The 15 sorted strings that consist of vowels only are +# ["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"]. +# Note that "ea" is not a valid string since 'e' comes after 'a' in the alphabet. +# +# Example 3: +# +# Input: n = 33 +# Output: 66045 + + +# +# Approach: Math +# + +# +# Intuition and Algorithm +# +# The problem is a variant of finding Combinations. +# Mathematically, the problem can be described as, +# given 5 vowels (let k = 5), we want to find the +# number of combinations using only nn vowels. Also, +# we can repeat each of those vowels multiple times. +# + +# Complexity Analysis +# +# Time Complexity: O(1), as the approach runs in constant time. +# Space Complexity: O(1), as the approach uses constant extra space. + +# @param {Integer} n +# @return {Integer} +def count_vowel_strings(n) + (n + 4) * (n + 3) * (n + 2) * (n + 1) / 24 +end + +n = 33 +puts count_vowel_strings(n) +# Output: 66045 + +n = 2 +puts count_vowel_strings(n) +# Output: 15 + +n = 1 +puts count_vowel_strings(n) +# Output: 5 From 51eb72bb28fa7dd31f74c0413078c1a70fbcfff5 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 17 May 2021 04:44:11 +0000 Subject: [PATCH 108/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 15bcf9f..7290fdc 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -78,6 +78,7 @@ * [Binary To Decimal](https://github.com/TheAlgorithms/Ruby/blob/master/maths/binary_to_decimal.rb) * [Ceil](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil.rb) * [Ceil Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/ceil_test.rb) + * [Count Sorted Vowel Strings](https://github.com/TheAlgorithms/Ruby/blob/master/maths/count_sorted_vowel_strings.rb) * [Decimal To Binary](https://github.com/TheAlgorithms/Ruby/blob/master/maths/decimal_to_binary.rb) * [Factorial](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial.rb) * [Factorial Non Recursive Non Iterative](https://github.com/TheAlgorithms/Ruby/blob/master/maths/factorial_non_recursive_non_iterative.rb) From b9596635ecc594ad60c448c6820a1a307d0b5cbe Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 16 May 2021 21:52:41 -0700 Subject: [PATCH 109/121] fix duplication --- maths/count_sorted_vowel_strings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/count_sorted_vowel_strings.rb b/maths/count_sorted_vowel_strings.rb index 33128b7..630f1f8 100644 --- a/maths/count_sorted_vowel_strings.rb +++ b/maths/count_sorted_vowel_strings.rb @@ -37,7 +37,7 @@ # The problem is a variant of finding Combinations. # Mathematically, the problem can be described as, # given 5 vowels (let k = 5), we want to find the -# number of combinations using only nn vowels. Also, +# number of combinations using only n vowels. Also, # we can repeat each of those vowels multiple times. # From a0ce59f41fa42b5eb9af58443596769da2af357b Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 16 May 2021 22:10:31 -0700 Subject: [PATCH 110/121] Count sorted vowel strings: dynamic programming --- .../count_sorted_vowel_strings.rb | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 dynamic_programming/count_sorted_vowel_strings.rb diff --git a/dynamic_programming/count_sorted_vowel_strings.rb b/dynamic_programming/count_sorted_vowel_strings.rb new file mode 100644 index 0000000..0696006 --- /dev/null +++ b/dynamic_programming/count_sorted_vowel_strings.rb @@ -0,0 +1,80 @@ +# Challenge name: Count Sorted Vowel Strings +# +# Given an integer n, return the number of strings of length n that consist only +# of vowels (a, e, i, o, u) and are lexicographically sorted. +# +# A string s is lexicographically sorted if for all valid i, s[i] is the same as +# or comes before s[i+1] in the alphabet. +# +# +# Example 1: +# +# Input: n = 1 +# Output: 5 +# Explanation: The 5 sorted strings that consist of vowels only are ["a","e","i","o","u"]. +# +# Example 2: +# +# Input: n = 2 +# Output: 15 +# Explanation: The 15 sorted strings that consist of vowels only are +# ["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"]. +# Note that "ea" is not a valid string since 'e' comes after 'a' in the alphabet. +# +# Example 3: +# +# Input: n = 33 +# Output: 66045 + +# +# Approach: Using Recursion + Memoization, Top Down Dynamic Programming +# + +# @param {Integer} n +# @return {Integer} + +def count_vowel_strings(n, letter = 'a') + return 1 if n < 1 + + @h ||= {} + key = [n, letter] + return @h[key] if @h[key] + + result = case letter + when 'a' + count_vowel_strings(n - 1, letter = 'a') + + count_vowel_strings(n - 1, letter = 'e') + + count_vowel_strings(n - 1, letter = 'i') + + count_vowel_strings(n - 1, letter = 'o') + + count_vowel_strings(n - 1, letter = 'u') + when 'e' + count_vowel_strings(n - 1, letter = 'e') + + count_vowel_strings(n - 1, letter = 'i') + + count_vowel_strings(n - 1, letter = 'o') + + count_vowel_strings(n - 1, letter = 'u') + when 'i' + count_vowel_strings(n - 1, letter = 'i') + + count_vowel_strings(n - 1, letter = 'o') + + count_vowel_strings(n - 1, letter = 'u') + when 'o' + count_vowel_strings(n - 1, letter = 'o') + + count_vowel_strings(n - 1, letter = 'u') + when 'u' + count_vowel_strings(n - 1, letter = 'u') + end + + @h[key] = result + @h[key] +end + +n = 33 +puts count_vowel_strings(n) +# Output: 66045 + +n = 2 +puts count_vowel_strings(n) +# Output: 15 + +n = 1 +puts count_vowel_strings(n) +# Output: 5 From fba17c66e968279bc00a33bc340f9fb88d63f1f2 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 17 May 2021 05:10:48 +0000 Subject: [PATCH 111/121] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 15bcf9f..93c812b 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -64,6 +64,7 @@ ## Dynamic Programming * [Coin Change](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/coin_change.rb) + * [Count Sorted Vowel Strings](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/count_sorted_vowel_strings.rb) * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/fibonacci.rb) ## Maths From 0884b95d4e1965487c813b1dd84b86156cd3853f Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 16 May 2021 22:12:36 -0700 Subject: [PATCH 112/121] add short explanation --- dynamic_programming/count_sorted_vowel_strings.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dynamic_programming/count_sorted_vowel_strings.rb b/dynamic_programming/count_sorted_vowel_strings.rb index 0696006..e6a9fbe 100644 --- a/dynamic_programming/count_sorted_vowel_strings.rb +++ b/dynamic_programming/count_sorted_vowel_strings.rb @@ -30,6 +30,17 @@ # Approach: Using Recursion + Memoization, Top Down Dynamic Programming # +# +# Algorithm: Dynamic Programming state transition. +# +# F(0) = 1 +# F(n)a = F(n-1)a + F(n-1)e + F(n-1)i + F(n-1)o +F(n-1)u +# F(n)e = F(n-1)e + F(n-1)i + F(n-1)o + F(n-1)u +# F(n)i = F(n-1)i + F(n-1)o +F(n-1)u +# F(n)o = F(n-1)o + F(n-1)u +# F(n)u = F(n-1)u +# + # @param {Integer} n # @return {Integer} From 7f6b015a3bd847d2c1cb4f7e34daa6c766787706 Mon Sep 17 00:00:00 2001 From: Jessica Kwok <60627484+jsca-kwok@users.noreply.github.com> Date: Mon, 17 May 2021 09:32:35 -0700 Subject: [PATCH 113/121] Update data_structures/hash_table/uncommon_words.rb Co-authored-by: Vitor Oliveira --- data_structures/hash_table/uncommon_words.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/data_structures/hash_table/uncommon_words.rb b/data_structures/hash_table/uncommon_words.rb index 9e17b61..ff0ace9 100644 --- a/data_structures/hash_table/uncommon_words.rb +++ b/data_structures/hash_table/uncommon_words.rb @@ -29,11 +29,7 @@ def find_uncommon_words(strA, strB) result = [] array.each do |word| - if hash[word] - hash[word] += 1 - else - hash[word] = 1 - end + hash[word] += 1 end hash.each do |k, v| @@ -49,4 +45,4 @@ puts find_uncommon_words("this apple is sweet", "this apple is sour") # => ["sweet", "sour"] puts find_uncommon_words("apple apple", "banana") -# => ["banana"] \ No newline at end of file +# => ["banana"] From a007c2b3e230b1b5387c5d547cffb2a199c5b48e Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Mon, 31 May 2021 21:56:36 +0530 Subject: [PATCH 114/121] abs max feature implementation --- DIRECTORY.md | 1 + maths/abs_max.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 maths/abs_max.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index bff4ebc..e40d772 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -66,6 +66,7 @@ * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/fibonacci.rb) ## Maths + * [Abs Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_max.rb) * [Abs](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs.rb) * [Abs Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_test.rb) * [Add](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add.rb) diff --git a/maths/abs_max.rb b/maths/abs_max.rb new file mode 100644 index 0000000..d3130d9 --- /dev/null +++ b/maths/abs_max.rb @@ -0,0 +1,30 @@ +# A ruby program to find absolute maximum +# Mathematical representation of abs max = ((a + b + absoulte(a - b)) / 2) + +def abs_max(x, y) + num = x - y + max_value = ((x + y + num.abs()) / 2) + "The Abs Max of #{x} and #{y} is #{max_value}." + rescue + "Error: Provide number only!" +end + +# Valid inputs +puts abs_max(10, 20) +# The Abs Max of 10 and 20 is 20. + +puts abs_max(-10, -1) +# The Abs Max of -10 and -1 is -1. + +puts abs_max(9, -121) +# The Abs Max of 9 and -121 is 9. + +# Invalid inputs +puts abs_max(2, "-1") +# Error: Provide number only! + +puts abs_max("3", "5") +# Error: Provide number only! + +puts abs_max("a", "5") +# Error: Provide number only! From 60d4a4bcbce7b73a1bf48437ea92a973bb3caa7b Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Tue, 1 Jun 2021 13:11:08 -0700 Subject: [PATCH 115/121] Add hash solution --- .../arrays/strings/common_characters.rb | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/data_structures/arrays/strings/common_characters.rb b/data_structures/arrays/strings/common_characters.rb index 42205aa..6d126c5 100644 --- a/data_structures/arrays/strings/common_characters.rb +++ b/data_structures/arrays/strings/common_characters.rb @@ -9,11 +9,43 @@ # You may return the answer in any order. # # Example 1: -# # Input: ["bella","label","roller"] # Output: ["e","l","l"] # # Example 2: -# # Input: ["cool","lock","cook"] -# Output: ["c","o"] \ No newline at end of file +# Output: ["c","o"] + +# +# Approach 1: Hash +# +# Time Complexity: O(n) +# +def common_characters(arr) + target_count = arr.count + + hash = Hash.new(0) + (0...target_count).each do |i| + arr[i].split('').each do |letter| + hash[letter] += 1 + end + end + + result = [] + hash.each do |k, v| + while v >= target_count + if v >= target_count + result << k + v -= target_count + end + end + end + + result +end + +puts common_characters(["bella","label","roller"]) +# => ["e","l","l"] + +puts common_characters(["cool","lock","cook"]) +# => ["c","o"] \ No newline at end of file From 7e95391397d7a86316cdf9836ba061d232d40696 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 2 Jun 2021 06:13:08 +0000 Subject: [PATCH 116/121] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index f709f0f..79cdbc8 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -79,8 +79,8 @@ * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/fibonacci.rb) ## Maths - * [Abs Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_max.rb) * [Abs](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs.rb) + * [Abs Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_max.rb) * [Abs Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_test.rb) * [Add](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add.rb) * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add_digits.rb) From 046560174629909d2348cad964ae320719530aec Mon Sep 17 00:00:00 2001 From: Sahil Afrid Farookhi Date: Wed, 2 Jun 2021 12:19:09 +0530 Subject: [PATCH 117/121] abs min feature implementation --- DIRECTORY.md | 1 + maths/abs_min.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 maths/abs_min.rb diff --git a/DIRECTORY.md b/DIRECTORY.md index f709f0f..ba9fb5c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -80,6 +80,7 @@ ## Maths * [Abs Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_max.rb) + * [Abs Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_min.rb) * [Abs](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs.rb) * [Abs Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_test.rb) * [Add](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add.rb) diff --git a/maths/abs_min.rb b/maths/abs_min.rb new file mode 100644 index 0000000..20e341c --- /dev/null +++ b/maths/abs_min.rb @@ -0,0 +1,34 @@ +# A ruby program to find absolute minimum +# Mathematical representation of abs min = ((a + b - absoulte(a - b)) / 2) + +def abs_min(x, y) + num = x - y + min_value = ((x + y - num.abs()) / 2) + "The Abs Min of #{x} and #{y} is #{min_value}." + rescue + "Error: Provide number only!" +end + +# +# Valid inputs +# +puts abs_min(10, 20) +# The Abs Min of 10 and 20 is 10. + +puts abs_min(-10, -1) +# The Abs Min of -10 and -1 is -10. + +puts abs_min(9, -121) +# The Abs Min of 9 and -121 is -121. + +# +# Invalid inputs +# +puts abs_min(2, "-1") +# Error: Provide number only! + +puts abs_min("3", "5") +# Error: Provide number only! + +puts abs_min("a", "5") +# Error: Provide number only! From d41ed0d5952b1f966f8bc691591725be14139e72 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 2 Jun 2021 07:16:42 +0000 Subject: [PATCH 118/121] updating DIRECTORY.md --- DIRECTORY.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 7f646d6..cb59b3e 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -79,10 +79,9 @@ * [Fibonacci](https://github.com/TheAlgorithms/Ruby/blob/master/dynamic_programming/fibonacci.rb) ## Maths - * [Abs Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_max.rb) - * [Abs Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_min.rb) * [Abs](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs.rb) * [Abs Max](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_max.rb) + * [Abs Min](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_min.rb) * [Abs Test](https://github.com/TheAlgorithms/Ruby/blob/master/maths/abs_test.rb) * [Add](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add.rb) * [Add Digits](https://github.com/TheAlgorithms/Ruby/blob/master/maths/add_digits.rb) From 3a104e9ff0c018475c75bb75d945119041560240 Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Thu, 3 Jun 2021 10:11:21 -0700 Subject: [PATCH 119/121] Move solution to hash table section --- DIRECTORY.md | 2 +- .../{arrays/strings => hash_table}/common_characters.rb | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename data_structures/{arrays/strings => hash_table}/common_characters.rb (100%) diff --git a/DIRECTORY.md b/DIRECTORY.md index fcd790b..43f1f82 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -22,7 +22,6 @@ * [Sort Squares Of An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/sort_squares_of_an_array.rb) * Strings * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/anagram_checker.rb) - * [Common Characters](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/common_characters.rb) * [Jewels And Stones](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/jewels_and_stones.rb) * [Remove Vowels](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/remove_vowels.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/two_sum.rb) @@ -38,6 +37,7 @@ * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/two_sum.rb) * Linked Lists * [Circular Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/circular_linked_list.rb) + * [Common Characters](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/common_characters.rb) * [Doubly Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/doubly_linked_list.rb) * [Singly Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/singly_linked_list.rb) * Queues diff --git a/data_structures/arrays/strings/common_characters.rb b/data_structures/hash_table/common_characters.rb similarity index 100% rename from data_structures/arrays/strings/common_characters.rb rename to data_structures/hash_table/common_characters.rb From c01e4b5b0c423ab6840ce6975f74abdb5abac85a Mon Sep 17 00:00:00 2001 From: Jessica Kwok Date: Thu, 3 Jun 2021 10:12:02 -0700 Subject: [PATCH 120/121] Update directory with solution in hash table section --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 43f1f82..c94148f 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -32,12 +32,12 @@ * [Postorder Traversal](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/binary_trees/postorder_traversal.rb) * [Preorder Traversal](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/binary_trees/preorder_traversal.rb) * Hash Table + * [Common Characters](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/common_characters.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/find_all_duplicates_in_an_array.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/richest_customer_wealth.rb) * [Two Sum](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/two_sum.rb) * Linked Lists * [Circular Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/circular_linked_list.rb) - * [Common Characters](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/common_characters.rb) * [Doubly Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/doubly_linked_list.rb) * [Singly Linked List](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/linked_lists/singly_linked_list.rb) * Queues From aece3afeee5232df496df8d382cfae1c29c83f79 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 8 Jun 2021 02:39:00 +0000 Subject: [PATCH 121/121] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index c9c954d..6babc0a 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -51,7 +51,7 @@ * Hash Table * [Anagram Checker](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/anagram_checker.rb) * [Arrays Intersection](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/arrays_intersection.rb) - * [Common Characters](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/arrays/strings/common_characters.rb) + * [Common Characters](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/common_characters.rb) * [Find All Duplicates In An Array](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/find_all_duplicates_in_an_array.rb) * [Good Pairs](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/good_pairs.rb) * [Richest Customer Wealth](https://github.com/TheAlgorithms/Ruby/blob/master/data_structures/hash_table/richest_customer_wealth.rb)