12
\$\begingroup\$

There has already been a 9 Hole Challenge (and another one here), but that was soooo last year. And besides, I have only been around for 2 months (although it seems like forever). And it is considerably different.

Leader Board: (note that weighting for holes are not established yet)

+---------------+------------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|Competitor     | Language   | Hole 1 | Hole 2 | Hole 3 | Hole 4 | Hole 5 | Hole 6 | Hole 7 | Hole 8 | Hole 9 | Total  |
+----------------------------------------------------------------------------------------------------------------------+
|Dennis         |CJam        |        | 31     |        |        |        |        |        |        |        | 31     |
+----------------------------------------------------------------------------------------------------------------------+
|Optimizer      |CJam        |        | 35     |        |        |        |        |        |        |        | 35     |
+----------------------------------------------------------------------------------------------------------------------+
|Martin Büttner |Mathematica |        | 222    |        |        |        |        |        |        |        | 222    |
+----------------------------------------------------------------------------------------------------------------------+
|Cameron        |Python      | 878    |        |        |        |        |        |        |        |        | 878    |
+----------------------------------------------------------------------------------------------------------------------+
|bubalou        |Processing 2| 717    |        |        |        |        |        |        |        |        | 717    |
+----------------------------------------------------------------------------------------------------------------------+
|Doorknob       |Python 2    |        |        |0.079711|        |        |        |        |        |        |0.079711|
+----------------------------------------------------------------------------------------------------------------------+
|Vulcan         |Java        |        |        |0.6949  |        |        |        |        |        |        |0.6949  |
+----------------------------------------------------------------------------------------------------------------------+
|Eli            |C++         |        |        |1.42042 |        |        |        |        |        |        |1.42042 |
+---------------+------------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

Other Holes:

It's been slow around here lately, so I am here to kick off the next 9 hole golf course, involving a smattering of all that I have seen here in my (albeit limited) experience. This will entail:

  • Ascii Art
  • Graphical Output
  • Conway's Game of Life
  • King of the Hill
  • Kolmogorov complexity
  • Quines
  • Image processing
  • Math
  • Classic code golf.

I am really looking forward to seeing what you can do!

Competition Rules

  • You will choose 1 language for all of the holes (that you participate in...see point 4 for more info).
  • For all holes - standard loopholes are (still) not funny.
  • The next challenge will appear when I see that there are enough submissions given a reasonable amount of time. King of the hill, for example, will take longer.
  • You do not have to participate in all of the holes. If you find a hole particularly challenging, don't have the time to do it, etc, you will receive 2 times as many points as the lowest score. Please do not take advantage of this rule by leaving 1 golfscript answer with 12 characters and taking 24 as a score.

Scoring

  • Your score is based on the culmination of the scores from all of the holes
  • Lowest score wins (as per real golf)
  • The leaderboard will be placed at the top of this page

I will try my very best to make sure that no questions are duplicates, all questions have objective criteria, are well written, and that they all have (relatively) equal weight in the context of the whole contest.

However, Please be patient when I fail.

And, without further ado, the first challenge!

The Plasma Globe

A plasma globe is everyone's favorite toy:

enter image description here

Your job it to draw one.

You must draw a base:

enter image description here

a globe:

enter image description here

A tesla thingy (?)

enter image description here

And, of course, cool plasma shoots:

enter image description here

However, when you put your hand near a plasma globe (or a conductive object as Wikipedia tells me), it attracts the plasma.

Your globe should reflect that.

To put it quantitatively, your globe has a maximum of 16 shoots (see above picture). An "object" on the surface of the globe (given by an angle in radians) will contain "conductive power", that is, the amount of beams it attracts. So an object with a power of 5 will attract 5 beams (a single line with thickness 5) leaving 11 to spread evenly among the rest of the globe:

enter image description here

Note that
1. the black circle in the middle remains above the plasma
2. that in this example, the angle would be pi/2.

You may have more than one conductive object, and in that event, it is not required that the shoots are equally spaced apart. However, they be relatively spaced out. For example, this is ok for 2 objects, 1 at angle pi/4 power 5 and another at angle 5pi/3 power 3:

enter image description here

You should be able to see each of the end points of the shoots (of plasma).

However, given an object (or sum of objects) with power greater than 16, the globe will "break":

enter image description here

Notes

  • The globe's diameter is 1.5 times bigger than the length of the base, which is a square
  • When the globe breaks, the globe is on the right side. It is tangent to the right side of the base as well as the ground. There should be no plasma when the plasma globe is broken (why? safety features of course! No word on how it broke in the first place.)
  • The color of everything except the shoots must be black, and 1 pixel thick. The color of the plasma has hue 245 - 280, and saturation/value 100. Use this under "HSV" if you have no idea what I am talking about.

Input

Input can be through STDIN/command line args/whatever or through function arguments.

There should be 2 inputs - length of the base of the plasma globe (include an axis if using vector graphics), and an array of objects like this:

[[angle,power],[angle,power],[angle,power]]

So for no objects (see first picture with 16 lines) the input would be

100,[]

For the next (one object, power 5) it would be:

100,[[1.570796,5]]

For the last example:

100,[[0.785398,5],[5.23598,3]]

This is code-golf, so shortest code in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ @MartinBüttner If the image does not get smaller when the base-length get smaller, include an axis \$\endgroup\$ – Stretch Maniac Oct 12 '14 at 23:29
  • \$\begingroup\$ In your second example. What if the second object was at -3/8π? In that case it would overlap exactly with one of the other beams. Do we have to rotate all the beams in such a case? If so, I think you need to specify how far away the individual beams need to be from the object-induced beams. \$\endgroup\$ – Martin Ender Oct 12 '14 at 23:43
  • 1
    \$\begingroup\$ er.... why the column "hole 2" of the board is already filled even if there are no answers? \$\endgroup\$ – xem Oct 17 '14 at 20:28
  • 2
    \$\begingroup\$ A little help to better visualize this: inear.se/plasmaball \$\endgroup\$ – CSᵠ Oct 18 '14 at 0:09
  • 1
    \$\begingroup\$ @xem um, there are answers to hole 2, so why not post them? This doesn't necessarily have to go in order... \$\endgroup\$ – Stretch Maniac Oct 18 '14 at 0:34
4
+50
\$\begingroup\$

Processing 2 - 717 characters

As processing is a language made for artists, and I am a very novice programmer, I do not expect to do very well on many of these challenges. That being said, I really like how simple it is to draw things in processing, and I have been meaning to play around with it some more, so these challenges should be interesting.

int j,m,b,k,d,l;float w,c,h,x,y,z;float v[],p[],g[];void setup(){j=m=d=0;c=z=0;String i[]= loadStrings("f.txt");i[0]=i[0].replace("[","").replace("]","");String o[]=split(i[0],',');v=new float[o.length];p=new float[o.length-1];for(String s:o){if(!s.equals("")){v[j]=Float.parseFloat(s);}j++;}w=v[0];size((int)w*3,(int)w*3);h=w*.75;l=v.length;noLoop();}void draw(){translate(w/2,height);scale(1,-1);rect(0,0,w,w);if(l>2){while(m<j-1){m+=2;c+=v[m];}}if(c>16){ellipse(w+h,h,2*h,2*h);rect(w/2,w,1,h);}else{ellipse(w/2,w+h,2*h,2*h);rect(w/2,w,1,h);b=16;m=1;stroke(#1500ff);if(l>2){while(m<j){p[m-1]=cos(v[m])*h;p[m]=sin(v[m])*h;strokeWeight(v[m+1]);line(w/2,w+h,p[m-1]+w/2,p[m]+w+h);b-=v[m+1];m+=2;}}strokeWeight(1);c=(PI*2)/b;k=b;g=new float[b+b];while(b>0){g[d]=cos(z+c*b)*h;g[d+1]=sin(z+c*b)*h;m=0;if(l>2){while(m<j-1){if(abs(g[d]-p[m])<.1 && abs(g[d+1]-p[m+1])<.1){b=k+1;z=z+.1;d=-2;break;}m+=2;}}b--;d+=2;}d--;while(d>0){line(w/2,w+h,g[d]+w/2,g[d-1]+w+h);d-=2;}}stroke(#000000);fill(#000000);ellipse(w/2,w+h,w/9,w/9);}

I'm sure this can be golfed down considerably and I may try to do that when I have more time, but for now I am happy with it.

reads in a file (f.txt) located in the data folder of the sketch to get its input. I used Camerons idea of shifting the free beams until they don't overlap.

int j,m,b,k,d,l;
float w,c,h,x,y,z;
float v[],p[],g[];
void setup(){
j=m=d=0;
c=z=0;
String i[]= loadStrings("f.txt");
i[0]=i[0].replace("[","").replace("]","");
String o[]=split(i[0],',');
v=new float[o.length];
p=new float[o.length-1];
for(String s:o){if(!s.equals("")){v[j]=Float.parseFloat(s);}j++;}
w=v[0];
size((int)w*3,(int)w*3);
h=w*.75;
l=v.length;
noLoop();
}

void draw()
{
  translate(w/2,height);
  scale(1,-1);
  rect(0,0,w,w);
  if(l>2) 
  {
    while(m<j-1)
    {
      m+=2;
      c+=v[m];
    }
  }
  if(c>16)
  {
    ellipse(w+h,h,2*h,2*h);
    rect(w/2,w,1,h);
  }
  else
  {
    ellipse(w/2,w+h,2*h,2*h);
    rect(w/2,w,1,h);
    b=16;m=1;
    stroke(#1500ff);
    if(l>2)
    { 
      while(m<j)
      {
        p[m-1] = cos(v[m]) * h;
        p[m] = sin(v[m]) * h;
        strokeWeight(v[m+1]);
        line(w/2,w+h,p[m-1]+w/2,p[m]+w+h);
        b-=v[m+1];
        m+=2;
      }
    }
    strokeWeight(1);
    c=(PI*2)/b;
    k=b;
    g=new float[b+b];
    while(b>0)
    {
      g[d] = cos(z+c*b) * h;
      g[d+1] = sin(z+c*b) * h;
      m=0;
      if(l>2)
      {
        while(m<j-1)
        {
          if(abs(g[d]-p[m])<.1 && abs(g[d+1]-p[m+1])<.1)
          {
            b=k+1;
            z=z+.1;
            d=-2;
            break;
          }
          m+=2;
        }
      }
      b--;
      d+=2;
    }
    d--;
    while(d>0)
    {
      line(w/2,w+h,g[d]+w/2,g[d-1]+w+h);
      d-=2;
    }
  }
    stroke(#000000);
    fill(#000000);
    ellipse(w/2,w+h,w/9,w/9);
}

Examples:

100,[[0.785398,3],[5.23598,5]]

plasma orb 1

100,[]

plasma orb 2

100,[[1.72398,12],[5.23598,5]]

plasma orb 3

get processing here

\$\endgroup\$
3
\$\begingroup\$

Python, 878 chars

By no means is this golfed well, but I wanted to see an answer for this hole.

import matplotlib.pyplot as P
from math import *
L=len
M=min
Y=P.plot
K=P.Circle
Z=P.gcf().gca().add_artist
f=sin
g=cos
k={'color':(0,0,0)}
j={'color':(.16,0,1)}
def Q(S,C):
    P.axis([-S,S*2.5,0,S*3.5],**k)
    Y([0,S,S,0,0],[0,0,S,S,0],**k)
    Y([S/2,S/2],[S,7*S/4],**k)
    Z(K([S/2,7*S/4],S/20,**k))

    k['fill']=False

    A,B=zip(*C)

    N=16-sum(B)
    if N<0:
        Z(K([7*S/4,3*S/4],3*S/4,**k))

    else:
        Z(K([S/2,7*S/4],3*S/4,**k))
        if L(C)==0:
            D(16,0,S)
        elif L(C)==1:
            D(N,A[0],S)
            Y([S/2,S/2+3*S*g(A[0])/4],[7*S/4,7*S/4+3*S*f(A[0])/4],linewidth=B[0],**j)
        else:
            for c in C:
                Y([S/2,S/2+3*S*g(c[0])/4],[7*S/4,7*S/4+3*S*f(c[0])/4],linewidth=c[1],**j)
            D(N,J(N,A),S)
    P.show()


def J(N,A):
    T=d=0
    t=2*pi/N
    while d<0.1:
        T+=0.1
        d=M(M(a-T-floor((a-T)/t)*t for a in A),\
            M(T+ceil((a-T)/t)*t-a for a in A))
    return T


def D(N,I,S):
    a=I
    for i in range(N):
        Y([S/2,S/2+3*S*g(a)/4],[7*S/4,7*S/4+3*S*f(a)/4],**j)
        a+=2*pi/N

And some sample outputs

Q(100,[[pi/4,6],[-4.2*pi/8,1]])

enter image description here

Q(100,[[0.785398,10],[5.23598,7]])

enter image description here

Q(100,[[pi/4,3],[pi/2,3],[3*pi/2,2],[5*pi/4,2]])

enter image description here

\$\endgroup\$
  • \$\begingroup\$ How does this ensure that object-induced and free beams never overlap? \$\endgroup\$ – Martin Ender Oct 19 '14 at 20:36
  • \$\begingroup\$ I rotate the equally spaced beams by a small amount until I find an orientation that ensures the beams are at least 0.1 radians spaced apart \$\endgroup\$ – Cameron Oct 19 '14 at 20:56
  • \$\begingroup\$ Ah, right, I expected something like that. Thanks for clarifying! \$\endgroup\$ – Martin Ender Oct 19 '14 at 20:58
  • \$\begingroup\$ Np, I've been trying to solve how to maximize the minimal distance between any object-induced beam and any free beam, but its seems to be a difficult question \$\endgroup\$ – Cameron Oct 19 '14 at 20:59
  • 1
    \$\begingroup\$ A,B=zip(*C) should save a few bytes \$\endgroup\$ – gnibbler Oct 21 '14 at 2:08
1
\$\begingroup\$

Python 2.7, 378 375

from turtle import *;import sys
(s,P),A,B=eval(sys.argv[1]),90,180
n,S=sum([b for(a,b) in P]),.75*s;l=16-n
for i in 'abcd':fd(s);lt(A)
pu()
if l<0:goto(s+S,0)
else:goto(s/2,s)
pd();circle(S);pu();goto(s/2,s);lt(A);pd();fd(S)
def C():fd(S);fd(-S)
if n<16:
 color('blue')
 for i in range(l):rt(360/l);C()
 for a,p in P:pensize(p);rt(a*57.3);C()
color('black')
shape('circle')

It reads its parameters from commandline argument.

Sample images :

(parameters=100,[[0.785398,5],[5.23598,3]])

tesla

(parameters=100,[])

tesla2

(parameters=100,[[1.72398,12],[5.23598,5]])

tesla3

\$\endgroup\$
  • \$\begingroup\$ I wasn't able to test this, but it's golfed a bit here: repl.it/E52i \$\endgroup\$ – 0WJYxW9FMN Nov 22 '16 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.