The shoutbox is currently out of service. Join us on Discord instead.
You can help CodeWalrus stay online by donating here.

Code Golf Contest: The Pythagorean Problem

Started by Juju, August 15, 2017, 07:52:01 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kotu

August 16, 2017, 02:36:11 pm #15 Last Edit: August 16, 2017, 02:38:27 pm by kotu
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.
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Juju

August 17, 2017, 05:22:51 am #16 Last Edit: August 17, 2017, 06:51:51 am by Juju
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
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron



if you wanna throw money at me and/or CodeWalrus monthly it's here

Snektron

you havent updated the standings yet, juju
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


c4ooo

August 17, 2017, 02:15:48 pm #18 Last Edit: August 17, 2017, 02:30:28 pm by c4ooo
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.

Snektron

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.
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Juju

Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron



if you wanna throw money at me and/or CodeWalrus monthly it's here

c4ooo

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.

Powered by EzPortal