6 kyu
Smallest Permutation
888 of 1,552coder334
Loading description...
Fundamentals
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.
11588 should equal 1001588
just tell me why, something wrong in this kata
What was the input value? It seems your number has indeed leading zeros.
No enough explanation
C translation (author gone)
Great kata
n = -482072 answer = -874220
Why is incorrect answer?
Because we're looking for smallest absolute value, your result is highest one.
Thank you
cool kata. good test cases.
Haskell translation
approved by someone
JavaScript Translation
Should use
assert.strictEqual
.assert.equal
will allow strings as a correct answer if it coerces to the right number.how i can change translation after approved?
Fork the existing translation and ask someone to approve it.
I forked
Failed to approve: translation must be pending over a week or the kata author must be inactive for the past month
okey, i just change kata itself
already approved
csharp translation.
post as suggestion next time (approved by someone)
good and basic, nice work! you should add non number validation
Seems you didn't see that one. It's ""worse"" now that you removed the floats: half of the random tests are invalid inputs. => Update the tests to something like:
cheers
um sorry, i think you misunderstood something i updated the kata to have no floats, and negative and positive are both valid that's why it randomly picks a positive or negative number
basically none of the inputs are invalid anymore if that's not what you meant pls comment again
oh, I didn't see the switch in the requirements. perfect, then.
:+1:
[deleted]
Apparently, you're under the impression you're at your grandmother's dining room table, she has spent hours in the kitchen to cook you a fabulous dinner and you don't like it. That would be the moment to not say anything, as my mother taught me. But you are not at your granny's dining room table, this is CodeWars. If you publish a kata, you are inviting criticism ( of it, not of you. and that's the last I'll say about personal attacks ).
Yes, I am saying this is an 8 kyu kata, because it is. The task is sorting an algebraic datatype. In this case, that algebraic datatype is a number composed of digits, but as I mentioned, it could have been a string composed of characters or a generic polymorphic list composed of arbitrary elements ( for which an order is defined ). The particular encoding has no bearing on the essence of the task, decoding and encoding a number as a list of digits does not raise the difficulty above 8, and sorting a list has been done, which makes this a duplicate. I did not give specific examples of previous "sort my list" kata, but if you think I could not, you did not yet encounter a lot of kata I have some across.
go do a real 8 kyu kata and you'll see what i mean for a 1 dan anything below 5 kyu is 8 kyu why am i not surprised 8 kyu kata are super easy
literally everyone disagrees with you i mean 75% of people disagree with you plus the average ranking is 6 kyu and that ranking was before someone trolled and said 1 kyu
From the Kata Best Practices: "Something important to consider when one is writing or editing kata: Is the concept behind this kata novel?"
There are two concepts behind this kata: decoding and encoding a number to and from a list of digits, and sorting the list ( I don't think anybody would sort the number itself ). Neither of those ideas is new, but it requires a more abstract way of looking at the kata. Because the Best Practices specifically mention "the concept behind this kata" and not the specific implementation, I generally take a step back from the specific implementation and try to discern the concept(s) behind it. In this case, I think those concepts have been done before, and have been done often enough, already.
Of course this is not a black and white argument - you can lean slightly back and see a kata about the smallest number with the same digits, or you can run an entire marathon backwards and see a kata about transforming an input. Somewhere inbetween those two a kata about deconstructing a value, sorting the resulting list and constructing it back into a single value is visible. If you think that's too abstract a point of view, I can't say you're wrong. But that's my point of view. I think it's a reasonable abstraction of the kata in the spirit of the Best Practices.
ok then why don't you give me some examples because this is different from something like a simple return sorted(list) thing it specifically says no leading zeros, and you have to account for negatives so you can't turn 10 into 01 did you even read the description
yes it has been done before but this is my first kata and i'm just testing stuff out BESIDES you m ight think it's easy because you're master rank go look at real 8 kyu they are so much easier than this
as said before why don't you give me some of your kata as examples until then i'm just going to ignore you
I also think that comparing this task to sorting is a bit of oversimplification.Removed because already answered above, I missed the answer.
This comment has been hidden.
Just ignore these comments. Johan clearly didn't understand the task, and is shitposting about how it's "simply sorting a list".
@code334 there's no need to throw a tantrum, you know?
to the original personal attack: my grandma lives in china so it means nothing to me i'm still waiting for your example of a duplicate
You are aware thet Johan's opinion is (as he already explained) his opinion, and you do not have to wait for any example from him, and you can just, well, hear him, balance his point of view with points of view of other users, and get over it?
Your kata has a satisfaction rating of 75%. It's a very good score for an easy beta, which not many kata achieve recently, let alone duplicates. Just ressolve the issues, listen to the suggestions (which you did, and that's great), and things should be fine.
hmm ok well i'll just let it go then
No further comment.
for the record: no, it's not 8 kyu...
You're correct, of course. "Basic data type manipulations" are 7 kyu. I was still hung up on trivial algorithms and API reference knowledge ( wait, or is
nativeSort(x)
also 7 kyu already ?!? ).Implementing a simple task overly complex does not, of course, increase the complexity of the task itself though. If inexperience or tunnel vision leads someone to unnecessary complexity, that's not the fault of an essentially simple task.
Don't use the info below rank suggestions, you already know they are overly wrong. It's not 8 kyu because the user has to find the algo on his own. Even if simple. That only justifies to make it 7.
Huh ?!? Would you please listen to yourself?
There is exceedingly little info that is ex cathedra and not invented by users themselves on here. If I'm to invent my own ranks, why is that stuff there !?!?!? Also, if I am to invent my own ranks, who's to say those guys that rank everything 8 are wrong?
yeah, I pretty much listen to myself.
And if PUs were at least a bit capable of looking at other already approved kata, they'd realized already that all these "hints" are pretty wrong and never matched anything of what has been approved for 5 years or even more.
I would suggest changing the requirement of returning
None
to some sentinel integer value, for example -1. Otherwise you risk problems with description when kata gets translated to other languages and translators will create frankensteinous monstrosities like "returnNone
in Pyton, -1 in C,Nothing
in Haskell" and you will get overwhelmed by description merge conflicts.Does there need to be invalid input? Also, 1.5 is float, the rest are int. That probably doesn't translate so well. Why should 1.5 give None? The type? In that case, should one expect strings, lists, elephants too?
I wanted to ask this too, I just held myself back because I am afraid users think I am bugging them too much already :)
However, I thik this could be translated consistently, simply by using floating point numbers as inputs in all languages.
double
can represent integers exactly up to ~2^53, so if translations to statically typed languages (C, Java, C#, etc) would use double precision floating point numbers, there would be no problem. But that's just additional tricky aspect which has to be considered when reviewing translations, and the requirement itself is just distracting. I would vote for removing it and limiting input to valid integers, but I won't fight about it too much.Uniform return values are IMO more important for this kata.
Checking whether a float is integer is such a weird (if not incorrect) thing to do. Especially when types can already express: does not operate on float. And it would be different in python, because python wouldn't do that, it would instead use different types? So then it would make more sense for python to use float for all input.
to the original suggestion: it says "none or language equivalent" if someone else other than you guys says they want to remove float i'll remove float :) if someone says they want to make float and negative valid i'll make them valid
edit: nevermind i'm going to try and make float and negative valid
What is language equivalent of
None
for C and C++? What is return type of this function for C#? What is language equivalent ofNone
in JS?Translations will drown in description merge conflicts.
done! now you can test it i'm pretty sure it works @above i made the changes, you don't need to return None no inputs are invalid anymore
Okay but
1.52 => 1.25
it is not necessarily clear what digits a float has. They're not strings. Arguably, as far as the problem is concerned, this is 152. An integer. So it doesn't need to be string. For example:See the problem?
Negative numbers don't seem to add anything. That's less of a problem but that's my thought there. My thoughts aren't incredibly valuable.
Another problem with floats is that after rearranging their digits, you might not be able to get the exact FP representation, and comparison with
assert_equals
will fail.wait waaaaaaaaaaaaat can you guys explain that again im big confused i changed the description to read "permutation with smallest abs()" but i don't understand what you guys mean by "exact FP representation" and "it is not necessarily clear what digits a float has"
ok natan the digits in a float are just all the digits basically the digits are the same in an int without the decimal point so the digits in 1.52 are the same as the digits in 152 digits in 2.05 are the same as the digits in 205
You probably thinking of float like numbers taught in elementary school. They're not that. Floats approximate values, they are spread out over a large range with gaps between representable values.
1.52 isn't representable either, nor is 2.05
instead, a representable point near it is picked.
You can print a float and get a base 10 representation, and yes that will have digits, but that's a string as opposed to a true representation of the data in memory.
float(2.05)
does not have the digits 2 0 5, if you were to get the ACTUAL digits for these values, you get:Worse yet, it might have infinite digits. (Not sure this can happen, I don't math, but it might be possible) So you would need to use string instead. But int already is able to represent these cases so there's no need.
There's additionally the problem of types. Currently you have
Either Int Double -> Maybe Int
But the problem is representable withInt -> Int
Simpler is better.well yeah maybe but that's not what i'm trying to do wait can you explain to me what changes i should make to code?
more accurately for my purposes, it works like i dont want the actual digits cuz im trying to do smallest permutation of digits (not actual, just the inputted digits)
wait how would i express a float using ints? cuz i'm big confused right now
The inputted digits are not included. (It's not a string) My suggestion is to not include those cases. Or, from my perspective: those cases are representable as positive integers.
You don't want to represent float. Float is not string. You want to represent digits
205
152
Or, you want strings:'2.05'
'1.52'
but it's not really different from205
and152
wait so what i'm trying to say is the value isn't relevant to the original question i'm just looking for the digits
edit: but how would i express the float cases as ints?
edit edit: i think i see what you're saying now, 2.05 can just be 205 right???
edit x 3: i did floats cuz that gets all numbers
You assume that you can make a floating point value out of decimal digits, and it's a wrong assumption. Floating point value (i.e. IEEE-754 value) composed out of:
2
,.
,0
,5
, simply does not exist.If you want to manipulate digits, you either could stick to integers (the best approach IMO), decimals (not supported in many languages), or strings (not really fit this particular task, but would be OK as long as both input and output are strings, but this would make the task somewhat awkward, and opens several other problems).
Just use integers as inputs and outputs of your function, and all will be good.
waaaaaaaaaaaaaaaaat ok
i've removed float
Float is suitable for measurements and other approximations.
If you're not using the word "approximately" when describing a value, then float is definitely not what you want. If you use
==
, float is not what you want.If you lower the size of the unit, then int is still appropriate (12 hundredth's instead of 0.12), otherwise you're looking for Fraction or Decimal. Decimal matches what we're taught in school, fixed number of digits, pretty much a string. Indeed we learn to carry out operations on strings if you think about it.
ohhhhhh i get it now thx for the help :):):)
Actually,
null
. Though you can't nestnull
s in JS like you can nestMaybe
s in Haskell (Nothing
,Just Nothing
,Just Just Nothing
, .. ).Basically, the task here is to
sort
( ascending ) a valid value. That means any input for which an order is defined over the elements of the value ( which could be digits of a number, characters of a string, elements of a list, &c ) will work. There is no reason to complicate the task with negative floats and other insanity, other than making it look like something it is not.It also means any ranking over
8
means you didn't understand the task, and it's a duplicate of a duplicate of a duplicate.I'm not sure the kata is worth saving. If
@failure
learned a few useful things, it's all good and the decent thing to do next is unpublish the kata.is that fixed point numbers?
that's a little harsh are you saying this is 8 kyu? cuz it's not if you haven't got anything good to say or any real feedback then dont say it
let's put it this way: do you have any REAL feedback other than 'it's a duplicate of a duplicate of a duplicate' which you have given no proof of and that i doubt you really have also i really doubt you read everything in here because i removed floats and made the task only integers actually i doubt you even read the description
No, I meant decimals (i.e. numbers using base 10 internal representation), be it fixed point, or floating point. Floating point decimals are a thing, for example C#
decimal
built-in type. Fixed point decimals would be something likejava.math.BigDecimal
or equivalents from other languages with predetermined scale, I think.About this being a duplicate: I've explicitly searched for a kata like "the smallest number with the same digits" and I was not able to find it. IMO it makes a quite nice intro level kata, if technical issues get resolved. I don't think it's a duplicate, or I jsut were not able to find another kata with such idea.
Ah, Binary Coded Decimals. I think the issue is not binary or decimal internal, but floating point or fixed point.
Taking the "is this a duplicate" discussion to its own topic, because I don't get notifications for this one.
Is your kata meant to be solvable by iteration from 0 to
n
checking if the number satisfies the condition of being minimal, and having the same digits? If not, you should take special care of generating some pessimistic input. There are already two digits rearrangement kata (Next bigger number with the same digits and Next smaller number with the same digits) with tests randomized in a way that iterative solutions are able to pass after sufficient (and not that high) amount of resubmits.well i mean that's giong to time out, my test cases go up to 10^7 and there are near 300 of them
Hi again,
I didn't pay enough attention before, sorry, but you need to mix the two types of random cases: use one single batch of random tests and you generate randomly a good or wrong random input. Otherwise, your tests aren't really random (the expected output for the first batch is know upfront, for instance). Use something like this:
note: might be good to have 2 different kinds of valid generators, the second one inserting zeroes in the input, to make sure this is properly tested (after all, that's the main point of the kata)
i randomized the number of tests of each type but the probability of having zeros in a number is decently high (around 1/10??) so there is basically guaranteed chance of having zeros also even if you know the expected output for the first batch there's no way to code that (you can't say if randomtestnumber < 10 return None) and i did it that way so i can sort the tests into groups unless i missed something
just to clarify the random number of tests thing i changed number of negative and float to a random integer from 10 to 15 then a made number of valid tests 10 times the number of negative and float combined
It never occured to me how is random amount of test cases helpful in any way other than creating unbalanced test suites... :)
idk im just listening to the master rank guy
however it might help it be more random idk
warning, there are currently only 1/3 if the random tests that aren't expecting None. The probability if valid inputs should be much higher than invalid inputs.
why provide the input as a string? if that's the type of input, you really should test for stuff like
'0000'
and'000123'
too.So imo, you should rather go for integers as inputs (which would make much more sense considering the context of the task)
i just felt like adding that because it would make things just that much more complicated (like 1% more complicated)
"Do one thing, and do it well."
Complicating a task with an unrelated task is almost never a good idea. Input validation is almost always unrelated ( unless you're writing a parser or something ).
ETA: Google that phrase and learn why it's a good idea: composability. Composability is A Good Thing.
ok then if two dan rank tell me to do it then im gonna do it
done!
hi,
nice enough, but:
minPermutation('0') => ''
It should be'0'
"..."
which are working in most languages for strings while'...'
doesn't.snake_case
, hencemin_permutation
cheers
ok thanks!!!! going to make your changes right now
done! if you see anything else please let me know :)
@Blind, I think you're mostly right on those points ( the second bullet stuff ), but enforcing them on low-level kata for low-level authors is going to be a Herculean task. I'd be afraid you'll just burn yourself out that much sooner, for very little gain.
It's absolutely useful, but it's just so much work.
Hi!
Very nice kata, enjoying it.
I don't quite get why permuting 10 doesn't give 01 as a min output, however. Unless the length > the value of the input is the rule. If someone could clarify, please. :)
Many thanks.
because it's not a valid number (as string)
the problem states that leading 0s aren't allowed. so 01 would be invalid
elaborate please?