Temperature Code Golf puzzle discussion

There are now 12 test cases and all the submissions have been recomputed ;).


The 12th test case always fails for me… are you sure its correct?

1 Like

We would receive a lot of complains if the last test case were incorrect.

1 Like

ok so I’m enjoying those codegolf challenges a lot so far, but I feel that there must be some environment-specific hacks that you have to know in order to reduce more.
I mean, I’m at 87 in js, and 70 in ruby, and I feel quite good about it, but at this point most of my code is input handling and output. the best JS is at 67 char I think, and my “non-operative” code ( like the all-dreaded, 21char-long readline().split(’ ‘) … brrrr) is almost that long in itself…
I guess what I mean is, without giving solutions to the puzzles, are there “hacks”, like, say, aliases to readline and print, or ways to gulp multiple lines in a statement, or maybe alternatives to split(’ ')…

Maybe we should have a forum post with those for each language, so we’re all on the same footing?

Feel free to create a new thread for each language and share your tricks! I think people would be very interested.

1 Like

I was wondering what were the functions for input that cg implemented to see if there was anything shorter too.

Actually, it exists already for a few language, you just need to create your own for Javascript, you can copy those to make your own. Here is the C++ one and that is the Haskell one

thanks! I was just reading the C++ one and mustering my best tricks. Hopefully someone will have what we’re looking for :slightly_smiling:

I don’t know if there’re any built-in aliases but I did 69 characters in JS using print, readline and split(’ '). Sometimes, I create my own aliases to functions (like readline) when I need to use it >2 times.


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)

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: ).