Feel free to send your feedback or ask some help here!
I think there is a little bug in length calculation since my code changed size after multiple sends with no change.
@SaiksyApo I think you should add more tests for validation, because right now it is possible to reduce the size of your code by not going north for example
Do you guys think itâs fun to try to write a code in as few characters as possible? This kind of puzzle didnât really appeal to meâŚ
By the way, I appreciate the fact that developers are trying new things, I just didnât like the direction they took, because coding using the least possible amount of characters encourages bad programming practices, like variable reuse, single letter definitions and cryptic code. I donât know if this is a good idea, since there are many students here and a lot of people use these puzzles to learn how to program. Some habits die hardâŚ
Maybe an optimization challenge related to the time an algorithm takes to run would be more fun. Also, it could encourage good programming practices, like writing eficient codes, avoiding to performe the same task multiple times, using heuristics to find a solution faster etc. Furthermore, it could encourage students to learn faster languages, like C. Well, just my opinion about this new optimization puzzles. Overall, I like CodinGame very much (:
Code golf (because this is how this kind of puzzle is called) also has benefits when learning. You have to find the limits of your language like what happens if you use an uninitialized variable, an undefined constant, the tiny differences between two similar functions or such things. Sure the final code is full of bad practices but itâs not as if youâll code the same way everyday (except for physicists, as lots of them still think than naming variables i, ii, iii, and so on is perfectly fine).
Anyway, I find weird youâre saying that time optimization would lead to better practices. I mean, fast algorithms are also often cryptic because theyâre based on how a CPU handles operations. Just take this famous example from Quake III Arena (with original comments):
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}
This function is an optimized approximation of inversed square root, or to say it differently x^-0.5
. Will you learn good practices from it? Certainly not.
The only bad practice I can see here is the magical number (which could be given a more useful name) and the scarce documentation. Both of these can be fixed without impairing the performances.
(Side note: this piece of code is considered a masterpiece by some people)
What you say about the limits of the language is true to some point, but then whitespace and comments (excluding preproc macros) could be excluded from the score.
I think CodinGame should take care of the spaces and comments removal. Else it just makes it unreadable and forces you to keep a copy of your code sideways to work on it.
NewboO, I said a performance challenge related to time would be more fun to me and could lead to better programming practice in general in most cases. But trying to code using as few characters as possible, in my opinion, will necessarily lead to bad programming practices. For example, nothing good can come from removing white spaces from your code. In most languages it will remove identation, cripple readability and decrease clarity. And this is why I think this kind of puzzle can be harmful for beginners, since they could develop bad habits that are hard to get rid from. I think a performance challenge related to time would be more fun (to me) and more instructive in general to students.
Code size optimization doesnât lead to improve coding practices but I think itâs a good way to hack programming languages. In my own case I learnt few things in javascript like:
- better understanding of typecasting
- [a, b, c, d] = readline().split(â ') is possible, yeah!
Same thing for me, Iâve learned a few things in C
Hi!
Is there a limiit to the submissions?
When I submit after writting my new code in the âCode Editorâ, it doesnât use the new code when computing but a previous code⌠Which results in my code size and ranking being associated with my previous code and not my newly edited codeâŚ
When I click on âView Reportâ, I see my old code in the âAnswerâ box, but when I go and âTry Againâ itâs my new code I find in the âCode Editorâ.
There is absolutely no submission limit.
If you still see your old code on the report page after publishing a new solution, it may be because of two reasons:
- Your new code is longer than the previous one, so the best solution is kept
- Your new code did not pass all the test cases and so is not accepted
From what you say, I think this is the second reason.
Actually, the report page is intended to display our best submission and not the last one.
Is it possible to have the exact rules used for the calculation of the code length?
Are the spaces taken into account?
Does the number of line count?
Does the length of a variable name count?
Does the number of variables count?
But concerning the question âis optimizing code length interesting?â, I think that yes. I usually donât do that when I write a program, but in can be interesting challenge. If any of you know the games âSpacechemâ and âInfinifactoryâ, you know that trying to acheive a solution using the least number of command can be very satisfying.
I have the same problem: my code is shorter now and itâs still the first one that is shown and used.
Me too. There should be a way to know exactly how well does the new code with the final tests. Otherwise we have no way to correct itâŚ
Code length only counts the number of characters. All characters count, including those in variable names, line feeds, spaces and tabulations.
Formerly, spaces and such did not count, but someone found an abuse by cyphering all his code into only spaces and such, scoring 42 for the Clones Code Length. So, the rules where changed.
Actually, tabulations count as 4 spaces, so youâd better replace them by 1 space if youâre using python. Or put multiple commands in 1 line using â;â
Thanks for the answer. If the spaces count, then maybe some languages are better than other. On the orther hand, in Python, we need to indent with at least one space, but we donât need â;â at the end of each line or horribles brackets every 2 linesâŚ
I think it would be great if you should show the character count on the page somewhere so we wouldnât have to submit or use an external tool when weâre trying to optimize. Fun problem though!
This small hack can do the job (open the puzzle, open the js console and paste it):
var iframe=$("#ideFrame")[0].contentWindow;var ide=iframe.ace.edit("ace_edit"); ide.on("change", function(e){iframe.$(".squareTitle").find("h2").text(ide.getValue().length + " chars")});