You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server
We have an anniversary Game Jam! Click here for more info.

Code Golf Contest: The Pythagorean Problem

b/Contests Started by Yuki, August 15, 2017, 07:52:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

u/kotu August 16, 2017, 02:36:11 PM
it is actually unless you have infinite bits of precision

*edit*
in fact if you zoom in or out of the common domain slightly or scroll around slightly, every boolean value in the 96x64 area could be untrue. its just quite unlikely

HMM

there are technically infinte number of places where this does in fact happen.
Last Edit: August 16, 2017, 02:38:27 PM by kotu
u/Yuki August 17, 2017, 05:22:51 AM
Depending of the language you use, it is possible to check if your integer is an integer. As in, you can cast your float into an int, if it didn't lost information it's an integer.

Oh, also optimized my entries to 60 and 52 bytes respectively.

Code (Ruby) Select

64.times{|v|96.times{|u|$><<((u.i+v).abs%1==0??o:" ")}
puts}
Code (Ruby) Select

p (0..6143).select{|n|((n%96).i+n/96).abs%1==0}.size
Last Edit: August 17, 2017, 06:51:51 AM by Juju
u/Snektron August 17, 2017, 11:35:21 AM
you havent updated the standings yet, juju
u/c4ooo August 17, 2017, 02:15:48 PM
Quote from: Juju on August 17, 2017, 05:22:51 AM
Depending of the language you use, it is possible to check if your integer is an integer. As in, you can cast your float into an int, if it didn't lost information it's an integer.
Yep. In a float, the first byte is almost always a signed exponent, so as long as it is >=0 its an integer (unless I got something mixed up). This should be useful if someone does the challenge in assembly.

Edit: got 39 bytes in tibasic but its a very lazy solution lol. Will post code when I get time.
Last Edit: August 17, 2017, 02:30:28 PM by c4ooo
u/Snektron August 17, 2017, 02:51:35 PM
Quote from: c4ooo on August 17, 2017, 02:15:48 PM
Quote from: Juju on August 17, 2017, 05:22:51 AM
Depending of the language you use, it is possible to check if your integer is an integer. As in, you can cast your float into an int, if it didn't lost information it's an integer.
Yep. In a float, the first byte is almost always a signed exponent, so as long as it is >=0 its an integer (unless I got something mixed up). This should be useful if someone does the challenge in assembly.

thats not true, because the mantissa (other part of the float) is a fraction part: (1/16 + 1/8)*2^3 is 1.5, but it still has a positive exponent.
Instead you could check if the mantissa is clone enough to zero: if its smaller than 0.00001 for example is probably an integer. I think most is_integer() functions will work this way.

My solution actually uses this:
#define mainImage(O, U)O+=sign(fract(length(U-.5)))
O is the output color, U is the input coodinate plus 0.5. length() is just sqrt(U.x*U.x + U.y*U.y).
fract takes the fraction part of the float (the mantissa). Sign(x) returns -1 if x < 0, 0 if x == 0 and 1 if x >0. I think the sign function internally also compares x to some small value.
u/Yuki August 17, 2017, 05:03:40 PM
Quote from: Snektron on August 17, 2017, 11:35:21 AM
you havent updated the standings yet, juju
Ah yeah, forgot yours, thanks.
u/c4ooo August 17, 2017, 05:22:35 PM
Quote from: Snektron on August 17, 2017, 02:51:35 PM
Quote from: c4ooo on August 17, 2017, 02:15:48 PM
Quote from: Juju on August 17, 2017, 05:22:51 AM
Depending of the language you use, it is possible to check if your integer is an integer. As in, you can cast your float into an int, if it didn't lost information it's an integer.
Yep. In a float, the first byte is almost always a signed exponent, so as long as it is >=0 its an integer (unless I got something mixed up). This should be useful if someone does the challenge in assembly.

thats not true, because the mantissa (other part of the float) is a fraction part: (1/16 + 1/8)*2^3 is 1.5, but it still has a positive exponent.
Instead you could check if the mantissa is clone enough to zero: if its smaller than 0.00001 for example is probably an integer.
Ohh well it works for tios floats. In my monochrome CE wrapper demo I had to convert floats to integers and I checked if the first byte was zero or one (meaning the float had one or two digits, respectively), and everything else was Out of bounds. But tios floats use BCD so I guess its a but different.
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal