6 kyu
Unique Strings
278 of 463aditya7iyengar
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
python test framework takes too long
Pretty nice coding challenge.
How does "Aa" have only 1n combination? Can't this be arranged "Aa" and "aA"? I would think this would be 2n if rearrangement of "ABBb" is 4n ("ABBB","BABB","BBAB","BBBA")
Maybe if I figure the above I could figure why I'm passing this test "ABcDEFgHIJ" but failing "ABcDEFgHIJbaslidbailsbdilasbdkanmsdklhkbHSJKHVDASH".
Hi @ameenj - in Description it says "Strings are case insensitive".
So - in the context of this kata - the string "Aa" is the same as "aa" "AA" and "aA".
That's why there are 4 "rearrangements" of "ABBb" - because, ignoring case, they are the 4 you gave in your comment.
Well that makes sense now. Thanks :)
This comment has been hidden.
you are converting to
BigInt
too late, overflow already happens in yourfact
functionAh I see, thank you for taking the time to point that out!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please use markdown to format your code or it's not readable, it is explained there: https://docs.codewars.com/training/troubleshooting/#post-discourse
Your code has probably the same problem as several persons that have posted questions recently (see comments below). Some operation you are doing is introducing useless inaccuracies, I guess.
I've copied your solution locally to my computer -- as akar-0 said, in future if you use markdown it's much easier for people to troubleshoot -- your logic is basically fine, your code currently has 2 errors in its implementation.
The first error is a small "programming" error, which is introducing inaccuracies - check your mathematical operations in your code to see if you can find a place where you aren't working correctly with integer values.
The second error is a more important "mathematical" error: you don't need to use large test cases to debug it: try your code on the following string and then calculate the correct answer manually (pen and paper) to see where you are going wrong:
'ABBB' your code gives 8, correct answer is 4. Try to figure out where the discrepancy comes from.
I see, thank you to both of you. I'll try again + read the instruction
hm, i can get the test cases but i haven't figured out what to do in certain cases yet.
This comment has been hidden.
You must return an exact answer.
Floating point values are not exact.
do i have to rework how my program works?
You should rework it to work with integers, not floats or doubles. Python has arbitrary precision integers; they'll work.
This comment has been hidden.
Please use a spoiler flag, your post contains hints to solve the kata (I've just put the flag on for you). I am not going to give you the answer, your code has a flaw that introduces possible imprecision. It doesn't matter with small numbers, but with large values it becomes sensible. Hint: it's just one operation.
That makes sense. Using the wrong datatype will preserve precision in the first 20 or so digits, and lose precision thereafter.
( If you had mentioned in which of the 8 available languages you're solving, you might have gotten a more specific answer. But you didn't, so you don't. )
Thank you, I'm very new to this. Will keep trying.
JS translation
This translation modifies the description. (
BigInt
needed to be specified. )Why not just insert a comment in solution set up? I mean, for typed languages, the signature gives the output type and there is no need to pollute the description with all the types for all languages. Moreover BigInts are straigthforward in JS, they don't add any difficulty to the task (with difference to other languages like Go or Rust for example).
Approved.
Because IMO the description should specify it; you should be told to work in BigInts before you train. Solution setup is too late for my taste.
This is my opinion; other opinions may be available. But since I made the translation, it's in the description.
ETA: the problems posted ( in what seems to be Python ) since I decided to specify bigints in the description make me think I was right :/
Go translation
Approved
D translation
Approved
Rust translation
Approved
Haskell translation
Approved
This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/125.
Please join the discussion to help us identify duplicate kata and retire them.
This one was decided to stay !
Ruby 3.0 should be enabled (Refer this & this for more detail)
Please use new python test framework.
Fixed by hobovsky.
This comment has been hidden.
the issue comes from your code, you are using float division instead of integer division
This comment has been hidden.
Answer to this question will give away the solution.
"Process exited prematurely with a SIGSEGV signal."
Python 2.7
Please check it!
Python 2.7 works fine. Its probobly a problem with your code. Don't try and calculate all the permutations as this is too slow and is probobly what is making your code time out. There is a much better math based approach :P
This comment has been hidden.
It works. Its just too slow.
This comment has been hidden.
There is nothing wrong with this kata. Just because your code doesn't work, it doesn't me that this kata is broken.
Go into your IDE and try to calculate all the permutations of 'qwertyuiopasdfghjklz'. See how long that will take.
Not an issue of the kata.
Well, it's much more of a mathematical problem, than a programming one. Then, if you want to have an elegant solution, you have to import a bunch of modules... I'm a bit undecided :-)
This comment has been hidden.
That is the part of the puzzle for you to figure out.
Not an issue. If your algorithm is not good enough please try again ;-)
Who approved this kata? This is a duplicate of https://www.codewars.com/kata/number-of-permutations-without-repetitions.
At the end of the day that kata was decided to be retired while THIS kata was decided to stay (CW, Github), so I think this issue may be resolved now
The Ruby and Python versions should have a test with an empty string. There already are some submitted solutions that fail in this case.
damn you... ;p
This comment has been hidden.
1 of course!
This comment has been hidden.
Couldn't approve changes, but updated the test cases manually.
Random tests needed in Elixir and Ruby.
Ruby seems to be OK. Anybody feels like porting them to Elixir?!
Python Translation Kumited :D
This comment has been hidden.
Sorry, just added this to the description: "HINT: Getting all the uniq strings and calling length on that isn't a great solution for this problem. It can be done a lot faster.."
I don't want people to just get the permutations and count them, there's a much better way to do this.