# Temperature Code Golf puzzle discussion

#122

same for me. 12th doesn’t work.

#123

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.

#124

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.

#125

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.

#126

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.

#127

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

#128

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.

#129

Great.
thank you

#130

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

#131

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

#132

Same to me.

#133

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?

#134

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.

#135

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)…

#136

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…

#137

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

#138

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)

#139

Math.pow

if `double` is fine you can use `1e9`

#140

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.

#141

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?