Ad
  • Custom User Avatar

    Thank you!)

  • Custom User Avatar

    Thank you! 😉

  • Custom User Avatar

    Golang translation 🕖🕜🕧

  • Custom User Avatar

    you should open a suggestion in the kata's discourse page, with a link to the translation. Kata authors can approve translations of their own kata; if they have been inactive in the past month, users with more than 4,000 honor can approve them

  • Custom User Avatar

    I've added a translation to another kata. Could you take a look at it? I don't know who can approve translations. Would you approve it?

  • Custom User Avatar

    Thank you very much for the explanation. I have already familiarized myself with the Go documentation and now know a bit more about working with the "math/rand" package :)

  • Custom User Avatar
    • you are not required to a make line-by-line translation of the original kata. Use what is idiomatic in your language; and if the original fixed or random tests are poorly written or do not adequately cover all the cases, feel free to do better in your own translation
    • Sorry, I did not see that the description indicates the range of the input length (from 1 to 10,000). The upper bound can be safely ignored though: testing large strings adds nothing to the task and only makes it harder to debug
    • The way pseudo-random number generators work is by starting from some number (the seed) and applying various operations to it in a deterministic way, so the same seed will always generate the same sequence, which is not what we want on Codewars, otherwise some solvers could just hardcode every answer. So the seed is usually choosen via another source of randomness, which is often the system time (time.Now() in Go).
      However, apparently, as of Go 1.20, it is not necessary to call seed anymore: the language will ensure that the RNG is seeded randomly at program startup. Before Go 1.20, the seed was 1 by default.
    • You can find guidelines about translations here and about the preloaded section here. Basically, the preloaded section is used in some katas when it is necessary to make some variables, functions or datatypes available to the user. You do not need one for this kata.
  • Custom User Avatar

    I removed the rand.Seed() function because the documentation says that the function is deprecated, verbatim:

    Deprecated: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator.

    Link: https://pkg.go.dev/math/rand#Seed

  • Custom User Avatar

    Also, could you tell me what the Preloaded tab is for?

  • Custom User Avatar

    Could you please help me understand the rand.Seed(time.Now().UnixNano()) function? I have run some tests locally without using this function. I called rand.Intn(50) 10 times in a loop and each time I ran the programme I got a different set of numbers. In this case, I can't understand why forums recommend using the current time to get different sets of data. I will be really grateful for your explanations.

  • Custom User Avatar

    Your remarks were absolutely fair. I have taken your advice into account and made the appropriate changes.

  • Custom User Avatar

    The original kata also has an unnecessary line:

    var l = big ? rand(1000, 10000) : rand(1, 20);
    var len = l || rand(2, 8);
    

    The rand(2, 8) function will never execute.

  • Custom User Avatar

    Yeah, I forgot about that tab. Already fixed it. Thank you!

  • Custom User Avatar
    • you should not test giant strings: this is not a performance kata, testing very large strings only makes debugging harder. stick to a reasonable maximum length, around 50 or so
    • the random number generator should only be seeded once. currently you call rand.Seed(time.Now().UnixNano()) for every string: it is better to put that line in the random tests block, out of the loop
    • initial code should contain a return statement (like return 0) so that it compiles. It is customary on Codewars to avoid that the initial code crashes / fails to compile, so that solvers can immediately try the code to see how the tests work
    • your letter generation algorithm is hard to understand, and can generate characters that are not letters. i suggest something like this:
    var a int
    if rand.Intn(2) == 1 {
        a = 'a'
    } else {
        a = 'A'
    }
    rs[i] = rune(a + rand.Intn(26))
    
    • in the tests' block names, 'should works' should be spelled 'should work' (the mistake was in the original kata)
  • Custom User Avatar

    good, but you forgot to add the message to the sample tests too

  • Loading more items...