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.
yeah sorry about that, you reminded me about this kata and I started revamping a lot of awkward stuff I wrote years ago, and I tried to unify the description instead of relying on per-language blocks. you will have to fork the current translation, it is the only way to resolve a merge conflict; thanks for choosing the enum too
lol
approved
the other languages use an
enum
(except JavaScript where I tried to emulate one with an unmodifiable object whose keys are equal to their values). I tried to cobble together something equivalent for Lua, which does not have native enumerated types:Preloaded:
user solution:
tests:
What do you think ? is it too awkward / unidiomatic ?
i thought that scientific notation is easier to understand and more informative for beginners (for example it gives a better idea of how small subnormal numbers are), and I for one cannot easily read the hexadecimal notation. but if you think it's better it's not that big of a deal
already handled here
done
thanks for making the changes, is there a particular reason why you use the hexadecimal notation for the floating point literals ?
Codewars works by receiving code as a piece of text from your web browser; saving it to a file ;executing it on their server with the appropriate compiler/interpreter; and returning the output to your browser. It follows that you can get information on the system that runs your code by calling the appropriate commands.
It's easy to establish that the server runs on Linux because of the low-level nature of C (for example the
__linux__
macro is defined); web servers also typically run on Ubuntu, and the x86_64 architecture has become almost ubiquitous for desktop computers. But you can make sure of that by running something like this on Codewars (i wrote it in C because it is the only language you trained, but you could do the equivalent in almost all the other languages on Codewars):Use this function on Codewars (just call it in the function you're supposed to write for the kata) and you will see:
So we know the endianness, OS, and architecture.
C is a compiled language and C compilers generate lower-level assembly code for a specific architecture. We've established that Codewars runs on Linux x86_64, so we only need to search which calling convention is used: the System V ABI. A calling convention is a way to precisely describe how functions are to be called in assembly and how they return. It specifies which arguments are to be put in which registers by the caller, what the callee has to restore before returning control, etc. Without a calling convention, the different parts of a program could not talk to each other and it would be impossible to write reliable code.
IEEE 754 is a techincal standard/specification for floating-point numbers. It's so widely adopted that it's become almost synonymous with them. Almost all programming languages use it for their
float
and/ordouble
datatypes.we've established that Codewars runs on a Little-Endian machine, so the bytes that represent the float value are going to be hardcoded in little endian order in the executable files (on disk) as well, as they will be directly loaded into memory (RAM) in the same order.
You should experiment with compiling and building C programs that are split between several files to get a better understanding of the process. The peculiarity of the Codewars setup is that it uses no header (
.h
) files, unlike most large C programs. The command basically goes likecc user_code.c tests.c
. Due to the absence of header files there is no mechanism to ensure that types are compatible between the two files. Alltests.c
knows (from a declaration) is that there is a functionint multiply(int, int)
that it can call, but nothing prevents you from writing e.g.double multiply(int a, float b, short c)
instead inuser_code.c
(which is the file that you edit when you train on a kata), and it will still compile and run (but will behave strangely); you can see it for yourself.I have known (not in great detail) about these things for some time now and it would be hard for me to give advice to a beginner on the best way to learn in 2025, especially within the current AI boom. Many Wikipedia articles give in depth descriptions of subjects such as calling conventions; cppreference.com is a good reference on C/C++ specifically, godbolt.org is good to see what your code compiles to in different languages/environments/compilers, I often use tsnippet.trust-in-soft.com to find bugs in my C programs. But none of these tools are aimed at beginners.
Hello, thanks for the translation. I am not experienced in Lua and have a few remarks:
why do you need to compute
nan
in preloaded ? can't you do have it in the tests, like?
I feel like the wording is ambiguous and can mislead beginners. How about something like "until Lua 5.3, all
number
s were IEEE 754 DP. Since 5.3,number
s variables can also hold 2s complement integers". What do you think ?this line in the description is irrelevant since Python3
approved
tests require proper
@it()
/@describe()
blocks and explicit import oftest
andclass_name_changer
approved by someone
in the initial code,
class ReNameAbleClass(object):
is legacy from Python2 and should be changed to the more modernclass ReNameAbleClass:
Loading more items...