* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Code Golf Contest: The Pythagorean Problem  (Read 678 times)

0 Members and 1 Guest are viewing this topic.

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 3099
  • Post Rating Ratio: +30/-2
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • @juju2143
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Code Golf Contest: The Pythagorean Problem
« on: August 15, 2017, 07:52:01 pm »
Time for a code golf contest? Been a while we did that. Thought that'd be fun while I'm busy with other stuff. If you don't remember what it is, I give you a task and you try to write a program that is the shortest you can do. Standard rules apply, you can find them on Stack Overflow. If in doubt, like how to count the size of your entry, just ask me or anyone familiar with the previous contests we did before.

So yeah, this one revolves around Pythagorean triplets. If you don't know what it is either, it's any set of integers (a,b,c) that solves the formula a2 + b2 = c2. So if you take a point on a plane, say (3,4), it should be at a distance 5 from the origin (0,0). Same for (4,3). The point (3,5), though, is at a distance √34 from the origin, which is not an integer and therefore not Pythagorean.

So your task is, you are given a monochrome graphic screen (96x64 on a TI-83+, but could be anything big enough we can see something) with the origin (0,0) in a corner (usually upper left, but could be lower left) and you must turn on every pixel (a,b) that verifies a2 + b2 = c2 with a, b and c being integers, with the rest must be off. Don't miss one! I know there's a bunch of clever tricks to do that, so be creative.

Bonus task: Write another program that counts how many pixels are on this way for any width and height given as inputs.

Send the source code either in this thread on in PM to me before September 1st, 23:59:59 EST. and make it clear whether the codes you send are for the main task or the bonus one. There's nothing at stake other than the honor, feel free to help each other and have fun!

Standings

Main task
UserLanguageBytes
@SnektronShaderToy50
@JujuRuby60

Bonus task
UserLanguageBytes
@JujuRuby52

* Entries must be valid and verified before showing up in this table.
« Last Edit: August 17, 2017, 05:02:31 pm by Juju »


  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
On semi-hiatus until who knows when. CODEWALRUS 2.0 COMING SOON
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

Offline c4ooo

  • Super User
  • CW Contest II Winner
  • *
  • Join Date: Aug 2015
  • Location: 127.0.0.1
  • Posts: 1012
  • Post Rating Ratio: +12/-4
  • Advanced forumer
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #1 on: August 15, 2017, 08:27:04 pm »
I don't understand, if (a,b) is the pixel coords what is c?
Am I supposed to check if sqrt(a*a+b*b) is an integer?
« Last Edit: August 15, 2017, 08:31:44 pm by c4ooo »

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 3099
  • Post Rating Ratio: +30/-2
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • @juju2143
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Re: Code Golf Contest: The Pythagorean Problem
« Reply #2 on: August 15, 2017, 11:01:53 pm »
Exactly. c a bit irrelevant as you can derive it from a and b, but yeah, pretty much.
« Last Edit: August 16, 2017, 12:25:32 am by Juju »
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
On semi-hiatus until who knows when. CODEWALRUS 2.0 COMING SOON
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

Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #3 on: August 15, 2017, 11:06:12 pm »
Can I use C++
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline jamu

  • Full User
  • Safe-haven access
  • Join Date: Jan 2015
  • Location: Next to walrii
  • Posts: 36
  • Post Rating Ratio: +0/-0
    • @jamesguessis
    • @jamesguessis
    • /u/jamesguessis
    • jamesguessis
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #4 on: August 15, 2017, 11:08:33 pm »
so this works in python?
Code: [Select]
import math
points = [(x,y) for x in range(1, 96) for y in range(1, 64) if math.sqrt(x * x + y * y).is_integer()]



producing this when scatter plotted:
I have a rhythm game problem.

Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #5 on: August 15, 2017, 11:09:49 pm »
Winner should be determined by processing time

*edit*
think i can do it about 4 or 5 characters shorter in c++builder (as the code that is added to a blank project with one control)
« Last Edit: August 15, 2017, 11:12:46 pm by kotu »
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 3099
  • Post Rating Ratio: +30/-2
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • @juju2143
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Re: Code Golf Contest: The Pythagorean Problem
« Reply #6 on: August 16, 2017, 01:29:25 am »
Ideally, your program should be a complete, valid program you run (in cmd, bash or double-clicking it) that output a 96x64 image (or in the size you give as input) either on screen or in a file. So the scatter plot part should also be part of the program. Additionally, you'll want to save as much bytes as possible. You can use any programming language, but ideally it should fit in one file I compile/interpret and run. And of course, it shouldn't take 3 hours to run.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
On semi-hiatus until who knows when. CODEWALRUS 2.0 COMING SOON
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

Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #7 on: August 16, 2017, 02:21:50 am »
@Juju do you have Turbo C++ 2006? I might be able to make something pretty... meh
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 3099
  • Post Rating Ratio: +30/-2
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • @juju2143
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Re: Code Golf Contest: The Pythagorean Problem
« Reply #8 on: August 16, 2017, 03:32:48 am »
Ideally, if you make it work with gcc, that'd be perfect. Also, the code you generated with the builder (that isn't in a third-party library) might count against the byte total.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
On semi-hiatus until who knows when. CODEWALRUS 2.0 COMING SOON
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

Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #9 on: August 16, 2017, 03:42:15 am »
I did it in * here is the code
Code: [Select]
f(096){f(064)

*C++Builder
(forgot about all the extra stuff I had to put in)
« Last Edit: August 16, 2017, 03:52:17 am by kotu »
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline Juju

  • aka Yuki Kagayaki aka J̵̭͕͇ù̞̭̝̯̦j̴̭̙̗͖͡ù͏͓̲̕
  • CodeWalrus Staff
  • Super User
  • Server Maintenance
  • Moderator
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Inside a walrus
  • Posts: 3099
  • Post Rating Ratio: +30/-2
  • Couch potato
    • jul.savard
    • juju2143
    • @juju2143
    • juju2143
    • @julosoft
    • juju-kun
    • /u/juju2143
    • juju2143
    • @juju2143
    • Juju's shed
  • Gender: Female
  • WalriiPoints: 99999
Re: Code Golf Contest: The Pythagorean Problem
« Reply #10 on: August 16, 2017, 05:15:25 am »
Code: (Ruby) [Select]
64.times{|v|96.times{|u|print((u*u+v*v)**0.5%1==0?"o":" ")}
puts}

This is a 65-byte solution in Ruby. You're supposed to paste that in a file and then just run it, that's it.

It prints a beautiful ASCII art thing:

Code: [Select]
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
o                                                                                               
o                                                                                               
o   o                                                                                           
o  o                                                                                           
o           o                                                                                   
o       o                                                                                       
o                       o                                                                       
o     o        o                                                                               
o           o                           o                                                       
o                       o                                                                       
o                                                           o                                   
o    o   o      o                  o                                                           
o                                                                                   o           
o                                               o                                               
o       o           o               o                                                           
o           o                 o                                o                               
o                                                                                               
o                       o                                                       o               
o                                                                                               
o              o     o                          o                                               
o                   o       o                                           o                       
o                                                                                               
o                                                                                               
o      o  o       o             o            o                        o                         
o                                                           o                                   
o                                                                                               
o                                   o                                                           
o                    o                       o                                                 
o                                                                                               
o               o                       o                               o                       
o                                                                                               
o                       o                                   o                                   
o                                           o           o                                       
o                                                                                               
o           o                                                                       o           
o              o           o                    o                            o                 
o                                                                                               
o                                                                                               
o                                                   o                           o               
o        o                    o           o                                o                   
o                                                                                               
o                                       o               o                                       
o                                                                                               
o                                o                                                             
o                       o   o                               o                                   
o                                                                                               
o                                                                                               
o             o     o               o                  o        o                         o     
o                                                                                               
o                                                                                               
o                                                                   o                           
o                                      o                                                       
o                                                                                               
o                                                                       o                       
o                                               o                                               
o                                o        o                                               o     
o                                                                           o                   
o                                                                                               
o                                                                                               
o          o             o      o            o                 o                o          o   
o                                                                                               
o                                                                                               
o               o                                           o                       o           

Bonus:
Code: (Ruby) [Select]
a=0
64.times{|v|96.times{|u|a+=1if(u*u+v*v)**0.5%1==0}}
p a
Code: (Ruby) [Select]
p (0..6143).select{|n|((n%96)**2+(n/96)**2)**0.5%1==0}.size

Both 59 bytes in Ruby, gives out 249.
« Last Edit: August 16, 2017, 07:45:43 am by Juju »
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
On semi-hiatus until who knows when. CODEWALRUS 2.0 COMING SOON
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

Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #11 on: August 16, 2017, 09:27:11 am »
Thanks
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline Snektron

  • Lvl 69 Russian Snake
  • Super User
  • Join Date: Dec 2014
  • Location: Netherlands
  • Posts: 3165
  • Post Rating Ratio: +32/-0
  • SSSssssss.....
    • RobinDeWalvis
    • Kzyrox
    • RobinDeWalvis
    • quantuminfinity
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #12 on: August 16, 2017, 11:41:34 am »
Code: [Select]
#define mainImage(O, U)O+=sign(fract(length(U-.5)))
50 chars / 51 bytes
view live on ShaderToy
its bigger than 64x96 though so you'll just have to resize your browser.
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Offline kotu

  • -< \'V/,,,
  • Super User
  • Join Date: Aug 2016
  • Location: don't panic
  • Posts: 1160
  • Post Rating Ratio: +7/-11
  • woah
    • dj_kotu
    • @UCAy2ZF4hbc08iStnTn6jgxQ
    • rowanmedhurst
    • @romanov-psyco
    • futurerave.uk
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #13 on: August 16, 2017, 11:54:42 am »
We all know it is impossible to tell if sqrt(x²+y²) is an integer or not, right?

Only humans can do that, really


..hmm
probably the best thing to do is store bools in a lookup table, start with 3x4, multiply that out (6x8, 9x12 etc)
bleah!

as a double blow i think the sqrt function is probably a numerical method
« Last Edit: August 16, 2017, 12:01:50 pm by kotu »
  • Calculators owned: TI 84+CE-T
  • Consoles, mobile devices and vintage computers owned: Sega Master System, Sony PlayStation 3
SUBSCRIBE TO THE FUTURERAVE.UK MAILING LIST
http://futurerave.uk

Offline _iPhoenix_

  • Full User
  • Join Date: Mar 2017
  • Location:
  • Posts: 479
  • Post Rating Ratio: +9/-1
  • █████ ▼ ♪ Best music ♫
    • @dj_iPhoenix
    • @UCytgMNPxAMDsxjimvxHf01w
    • @the-legend-of-iphoenix
  • Gender: Male
Re: Code Golf Contest: The Pythagorean Problem
« Reply #14 on: August 16, 2017, 02:17:10 pm »
Uhh it is not impossible.
  • Calculators owned: A sentient TI-84+ CE, TI-85
  • Consoles, mobile devices and vintage computers owned: TI-99/4a home computer
Help me with a project by voting here! Thanks!

"walruses are better than tuxedo chickens, all hail the great :walrii:" ~ me

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games