To be graded#65
To be graded#65trashcanmonster8 wants to merge 3 commits intopaircolumbus:masterfrom trashcanmonster8:master
Conversation
I am interested in your thoughts on this algorithm. I have commented my thoughts about it. I am wondering if there are any cases that can fool this algorithm.
mikegee
left a comment
There was a problem hiding this comment.
I love that you have a unique solution to this problem. But, I'm not convinced it handles all input correctly. If ASCII codes started at 1, it surely would have bugs, right?
Since an anagram means two words have the same letters, we're expecting canonical to return the input word's letters.
|
I was thinking if I made a function that would convert every letter to a
unique prime number, then the algorithm would work every time. But then I
would have to know every possible character input. Is there a way to make a
function (hash right?) that can make additional unique keys I'd the user
inputs a new character and make the value the next prime number that I
haven't used?
…On Dec 2, 2016 7:50 AM, "Michael Gee" ***@***.***> wrote:
***@***.**** commented on this pull request.
I love that you have a unique solution to this problem. But, I'm not
convinced it handles all input correctly. If ASCII codes started at 1, it
surely would have bugs, right?
Since an anagram means two words have the same letters, we're expecting
canonical to return the input word's letters.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#65 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVuix9XGWeZ_27ZVFM1a0iXJlesuP9Cqks5rEBQHgaJpZM4LCOkM>
.
|
|
I threw together a tester and found some problem "words": ["sjkip", "sbjxk"]
["wxsby", "wyisp"]
["nnmlf", "mlyfd"]
["jncxw", "iyxjf"] |
|
Here's something that might help: |
|
While the concept remains the same, I make a hash that maps each ascii characters to a prime by iterating through numbers 0 to 255. Thus each set of characters has a unique set of primes with a unique product.
|
I updated the algorithm. If you got the time, let me know what you think! Thanks. |
|
Check out some of the other pull requests on this problem... |
anagram_detector.rb
Outdated
| #Furthermore, it is less likely to happen as the strings get longer since the sp | ||
| #ecific value of the product would be hard to match with those large numbers. | ||
| #each ascii character is assigned a unique prime number | ||
| (0..255).each { |asciiNumber| @alphabet[asciiNumber.chr] = primes.next} |
There was a problem hiding this comment.
By convention variables in ruby are snaked_cased, not camelCased
qubbit
left a comment
There was a problem hiding this comment.
Your solution probably won't work for unicode strings. Oh well
mikegee
left a comment
There was a problem hiding this comment.
I think this is neat, but it is still overly complicated for the task. 😺
anagram_detector.rb
Outdated
| #initialize the variable product | ||
| product = 1 | ||
|
|
||
| for i in 0..(word.length - 1) |
There was a problem hiding this comment.
To iterate over the characters in a string, use String#chars.
Looked at string/array methods to develop a simipler algorithm.
|
|
||
| #Editting detect_anagram in this manner would also decrease the likelihood of th | ||
| #e above exception. | ||
| def detect_anagram(word1, word2) |
I am interested in your thoughts on this algorithm. I have commented my
thoughts about it. I am wondering if there are any cases that can fool
this algorithm.