Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
no need to check if numbers are repeated, just check for membership in the subset
I got it. Thank you so much!
Oh ok nevermind what I said then, I thought it had some special meaning. C does have enumerated types (
enum
s), and it would be perfectly reasonable to haveenum outcome { LOSE = false, WIN = true};
hereI don't know TS either ( I know JS, but it doesn't have the
enum
type ).But I think they're effectively the same ( up to implementation details ).
he should rather look up the comma and parenthesis operators. JavaScript does not have tuples :p
Not a kata issue.
You're failing because your code is incorrect. Look up
includes
on MDN.This comment is hidden because it contains spoiler information about the solution
sorry for being a bit dumb : what's the difference between an
enum
and anEnumerable
? I know you dont know C, but let's take as example a TypeScriptenum
, which are syntactically identical to C onesI am very much used to
Boolean
being anEnumerable
in Haskell; the concept fits perfectly ( andcoerce = toEnum . fromEnum
works perfectly for customEnumerable
s that are isomorphic toBoolean
s ).But if that's not a thing in C, maybe we should not be blaming a
7kyu
kata for not using this useful abstraction in a language that doesn't have it ( even if it could be retrofitted quite nicely ).bool
is not implemented as anenum bool { false, true };
if that's what you mean by enumerable. the C standard does not mention the word enumerableSloppy code, or optimised code?
"Enumerable" would mean they have enum values I guess ( just quoting Dinglemouse here - is this not a well-defined concept in C? ). It would mean some conversion ( or coercion ) to and from ( unsigned, bounded? ) integers is possible.
in C
bool
is an integer type that can only hold two values,0
and1
.true
andfalse
are just macros that expand to1
and0
, respectively.NULL
pointers and integral-type zeroes are falsy, everything else is truthy (this includes0.0
, sadly).bool
is not implemented as anenum bool { false, true };
if that's what you mean by enumerablealso, I agree that
WIN
being truthy andLOSE
falsy would make sense, but I did not do it for the reason that I said, it might allow sloppy code to take advantage of memory that happens to be zeroedLOSE / WIN are isomorphic to booleans FALSE / TRUE ( and it could be argued that the return value should actually have been a boolean ). Are booleans enumerable? ( I don't know C. ) If so, it would not seem unreasonable to give LOSE / WIN the same values as FALSE / TRUE.
the problem is that
0
is a value that's going to appear in memory in a lot of places, and this can result in sloppy code that passes the tests (code that forgets to initialize stuff or to return values for example). So I try to prevent that with enum values above0
. In this specific example there would be an use case for things likeif (WIN) { doStuff }
, but most of the time you are not supposed to care about the actual values of enum members, it breaks abstraction.This comment is hidden because it contains spoiler information about the solution
Loading more items...