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.
LOL! I made it my personal challenge to solve all Codewars C problems with short but readable solutions. I've developed my own style throughout the years, which is not to everyone's taste, but I obviously like it. I'm almost there, but am now stuck with the hardest problems... It requires more of my time to solve these remaining problems, I'm not sure I will have enough time.
There are lots of interesting problems out there!
See if you can solve https://www.codewars.com/kata/5993c1d917bc97d05d000068/c
Yeah, I’m a pretty weird dude. I have an entire list of various sayings, quotes, and aphorisms from different people and languages. I'm pretty sure that particular one comes from a Latin book I have called Sententiae by Publilius Syrus. Most of the Latin ones I use are from him. He has a ton of good ones. You should check it out.
Yes, I’ve learned quite a few tricks from Code Golf on Stack Exchange. That said, I don’t post there like I do on Codewars. I just really enjoy trying to find the shortest C solution possible for each kata. It’s not just about code golf though, sometimes it’s about finding something equally as clever, like using shellcode tricks or inline assembly.
It feels like I’m always learning something new from someone’s unique solution. That’s really what I love about Codewars. But you’re totally right, I should visit Code Golf SE more often.
“Aliquid semper addiscendum est.”
Thanks, first time I've encountered someone quoting Latin proverbs.
If you like code golfing, why not try: https://codegolf.stackexchange.com/ ?
I think you miscounted, moving the body into the for statement doesn't save any characters.
As for K&R style, I don't like it, and it is removed from C since C23.
As for the header,
size_t
is compiler dependent, so there's no portable way to drop the header. I usually don't care too much about the includes.thank you for the upvote
I'm pretty sure we can drop the header if we use int instead of size_t especially if negative lengths are disallowed anyway. Hold on let me see if i can come up with a unique idea..
that's super clever
Really nice! Well done!
As for your remark on branchless; you need to check your code in godbolt to see what it does; have a look at https://godbolt.org/z/TK1xMj66d
Furthermore, almost all current CPUs have branch prediction, so if you measure performance, it might be different from what you would expect.
I'm pretty sure that my code is shorter even with the include (54 characters), and if we ignore whitespace (71). However, you're right that without the K&R style (no return type) implicit conversion, it would make my code 77 characters compared to yours which was 75. So in a fair competition according to your standards and without all the silly tricks you are right your code would be the shortest. Ç'est la vie (: it's still fun playing around with the technicalities and seeing what is possible! :D
For golfing, I ignore whitespace, and with the new C versions, K&R C isn't supported, so I prefer still rather formatted code.
A recursive solution is fine, but a simple for loop is good as well.
If I compare both, we have:
and
but the include for
abs
isn't used, if it's added we get:which is actually a little bit longer, hence making my code shorter looking from that perspective.
Both are fine solutions however in my opinion.
thanks! :D
hahaha, that's very creative!
Yes, I’m learning so much more about the technical intricacies of C through golfing than I would normally, especially by studying everyone else's solutions. You and a handful of others consistently come up with the most creative, mind-blowing solutions that I never would have thought of, and I’ve learned so much from all of you.
Thanks! :D you too
I totally get it. Yeah, I've noticed you ignore spaces too, and that’s tripped me up a couple of times, lol. I’m just trying to find the most golfed solution by any means necessary. I was originally following the C23 standard as well, until I saw other solutions that didn’t follow it, and when I tried it, it worked. So I guess if Codewars allows it, then it’s fair game? But I totally agree. I wish they would enforce the most recent standard or let us sort solutions by the standard we prefer to use.
Loading more items...