Temperature Code Golf puzzle discussion

Wow! A hint from the CEO of Codingame, that’s something :smiley:
Thanks for that :wink:

hm… so that means my sort() approach is probably not the best one… btw sometimes I even alias x=>readline().split(' '). useful (even if rarely).

Could not we have a per-language ranking? I’m just curious of my rank in my chosen lang.

Unit tests are not covering enough.

My current code would fail a few very simple cases that are obviously not tested.
Fixing my code for these cases would make me lose a few bytes.
I’m currently assuming that given I had to stretch the rules a bit to go to 103 bytes,
Given also that the smallest C program that declares, reads and writes one integer is 44 bytes, I’m very skeptic about the top scores. I assume they generate output on a minimal input (like I would have for an assembly minimal code contest).
Is the point finding generators, or minimal compact algorithms ?

You can do this with less!

Can you be more specific?

Given the way I handle the 0 samples case, if there was 1 sample of the maximum temperature, I would fail the test.
Fixing it would cost me 1 char (as you can easily see if you have access to the source code).

I think there were a coupe of other cases, but I would have to look at my different codes to remember that.

In my humble opinion : in order to avoid “generators”, one test should be purely random against a model program:random number of values (still close to 9999), purely random, time seeded, on the full range of temperatures.

If you say so.

I don’t want to spoil others so I’ll stay vague: I only see three approaches to read and write integers.

The easy natural one, one involving more work from the program and one shamelessly non-portable (I’m not counting generators).

The easy one, except if there is a couple of posix functions I’ve never heard about cannot be smaller that 44 bytes.

I cannot find a way to make the more involved one shorter than the easiest one (after all, the aforementioned posix functions are not taking that much letters for getting or putting an int).

And the “hack” would defeat the purpose of the game (and I’m not even sure it would be that short).

My solution in C contains 90 characters and is perfectly correct. So yes, you can do better.

Smaller : that’s obvious. I’m speaking of the lowest limit I can imagine just for the read & write part (I cannot of course speak about the ones I don’t imagine).
And I see I wrote something wrong above : it’s 46 bytes for the minimum, normal, read, write and two vars. (Or 41 with an horrible non-portable hack)

Bonjour,
est ce que le puzzle va prendre fin un jour ?
Parce que ce serait bien de pouvoir jeter un œil sur les solutions.
La tienne en particulier parce que si elle fait que 90 caractères et que ton programme résout le problème en général et pas seulement les test , c’est bluffant.
De mon coté je suis a 193 caractères et je sais très bien quels tests me prendraient en défaut mais ça me fait économiser 4 caractères (ça me fait gagner 7 places quand même :wink: ).

En ruby je suis à 52 caractères sans hard codding.

The test cases and validators do not seem to contain an example where 0 is one of the temperatures provided. I have a shorter version of code that could break in such case but it has passed the validation.

There are many many tricks in C :).

  • Use global variables: you don’t even have to specify the type for integers.
  • Use the return value of scanf to read the inputs.
  • Use the first argument of the main function.
  • Use the ternary operator.

Hope this will help you ;). But please post in english, most users do not understand French.

I just wonder how the first argument of the main function could be used? Does it contain some specific information? Or do you refer to reusing the variable without the need of declaring a new variable? But doesn’t that require a declaration like
int main(int argc, char* argv[])
which is much longer than
int main() ?

Yes, this compiles:

main(x) { x = 42; printf("%d", x); }

1 Like

Ah, that’s an interesting trick :+1: . I’ve never seen such declaration of a C function without any type information before. And the #include <stdio.h> statement is also omitted. Are these supported by common C compilers? Are there any documentation of these?

BTW, it seems that this compiler supports a main function with an arbitrary number of arguments. I tried this and it also compiles:

main(a,b,c,d,e) {
    a = "s";
    b = 1;
    c = 2;
    d = "abcde";
    e = 0x2f;

    printf("%s,%d,%d,%s,%d",a,b,c,d,e);
}

I’m surprised that the compiler can handle this. Which compiler do you use?

main(x) {
printf("%d", x);
}
// This shows ‘1’, because the program is called without arguments

White-spaces MUST be counted in the code size.
CG tried to get rid of them in the past, and some smart people did abuse of this rule to make very very tiny code (guessing how they did that is left as an exercise)