-
Notifications
You must be signed in to change notification settings - Fork 47
Space - Stephanie #28
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
base: master
Are you sure you want to change the base?
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,3 @@ | ||
def intersection(list1, list2) | ||
raise NotImplementedError, "Intersection not implemented" | ||
intersect = list1 & list2 | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,17 @@ | ||||||
|
||||||
def palindrome_permutation?(string) | ||||||
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 works, but see my note below. |
||||||
raise NotImplementedError, "palindrome_permutation? not implemented" | ||||||
end | ||||||
|
||||||
letter_hash = {} | ||||||
string.chars.map do |char| | ||||||
letter_hash["#{char}"] = string.count(char) | ||||||
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.
It could be better doing this:
Suggested change
|
||||||
end | ||||||
|
||||||
odd_count = 0 | ||||||
letter_hash.each do |key, value| | ||||||
value.odd? ? (odd_count += 1) : next | ||||||
end | ||||||
|
||||||
odd_count > 1 ? (return false) : (return true) | ||||||
|
||||||
end | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
|
||
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 fails for |
||
raise NotImplementedError, "permutations? not implemented" | ||
return false if string1.length != string2.length | ||
|
||
string1.chars.each do |char| | ||
if string2.include?(char) | ||
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.
|
||
string1.slice!(char) | ||
string2.slice!(char) | ||
end | ||
end | ||
|
||
return true if string1.empty? && string2.empty? | ||
return false | ||
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.
That works as it uses a feature of Ruby. Do think about how you'd solve it with a hash.