Temperature Code Golf puzzle discussion

same for me. 12th doesn’t work.

I wonder if there is any trick to shorten the part of the code where you calculate the temperature closest to zero.

I am using C for this challenge. Currently, for me, that part of code is 26 characters long (excluding the semicolon) including the ternary operator.

Maybe there is a way to find the temperature closest to zero by using bitwise operators? I have found a way to avoid utilising math functions (from the math library) to calculate it, but apart from that, I can’t think of anything else.

This is from my own experience. My best attempt with C, that does not do the “system” cheat, turned out to be 71 characters long in total. In this code, the “closest to zero and preferredly positive” check is 13 characters long. This consists basic C operations and no bitwise. Tip: one does not have to compare absolute values when in need of comparing by absolute values.

Thanks for the reply.

I have not used the abs() function in my code, but like you said, I did compare absolute values without using abs() before finding a way to use basic operations to do the check to make my code shorter. (Now that part of the code is 21 characters long and has 2 ternary operators.

Apart from this, is there a shorter way to get inputs other than using the scanf’s return value? I currently use 1 printf for outputting the value closest to zero and 2 scanf’s.

You are welcome!

I do not think that there is alternative and shorter ways than scanf and printf. ‘Scanf’ because input is a string, but the comparisons have to be numerical. ‘Printf’ because one has to output the numerical answer as a string. I have not found the way to do this with fewer number of characters. But concider this - it could be that the number of characters in code can be cut down by using some of the functions less times.

All right. Maybe I only need 1 scanf, but until I find a way to shorten my code, I am stuck at 90 characters total.

(The checking part of my code is now 19 characters long.)

Hi!
I was stuck on it for one year too but I finally figured out a special case that is indeed legitimate to test: it’s about the bold part of the rules. Actually it’s harder to understand properly in French.

Great.
Please, add more validators to avoid hardcoded solutions
thank you

I don’t think there’s a lot of hardcoded solutions on temperature. There’s already a lot of validators.

Getting around the validators is part of the fun here. Otherwise anarchy golf is a better platform.

Same to me.

Has the validator system changed after those years of hardcoding solutions? Are the top solutions hardcoded?

My concern is: is this still possible to have a solution at least as short as the top solutions?
Because if the top solutions come from a time where validators were easier, what’s the point then?

I can’t be sure, but i think top solutions are not hardcoded. There’s a lot of validators, it will be very hard to hardcode something.

Hey there, I’m pretty sure there is almost one validator missing.

1
5526

I pass everything by initializing my max at 999 and with this test which must return 5526, mine returns 999 :’)
(By initializing to 999 I win 1 char)…

Hey !
Seems logical your code doesn’t work. If you are only searching for values lower than 999, 5526 will never be selected…
But I don’t know how your code is made, so I could be wrong…

Initialize to 9^9 if you can…
Same length, and high enough :wink:

I think you have misunderstood.

My code passes ALL the test case even the submit ones. I’m conscious that my code is wrong. I’m not searching for a solution or any kind of optimisation here (I like to search by myself). All i’m saying is that the test where there is only 1 value wich is the maximum does not exist. It allows (in my case) to win 1 char on a code that shouldn’t be good.

PS:
@hoeskioeh, in java doing 9^9 is pretty long

Math.pow(9,9)

Math.pow

if double is fine you can use 1e9

Yes but it’s not fine, don’t have space to convert everything when int is enough.

Moreover I said

I’m not searching for a solution or any kind of optimisation here (I like to search by myself).

All i’m saying is that the test where there is only 1 value wich is the maximum does not exist.

Given that Bash ‘sort’ command behaviour has changed recently, so that at least my old solution do not pass validators any more, would it be a good idea to recalculate the scores?

1 Like