Ad
  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    no you havnt ur blind

  • Custom User Avatar

    Got it, you're right! Thx! 🙏🏻

    However, test cases do not test Unicode, only ASCII.

    "Never do that!" sounds extreme. The intention of Kumite is to challenge and not repeat past solutions.

    This was to similar to the previous 🤷🏻

        public static int SameCase(char a, char b)
        {
            if (!char.IsLetter(a) || !char.IsLetter(b)) return -1;
            return char.ToUpper(a) == char.ToUpper(b) ? 1 : 0;
        }
    
  • Custom User Avatar

    Because Unicode

  • Custom User Avatar

    Because Unicode

  • Custom User Avatar

    TRUE! I've seen it on a map. 🔭😏

  • Custom User Avatar

    you are wrong because the earht is flat

  • Custom User Avatar

    Never do that

  • Custom User Avatar

    Boxing won't occur here.

    char.IsUpper takes a char and returns a bool.

    bool (or System.Boolean) has a Equals(bool) override, so the compiler won't choose the Object.Equals(Object) method.

    Using == is still better practice, though, as

    1. it's more idiomatic; and
    2. it avoids having to perform a method call (Equals), though the I'm nearly positive bool.Equals(bool) would be inlined
  • Custom User Avatar

    The ValueType class that all structs implicitly inherit don't have a generic implementation so only the object base class' .Equals method is implemented, meaning you'll have to go through expensive boxing for a simple comparison. This can even involve reflection

    See here https://source.dot.net/#System.Private.CoreLib/src/System/ValueType.cs

    Fortunately, seemingly all value types provided by .NET implement their own .Equals method to avoid boxing. So do record structs

  • Custom User Avatar

    You're right, vectorMax should be initialized to that to account for negatives.

    Copying the vectors isn't an issue. You need two vectors to intrinsically compare two vectors. Doing this alone already compensates for the time spent copying some memory around. Memory is cheap. In fact, doing most things in C# involve allocating memory. A foreach loop even creates copies of values.

    From benchmarks I have done a while ago, this method of comparing values in an array is magnitudes faster than any scalar method.

  • Custom User Avatar

    You iterate through every vector which would not any faster than copying a very small block of memory after using abstracted intrinsics to compare two vectors. Under the hood, the Max method allows for "jit intrinsic expansions" so you should save the entirety of the compared vectors until you're done with vectors

  • Custom User Avatar

    Thanks for explaining your choices :)

  • Custom User Avatar

    var vectorMax = Vector<int>.Zero; but var vectorMax = Vector<int>(int.MinValue); should be, I think

    var blockVector = new Vector<int>(nums, blockIndex); copy memory

    vectorMax = Vector.Max(vectorMax, blockVector); copy memory

    2 memory coping. Is it faster then classic loop?

  • Loading more items...