Beta

Advanced cow farm

Description
Loading description...
Graphics
Algorithms
Design Patterns
Fundamentals
Lists
  • Please sign in or sign up to leave a comment.
  • malashonock Avatar

    Great kata! The only minor issue I encountered was mis-casing of dateOfbirth property (proper camelCase would be dateOfBirth).

  • mamamia5x Avatar

    Here's a random date generator I made so you can use an actual Date of Birth for the random tests. I made the year from 2000-2022, cow's have a life exepectancy of about 20 years.

    var date = "";
    var year = "20" + Math.floor(Math.random()*22).toString().padStart(2,"0");
    var month = (Math.floor(Math.random()*12)+1)
    var day = Math.floor(Math.random()*31)+1;
    var hour = Math.floor(Math.random()*24).toString().padStart(2,"0");
    var min = Math.floor(Math.random()*60).toString().padStart(2,"0");
    if (month == 2){
        if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) day = Math.floor(Math.random()*29)+1;
        else day = Math.floor(Math.random()*28)+1;
    }
    else if (month == 4 || month == 6 || month == 9 || month == 11){
        day = Math.floor(Math.random()*30)+1;
    }
    month = month.toString().padStart(2,"0")
    date = year+"-"+month+"-"+day.toString().padStart(2,"0")+ " " + hour +":"+min;
    
    // random outputs:
    // 2003-12-18 13:42
    // 2016-05-23 02:28
    // 2010-10-20 02:24
    // 2000-03-01 21:37
    // 2008-08-06 11:58
    
    • hobovsky Avatar

      Can't you just do Date(year:2000).add(days: random(20*365)).format('yyyy-MM-dd') in Javascript?
      Handling calendars maually is asking for trouble.

      let date = new Date(2000, 0, Math.random() * 20 * 365 + 1 | 0).toISOString().slice(0, 10);

    • mamamia5x Avatar

      I kinda accounted for that. But yeah, calenders are dumb.

      But if paxompaxom wanted to, he could do that and then use a random time generator.

      Is there a chance that Feb 29th occurs in let date = new Date(2000, 0, Math.random() * 20 * 365 + 1 | 0).toISOString().slice(0, 10);?

    • hobovsky Avatar

      Is there a chance that Feb 29th occurs in [code] ?

      There is, but small. But in your 'manual' implementation it's just the same. If author wants to target specifically leap years with random tests, they need to tune the generator to ensure generation of such dates:

      it("Leap years", () => {
      
        let date = new Date(2000 + random(5) * 4, 1, 29).toISOString().slice(0, 10); // luckily, year 2000 was a leap year
        ...
      });
      

      or something, depending on what exactly is needed.

    • vldnvsk Avatar

      In general, the Date Of Birth field does not have to be in date format, the only condition is that it is a string equal to 16 characters! But thanks for the improvements you suggested! I applied random date generation which you and mamamia5x suggested

      Suggestion marked resolved by vldnvsk 2 years ago
  • mamamia5x Avatar

    I like the idea. I think it will be a good idea to have an image of a generated code, but have grid lines in it. It would make it easier for me to see what each grid represents, rather than having just telling me what each is.

    • vldnvsk Avatar

      Good idea, thanks! In addition to the current description, I will add an image with a grid showing how the information will be displayed in the result

    • mamamia5x Avatar

      Thanks! This will make it way easier for people to decode the image and know what they'll have to print.

    • mamamia5x Avatar

      Also, this part kidna confuses me.

      Next, a string of the form <id><name><dateOfBirth> is formed from the fields - id, name, dateOfBirth. The name field is padded with spaces at the end of up to 10 characters.

      The resulting string is converted into a byte array — each character of the string is assigned a corresponding ASCII code (a number from 0 to 255).

      Is this just one string composed of all 3 forms combined (with name being a string with a length of 10)? Or is it 3 seperate strings?

      Edit, I think I figured this part out. It's <[id]><[name]><[dateOfBirth]>. I recommend putting an example like <0123456789><wisper cow><2019-06-11 00:00>

    • vldnvsk Avatar

      done

      Suggestion marked resolved by vldnvsk 2 years ago
    • mamamia5x Avatar

      Wow! That image helps out a lot!

  • Voile Avatar

    What's generated isn't a QR code at all, so it shouldn't even be called as such.

    There is already a kata on generating QR code (and one on QR code message encoding) which are both much, much more difficult than what is required by this kata.

    And if we aren't generating a QR code, there isn't much reason to turn it into a canvas and comparing the image content by certain base64 expressions, since there can be a million things that can cause the result to be different (format? PNG compression? Resolution? Pixel aliasing/alignment?). A 2D array is already sufficient.

    • vldnvsk Avatar

      Yes you are right it is not a QR code. Therefore, I will remove any mention of QR code from the description. But I want to leave the string in base64 as the return value as it is, since this is a rather unusual resulting value for tasks on codewars and more visual

    • vldnvsk Avatar

      done

      Issue marked resolved by vldnvsk 2 years ago
  • Fbasham Avatar

    This comment has been hidden.