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
my palindrome solution in go #46
Conversation
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.
I don't think this will work for say AA11BB.
or we are not considering mixed letters and numbers.
return false | ||
} | ||
// 256 chars in ascii charset | ||
ords := make([]int, 256) |
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.
Fun idea to pre-make the map
if ords[i]%2 != 0 { | ||
oddCount++ | ||
} | ||
if oddCount > 1 { |
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.
nice to interrupt as early as possible 💯
tables := []struct { | ||
x interface{} | ||
y bool | ||
}{ | ||
{"carrace", true}, | ||
{"", false}, | ||
{"annnab", false}, | ||
{41231234, true}, | ||
} | ||
|
||
for _, table := range tables { | ||
result := CanMakePalindrome(table.x) | ||
if result != table.y { | ||
t.Error("FAIL: CanMakePalindrome of: ", result, "was incorrect, got: ", result, "expected: ", table.y) | ||
} else { | ||
fmt.Println("SUCCESS: CanMakePalindrome of: ", result, "was correct, got: ", result, "expected: ", table.y) | ||
} | ||
} |
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.
really cool
If they are converted to string then ranging over them should return each character’s ascii value. Numbers have an ascii encoding also in the 256 charset so it should work. I am incrementing the index in the int slice of 0s that corresponds to the ascii encoding. I’ll add it to the test table tomorrow to make sure, but I don’t see why it wouldn’t work. |
@birenderjit just to follow up, I added that test case to the table and it passed. |
Nice!!
… On Apr 21, 2021, at 9:14 AM, Dennis R Kennetz ***@***.***> wrote:
@birenderjit <https://github.com/birenderjit> just to follow up, I added that test case to the table and it passed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#46 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAF6UGKZQBGOIAO2D374MYDTJ3MVVANCNFSM43JESKDQ>.
|
can be run in this directory by running
go test
. I've only handled the types of int and string in my type conversions (but I had a fun time writing a type converter). I also got my hands a little dirty with writing test tables!