-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Space - Diana #32
base: master
Are you sure you want to change the base?
Space - Diana #32
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,25 @@ | ||||||||||||||||||||||
def intersection(list1, list2) | ||||||||||||||||||||||
raise NotImplementedError, "Intersection not implemented" | ||||||||||||||||||||||
lookup_hash = {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if list1.length < list2.length | ||||||||||||||||||||||
list1.each do |num| | ||||||||||||||||||||||
lookup_hash[num] = true | ||||||||||||||||||||||
end | ||||||||||||||||||||||
|
||||||||||||||||||||||
intersection_array = list2.map do |num| | ||||||||||||||||||||||
num if lookup_hash[num] | ||||||||||||||||||||||
end | ||||||||||||||||||||||
|
||||||||||||||||||||||
return intersection_array.compact | ||||||||||||||||||||||
Comment on lines
+9
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Suggested change
|
||||||||||||||||||||||
else | ||||||||||||||||||||||
list2.each do |num| | ||||||||||||||||||||||
lookup_hash[num] = true | ||||||||||||||||||||||
end | ||||||||||||||||||||||
|
||||||||||||||||||||||
intersection_array = list1.map do |num| | ||||||||||||||||||||||
num if lookup_hash[num] | ||||||||||||||||||||||
end | ||||||||||||||||||||||
|
||||||||||||||||||||||
return intersection_array.compact | ||||||||||||||||||||||
end | ||||||||||||||||||||||
end |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,25 @@ | ||||||||||||||
|
||||||||||||||
def palindrome_permutation?(string) | ||||||||||||||
raise NotImplementedError, "palindrome_permutation? not implemented" | ||||||||||||||
lookup_hash = {} | ||||||||||||||
string.each_char do |letter| | ||||||||||||||
lookup_hash[letter] = 0 | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
string.each_char do |letter| | ||||||||||||||
if lookup_hash[letter] | ||||||||||||||
lookup_hash[letter] += 1 | ||||||||||||||
end | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
number_of_odd = 0 | ||||||||||||||
lookup_hash.each_value do |letter| | ||||||||||||||
number_of_odd += 1 if letter.odd? | ||||||||||||||
end | ||||||||||||||
|
||||||||||||||
if number_of_odd > 1 | ||||||||||||||
return false | ||||||||||||||
else | ||||||||||||||
return true | ||||||||||||||
end | ||||||||||||||
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
|
||
def permutations?(string1, string2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would fail for something like |
||
raise NotImplementedError, "permutations? not implemented" | ||
return false if string1.length != string2.length | ||
|
||
lookup_hash = {} | ||
string1.each_char do |letter| | ||
lookup_hash[letter] = 0 | ||
end | ||
|
||
string2.each_char do |letter| | ||
if lookup_hash[letter] | ||
lookup_hash[letter] = true | ||
end | ||
end | ||
|
||
puts lookup_hash | ||
if lookup_hash.value?(0) | ||
return false | ||
else | ||
return true | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍