Ad
  • Custom User Avatar

    approved

  • Custom User Avatar

    in tester(), the input parameter should be const, and using strdup() to copy it to the user's string would be cleaner than using a VLA (though you will need to declare strdup() and free word at the end):

    static void tester(const char *input, const char *expected) {
        extern char *strdup(const char *);
        char *word = strdup(input);
        // ... the rest of the logic stays the same
        free(word);
    }
    
  • Custom User Avatar
    • removes the testing code from preloaded
    • add quotes around strings in assertion messages
    • adds a note about memory allocation of the output in the solution setup
    • adds a valid return value in the solution setup
  • Custom User Avatar

    some of your test cases seem invalid, e.g. in the fixed tests:

                                      ↓ 'g' is a consonant and should be followed by "egg" as well
    word = "beggaceggonegg aneggdegg eggsegg"
     
    Submitted: "bacon and eggoas<@"
    Expected:  "bacon and eggs"
    

    this happens in the random tests too

  • Custom User Avatar

    I cannot seem to upgrade this kata to PHP 8.0. Since this version, the Codewars runner no longer concatenates the user file and the tests file, though the user file is autoloaded. The specific combination that seems to prevent the upgrade is that, in this kata, the user has to define a class as well as several variables.

    require "_solution.php"; seems necessary to pull the user's variables into the test suite's scope (they still need to be declared with global, e.g. global $user_variable; var_dump ($user_variable);.

    This works when there is no class in the user's file. But when there is a class, e.g. class UserClass {}, the tests do not compile: Fatal error: Cannot declare class UserClass, because the name is already in use in /workspace/default/_solution.php on line 1. Using require_once instead of require makes the test compile again, but then the user variables are no longer visible (they default to NULL).

    It seems that the autoloading conflicts with require when there are classes.

  • Custom User Avatar
    • why don't you use cr_assert_str_eq() instead of calling strcmp() yourself for the content equality assertion ?
    • casting 64-bit addresses to 32-bit unsigned is not robust. if you want to display those addresses (though i think it is not necessary), you can use the %p format instead (you will need to cast the addresses to void * in the printf() arguments in that case):
    char *pointer = "abc";
    printf("pointer has address %p\n", (void *)pointer);
    
  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    this was fixed by the upgrade to C# 12

  • Custom User Avatar

    PHP 8.0 should be enabled

  • Custom User Avatar
  • Custom User Avatar

    it seemed to work fine on my machine

    this is not surprising and that's exactly the problem with undefined behavior in C/C++ ... many things can happen depending on the platform, the way the code is run, the compiler, etc. the worst case scenario is when nothing special happens, until that one day when a cryptic bug pops up from nowhere. there are some tools that can help, such as static analyzers. when i ran your code in this one, it correctly detected UB when run with an empty string (warning, this analyzer is free and online but it's a bit slow and the UB diagnostics can be a bit cryptic if you're not well versed on low-level details)

  • Custom User Avatar

    the issue was due to the tests computing the actual answer before the expected one. fixed. I also modified the type signature for C#, as it was not in line with the description, it was taking an object[] instead of an int[] as promised by the description. you will need to refresh the page and reset the sample tests to see the changes.

  • Custom User Avatar

    breaking change:
    changing the signature from

    public static object[] IsVow(object[] a)
    

    to

    public static object[] IsVow(int[] a)
    

    as the description promises:

    Given an array of numbers...

    the only reasons to pass an object[] array containing only integer were to mimic dynamically-typed languages and to allow programming by mutation, which is not typical for C# arrays.

  • Custom User Avatar
    • allocation scheme explained in the initial code
  • Loading more items...