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.
You're right, that would lead to performance issues since it has to recalculate it. Better to just calculate it once and store it in a variable.
Pretty sure that modern compilers will optimise this away, as long as the length of the string isn't changed in the loop (or declaired as
volatile
).i could try to prevent this by passing integers that are big enough to look like valid memory addresses but i dont think there's much point in it. there are probably plenty of other possible hacks due to the low level nature of C
Characters are just numbers. in ASCII 32==
' '
(in this code 32 is also a bitmask). Why use it? It's shorter, and I try to write short code as a personal challenge.It's the same in C.
But it actually works! Can I ask about your solution?
Why do you use here your interesting type punning macro instead of memcpy() like this?:
memcpy (&ph[1], &nums[0], 4);
memcpy (&ph[6], &nums[3], 4);
memcpy (&ph[10],&nums[6], 4);
tact
has twot
s in it, so it goes against this part of the kata description:with a constant seed, random tests aren't random anymore, so they wouldn't have any purpose (they aren't there just to generate more tests, they are there to prevent some kind of cheats). If you wanna keep track of what's going on, you'll have to print the inputs and extract those where your code fails.
You're right - my mistake that I didn't do it
Fixed.
As seen in the example, the population is rounded in each iteration, so either such a solution won't work in some edge case or it requires some non-trivial proof that rounding can't change the result.