Problem:


Koch Curve

Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.

The Koch curve is well known as a kind of fractals.

You can draw a Koch curve in the following algorithm:

Divide a given segment (p1, p2) into three equal segments.

Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.

Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).

You should start (0, 0), (100, 0) as the first segment.

Input

An integer n is given.

Output

Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.

Constraints

 0 ≤ n ≤ 6

Sample Input 1

1

Sample Output 1

0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000

Sample Input 2

2

Sample Output 2

0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000

Notes



Sample input:
1


Sample output:
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000

Submission status: Runtime Error

Solution code:
import math
          
def koch(n, h, i, j, k):
 if n == 0:
  return
 s.x = (h*2+j)/3
 s.y = (i*2+k)/3
 t.x = (h+j*2)/3
 t.y = (i+k*2)/3
 u.x = (t.x-s.x)*math.cos(math.pi/3) - (t.y-s.y)*math.sin(math.pi/3) + s.x
 u.y = (t.x-s.x)*math.sin(math.pi/3) + (t.y-s.y)*math.cos(math.pi/3) + s.y
          
 koch(n-1, h, i, s.x, s.y)
 print s.x, s.y
 koch(n-1, s.x, s.y, u.x, u.y)
 print u.x, u.y
 koch(n-1, u.x, u.y, t.x, t.y)
 print t.x, t.y
 koch(n-1, t.x, t.y, j, k)
   
n = input()
          
px = float(0)
py = float(0)
qx = float(100)
qy = float(0)
          
print px, py
koch(n, px, py, qx, qy)
print qx, qy

Submission status: Runtime Error

Solution code:
import math
          
def koch(n, h, i, j, k):
 if n == 0:
  return
           
 s.x = (h*2+j)/3
 s.y = (i*2+k)/3
 t.x = (h+j*2)/3
 t.y = (i+k*2)/3
 u.x = (t.x-s.x)*math.cos(math.pi/3) - (t.y-s.y)*math.sin(math.pi/3) + s.x
 u.y = (t.x-s.x)*math.sin(math.pi/3) + (t.y-s.y)*math.cos(math.pi/3) + s.y
   
n = input()
          
px = float(0)
py = float(0)
qx = float(100)
qy = float(0)
          
print px, py
koch(n, px, py, qx, qy)
print qx, qy

Submission status: Runtime Error

Solution code:
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return

  th = math.pi*60.0/180.0

  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*cos(th) + (t_y - s_y)*sin(th) + s_x
  u_y = (t_x - s_x)*sin(th) + (t_y - s_y)*cos(th) + s_y

  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)



n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0

print '%.8f %8.f' % (a_x, a_y)
koch(n-1, a_x, a_y, b_x, b_y)
print '%.8f %8.f' % (b_x, b_y)

Submission status: Runtime Error

Solution code:
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return

  th = math.pi*60.0/180.0

  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*math.cos(th) + (t_y - s_y)*math.sin(th) + s_x
  u_y = (t_x - s_x)*math.sin(th) + (t_y - s_y)*math.cos(th) + s_y

  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)



n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0

print '%.8f %8.f' % (a_x, a_y)
koch(n-1, a_x, a_y, b_x, b_y)
print '%.8f %8.f' % (b_x, b_y)

Submission status: Runtime Error

Solution code:
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return

  th = math.pi*60.0/180.0

  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*math.cos(th) + (t_y - s_y)*math.sin(th) + s_x
  u_y = (t_x - s_x)*math.sin(th) + (t_y - s_y)*math.cos(th) + s_y

  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)


import math
n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0

print '%.8f %8.f' % (a_x, a_y)
koch(n-1, a_x, a_y, b_x, b_y)
print '%.8f %8.f' % (b_x, b_y)

Submission status: Runtime Error

Solution code:
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return
 
  th = math.pi*60.0/180.0
 
  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*math.cos(th) + (t_y - s_y)*math.sin(th) + s_x
  u_y = (t_x - s_x)*math.sin(th) + (t_y - s_y)*math.cos(th) + s_y
 
  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)
 
 

n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0
 
print '%.8f %8.f' % (a_x, a_y)
koch(n, a_x, a_y, b_x, b_y)
print '%.8f %8.f' % (b_x, b_y)

Submission status: Runtime Error

Solution code:
import math
class point:
    def __init__(self):
        self.x = 0.0
        self.y = 0.0
 
def koch(n,a,b):
    if n == 0 :
        return
 
    rad = 1.0471975511965976 ???# 60 deg
    s = point()
    t = point()
    u = point()
    tmp = point()
 
    s.x = (2 * a.x + b.x) / 3.0
    s.y = (2 * a.y + b.y) / 3.0
 
    t.x = (2 * b.x + a.x) / 3.0
    t.y = (2 * b.y + a.y) / 3.0
 
    tmp.x, tmp.y = s.x-t.x ,s.y-t.y
    u.x = (tmp.x * math.cos(rad) + tmp.y * math.sin(rad)) + t.x
    u.y = (-tmp.x * math.sin(rad) + tmp.y * math.cos(rad)) + t.y
 
 
    koch(n-1, a, s)
    print(s.x, s.y)
 
    koch(n-1, s, u)
    print(u.x, u.y)
 
    koch(n-1, u, t)
    print(t.x, t.y)
 
    koch(n-1, t, b)
 
    return
 
a = point()
b = point()
a.x, a.y =   0.0, 0.0
b.x, b.y = 100.0, 0.0
n = int(input())

print(a.x, a.y)
koch(n, a, b)
print(b.x, b.y)

Submission status: Runtime Error

Solution code:
import math
sin60 = math.sin(60*math.pi/180)
def koch(n,p1,p2):
    if n==0:
        return
    s = [ ( 2*p1[0] + 1*p2[0] ) / 3 , ( 2*p1[1] + 1*p2[1]) / 3 ]
    t = [ ( 1*p1[0] + 2*p2[0] ) / 3 , ( 1*p1[1] + 2*p2[1]) / 3 ]
    u = [ ( t[0] - s[0] ) *0.5 - ( t[1] - s[1] )*sin60 + s[0],
        ( t[0] - s[0] )*sin60 + ( t[1] - s[1] )*0.5 + s[1] ]
    koch(n-1,p1,s)
    print s[0],s[1]
    koch(n-1,s,u)
    print u[0],u[1]
    koch(n-1,u,t)
    print t[0],t[1]
    koch(n-1,t,p2)
        
n  = raw_input()
p1 = (0,0)
p2 = (100,0)
print p1[0],p1[1]
koch(n,p1,p2)
print p2[0],p1[1]

Submission status: Runtime Error

Solution code:
import math
sin60 = math.sin(60*math.pi/180)
def koch(n,p1,p2):
    if n==0:
        return
    s = [ ( 2*p1[0] + 1*p2[0] ) / 3. , ( 2*p1[1] + 1*p2[1]) / 3. ]
    t = [ ( 1*p1[0] + 2*p2[0] ) / 3. , ( 1*p1[1] + 2*p2[1]) / 3. ]
    u = [ ( t[0] - s[0] ) *0.5 - ( t[1] - s[1] )*sin60 + s[0],
        ( t[0] - s[0] )*sin60 + ( t[1] - s[1] )*0.5 + s[1] ]
    koch(n-1,p1,s)
    print s[0],s[1]
    koch(n-1,s,u)
    print u[0],u[1]
    koch(n-1,u,t)
    print t[0],t[1]
    koch(n-1,t,p2)
        
n  = raw_input()
p1 = (0,0)
p2 = (100,0)
print p1[0],p1[1]
koch(n,p1,p2)
print p2[0],p1[1]

Submission status: Runtime Error

Solution code:
import math

def koch(n,p1,p2):
    if n==0:
        return
    s = [(2*p1[0]+1*p2[0])/3, (2*p1[1]+1*p2[1])/3]
    t = [(1*p1[0]+2*p2[0])/3, (1*p1[1]+2*p2[1])/3]
    u = [(t[0]-s[0])*0.5 - (t[1]-s[1])*sin60+ s[0],
        (t[0]-s[0])*sin60 + (t[1]-s[1])*0.5 + s[1]]
    koch(n-1,p1,s)
    print s[0],s[1]
    koch(n-1,s,u)
    print u[0],u[1]
    koch(n-1,u,t)
    print t[0],t[1]
    koch(n-1,t,p2)
        
n = int(raw_input())
p1 = (0,0)
p2 = (100,0)
print p1[0],p1[1]
koch(n,p1,p2)
print p2[0],p1[1]

Submission status: Runtime Error

Solution code:
n = int(raw_input())
 
p1_x = float(0)
p1_y = float(0)
p2_x = float(100)
p2_y = float(0)
 
def KC(i, n, x1, y1, x2, y2):
    v = [0]*5
    w = [0]*5
    if i < n:
        v[0] = x1
        w[0] = y1
        v[1] = (2*x1+x2)/3.0
        w[1] = (2*y1+y2)/3.0
        v[2] = (x1+2*x2)/3.0
        w[2] = (y1+2*y2)/3.0
        v[3] = (v[2] - v[1])*math.cos(math.pi/3) - (w[2] - w[1])*math.sin(math.pi/3) + v[1]
        w[3] = (w[2] - w[1])*math.cos(math.pi/3) + (v[2] - v[1])*math.sin(math.pi/3) + w[1]
        v[3] = x2
        w[3] = y2
        KC(i+1, n, v[0], w[0], v[1], w[1])
        print v[1], w[1]
        KC(i+1, n, v[1], w[1], v[3], w[3])
        print v[3], w[3]
        KC(i+1, n, v[3], w[3], v[2], w[2])
        print v[2], w[2]
        KC(i+1, n, v[2], w[2], v[4], w[4])
 
print p1_x, p1_y
KC(0, n, p1_x, p1_y, p2_x, p2_y)
print p2_x, p2_y

Submission status: Runtime Error

Solution code:
import math

def kock(n, x1, y1, x1, y2):
    if n == 0:
        return

    angle = math.radians(60)

    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy

    kock(n-1, x1, y1, sx, sy)
    print sx, sy
    kock(n-1, sx, sy, ux, uy)
    print ux, uy
    kock(n-1, ux, uy, tx, ty)
    print tx, ty
    kock(n-1, tx, ty, x2, y2)

n = input()

p1x = 0.
p1y = 0.
p2x = 100.
p2y = 0.

print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Runtime Error

Solution code:
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
 
for e in koch(p1,p2,n):
    print e.real,e.imagimport math, cmath
 
def koch(p1, p2, n):
    if n == 0:
        return [p1, p2]
     
    rad60 = math.pi/3
    v1 = (p2 - p1)/3
    v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
    q1 = p1 + v1
    q2 = q1 + v2
    q3 = q1 + v1
    if n == 1:
        return [p1,q1,q2,q3,p2]
    else:
        x1 = koch(p1,q1,n-1)[:-1]
        x2 = koch(q1,q2,n-1)[:-1]
        x3 = koch(q2,q3,n-1)[:-1]
        x4 = koch(q3,p2,n-1)
        x = x1 + x2 + x3 + x4
    return x

Submission status: Runtime Error

Solution code:
import math
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
 
for e in koch(p1,p2,n):
    print e.real,e.imagimport math, cmath
 
def koch(p1, p2, n):
    if n == 0:
        return [p1, p2]
     
    rad60 = math.pi/3
    v1 = (p2 - p1)/3
    v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
    q1 = p1 + v1
    q2 = q1 + v2
    q3 = q1 + v1
    if n == 1:
        return [p1,q1,q2,q3,p2]
    else:
        x1 = koch(p1,q1,n-1)[:-1]
        x2 = koch(q1,q2,n-1)[:-1]
        x3 = koch(q2,q3,n-1)[:-1]
        x4 = koch(q3,p2,n-1)
        x = x1 + x2 + x3 + x4
    return x

Submission status: Runtime Error

Solution code:
import math, cmath
 
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
 
for e in koch(p1,p2,n):
    print e.real,e.imag

def koch(p1, p2, n):
    if n == 0:
        return [p1, p2]
     
    rad60 = math.pi/3
    v1 = (p2 - p1)/3
    v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
    q1 = p1 + v1
    q2 = q1 + v2
    q3 = q1 + v1
    if n == 1:
        return [p1,q1,q2,q3,p2]
    else:
        x1 = koch(p1,q1,n-1)[:-1]
        x2 = koch(q1,q2,n-1)[:-1]
        x3 = koch(q2,q3,n-1)[:-1]
        x4 = koch(q3,p2,n-1)
        x = x1 + x2 + x3 + x4
    return x
        x4 = koch(q3,p2,n-1)
        x = x1 + x2 + x3 + x4
    return x

Submission status: Runtime Error

Solution code:
import math, cmath
 
def koch(v1, v2, n):
    if n == 0:
        return [v1, v2]
     
    rad60 = math.pi/3
    u1 = (v2 - v1)/3
    u2 = cmath.rect(abs(u1), cmath.phase(u1)+rad60)
    q1 = v1 + u1
    q2 = q1 + u2
    q3 = q1 + u1
    if n == 1:
        return [v1,q1,q2,q3,v2]
    else:
        x1 = koch(v1,q1,n-1)[:-1]
        x2 = koch(q1,q2,n-1)[:-1]
        x3 = koch(q2,q3,n-1)[:-1]
        x4 = koch(q3,v2,n-1)
        x = x1 + x2 + x3 + x4
    return x
 
n = int(raw_input())
v1 = complex(0,0)
v2 = complex(100,0)
 
for e in koch(p1,p2,n):
    print e.real,e.imag

Submission status: Runtime Error

Solution code:
import math

  
x1 = 0
y1 = 0
x2 = 100
y2 = 0
  
def koch curve(i, n, x1, y1, x2, y2):
    x = [0] * 5
    y = [0] * 5
    if i < n:
        x[0] = x1
        y[0] = y1
        x[1] = (2 * x1 + x2) / 3.0
        y[1] = (2 * y1 + y2) / 3.0
        x[2] = (x1 + 2 * x2) / 3.0
        y[2] = (y1 + 2 * y2) / 3.0
        x[3] = (x[2] - x[1]) * math.cos(math.pi/3) - (x[2] - x[1]) * math.sin(math.pi/3) + y[1]
        y[3] = (y[2] - y[1]) * math.cos(math.pi/3) + (y[2] - y[1]) * math.sin(math.pi/3) + x[1]
        x[4] = x2
        y[4] = y2
        koch curve(i+1, n, x[0], y[0], x[1], y[1])
        print x[1], y[1]
        koch curve(i+1, n, x[1], y[1], x[3], y[3])
        print x[3], y[3]
        koch curve(i+1, n, x[3], y[3], x[2], y[2])
        print x[2], y[2]
        koch curve(i+1, n, x[2], y[2], x[4], y[4])
n = input()  
print x1 y1
koch curve(0, n, x1, y1, x2,y2)
print x2, y2

Submission status: Runtime Error

Solution code:

import math

  
x1 = 0
y1 = 0
x2 = 100
y2 = 0
  
def koch curve(i, n, x1, y1, x2, y2):
    x = [0] * 5
    y = [0] * 5
    if i < n:
        x[0] = x1
        y[0] = y1
        x[1] = (2 * x1 + x2) / 3.0
        y[1] = (2 * y1 + y2) / 3.0
        x[2] = (x1 + 2 * x2) / 3.0
        y[2] = (y1 + 2 * y2) / 3.0
        x[3] = (x[2] - x[1]) * math.cos(math.pi/3) - (x[2] - x[1]) * math.sin(math.pi/3) + x[1]
        y[3] = (y[2] - y[1]) * math.cos(math.pi/3) + (y[2] - y[1]) * math.sin(math.pi/3) + y[1]
        x[4] = x2
        y[4] = y2
        koch_curve(i+1, n, x[0], y[0], x[1], y[1])
        print x[1], y[1]
        koch_curve(i+1, n, x[1], y[1], x[3], y[3])
        print x[3], y[3]
        koch_curve(i+1, n, x[3], y[3], x[2], y[2])
        print x[2], y[2]
        koch_curve(i+1, n, x[2], y[2], x[4], y[4])
n = input()  
print x1 y1
koch_curve(0, n, x1, y1, x2,y2)
print x2, y2

Submission status: Runtime Error

Solution code:

ef koch_curve(i, n, x1, y1, x2, y2):
    x = [0] * 5
    y = [0] * 5
    if i < n:
        x[0] = x1
        y[0] = y1
        x[1] = (2 * x1 + x2) / 3.0
        y[1] = (2 * y1 + y2) / 3.0
        x[2] = (x1 + 2 * x2) / 3.0
        y[2] = (y1 + 2 * y2) / 3.0
        x[3] = (x[2] - x[1]) * math.cos(math.pi/3) - (x[2] - x[1]) * math.sin(math.pi/3) + x[1]
        y[3] = (y[2] - y[1]) * math.cos(math.pi/3) + (y[2] - y[1]) * math.sin(math.pi/3) + y[1]
        x[4] = x2
        y[4] = y2
        koch_curve(i+1, n, x[0], y[0], x[1], y[1])
        print x[1], y[1]
        koch_curve(i+1, n, x[1], y[1], x[3], y[3])
        print x[3], y[3]
        koch_curve(i+1, n, x[3], y[3], x[2], y[2])
        print x[2], y[2]
        koch_curve(i+1, n, x[2], y[2], x[4], y[4])
n = input()  
print x1 y1
koch_curve(0, n, x1, y1, x2,y2)
print x2, y2

Submission status: Runtime Error

Solution code:
import math

  
x1 = 0
y1 = 0
x2 = 100
y2 = 0
  
def koch_curve(i, n, x1, y1, x2, y2):
    x = [0] * 5
    y = [0] * 5
    if i < n:
        x[0] = x1
        y[0] = y1
        x[1] = (2 * x1 + x2) / 3.0
        y[1] = (2 * y1 + y2) / 3.0
        x[2] = (x1 + 2 * x2) / 3.0
        y[2] = (y1 + 2 * y2) / 3.0
        x[3] = (x[2] - x[1]) * math.cos(math.pi/3) - (x[2] - x[1]) * math.sin(math.pi/3) + x[1]
        y[3] = (y[2] - y[1]) * math.cos(math.pi/3) + (y[2] - y[1]) * math.sin(math.pi/3) + y[1]
        x[4] = x2
        y[4] = y2
        koch_curve(i+1, n, x[0], y[0], x[1], y[1])
        print x[1], y[1]
        koch_curve(i+1, n, x[1], y[1], x[3], y[3])
        print x[3], y[3]
        koch_curve(i+1, n, x[3], y[3], x[2], y[2])
        print x[2], y[2]
        koch_curve(i+1, n, x[2], y[2], x[4], y[4])
n = input()  
print x1 y1
koch_curve(0, n, x1, y1, x2,y2)
print x2, y2

Submission status: Runtime Error

Solution code:
03 sec    6668 KB    36 lines     878 bytes    2016-01-16 19:46 




?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
import math
n = input()
  
p1_x = float(0)
p1_y = float(0)
p2_x = float(100)
p2_y = float(0)
  
 
def kock(i, n, x1, y1, x2, y2):
    a = [0,0,0,0,0]
    b = [0,0,0,0,0]
    if i < n:
        a[0] = x1
        b[0] = y1
        a[1] = (2*x1+x2)/3.0
        b[1] = (2*y1+y2)/3.0
        a[2] = (x1+2*x2)/3.0
        b[2] = (y1+2*y2)/3.0
        a[3] = (a[2] - a[1])*math.cos(math.pi/3) - (b[2] - b[1])*math.sin(math.pi/3) + a[1]
        b[3] = (b[2] - b[1])*math.cos(math.pi/3) + (a[2] - a[1])*math.sin(math.pi/3) + b[1]
        a[4] = x2
        b[4] = y2
        kock(i+1, n, a[0], b[0], a[1], b[1])
        print a[1], b[1]
        kock(i+1, n, a[1], b[1], a[3], b[3])
        print a[3], b[3]
        kock(i+1, n, a[3], b[3], a[2], b[2])
        print a[2], b[2]
        kock(i+1, n, a[2], b[2], a[4], b[4])
 
print p1_x, p1_y
kock(0, n, p1_x, p1_y, p2_x, p2_y)
print p2_x, p2_y

Submission status: Runtime Error

Solution code:
import math

def koch(n, x1, y1, x2, y2):
    if n == 0:
        return
  
    angle = math.radians(60)
  
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy
  
    koch(n-1, x1, y1, sx, sy)
    print sx, sy
    koch(n-1, sx, sy, ux, uy)
    print ux, uy
    koch(n-1, ux, uy, tx, ty)
    print tx, ty
    koch(n-1, tx, ty, x2, y2)
  
n = input()
  
p1x = 0.0
p1y = 0.0
p2x = 100.0
p2y = 0.0
  
print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Runtime Error

Solution code:
degree = math.pi / 3
 
def print_point(point):
    print "%f %f"
 
def koch(depth, p1, p2):
    if depth == 0:
        return
    s = ((2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3)
    t = ((p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3)
    u = ((t[0] - s[0]) * math.cos(degree) - (t[1] - s[1]) * math.sin(degree) + s[0],
         (t[0] - s[0]) * math.sin(degree) + (t[1] - s[1]) * math.cos(degree) + s[1])
    depth -= 1
    koch(depth, p1, s)
    print_point(s)
    koch(depth, s, u)
    print_point(u)
    koch(depth, u, t)
    print_point(t)
    koch(depth, t, p2)
 
n = int(raw_input())
start = (0.0, 0.0)
end = (100.0, 0.0)
print_point(start)
koch(n, start, end)
print_point(end)

Submission status: Runtime Error

Solution code:
import math
n = int(raw_input())
degree = math.pi / 3
??????????
def print_point(point):
????????print "%f %f" % (point[0], point[1])
??????????
def koch(depth, p1, p2):
????????if depth == 0:
????????????????return
????????s = ((2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3)
????????t = ((p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3)
????????u = ((t[0] - s[0]) * math.cos(degree) - (t[1] - s[1]) * math.sin(degree) + s[0],
??????????????????(t[0] - s[0]) * math.sin(degree) + (t[1] - s[1]) * math.cos(degree) + s[1])
????????depth -= 1
????????koch(depth, p1, s)
????????print_point(s)
????????koch(depth, s, u)
????????print_point(u)
????????koch(depth, u, t)
????????print_point(t)
????????koch(depth, t, p2)
??????????
start = (0.0, 0.0)
end = (100.0, 0.0)
print_point(start)
koch(n, start, end)
print_point(end)

Submission status: Runtime Error

Solution code:
import math
n = input()

def koch(n, p1_x, p2_x, p1_y, p2_y):
  if n == 0:
    return
  
  %p1, p2 ?????? s, t, u ????¨????

  s_x = (2*p1_x + p2_x) / 3
  s_y = (2*p1_y + p2_y) / 3
  t_x = (p1_x + 2*p2_x) / 3
  t_y = (p1_y + 2*p2_y) / 3

  u_x = (t_x - s_x)/2 - (t_y - s_y) * sqrt(3)/2 + s_x
  u_y = (t_x - s_x) * sqrt(3)/2 + (t_y - s_y)/2 + s_y

  koch(n-1, p1_x, s_x, p1_y, s_y)
  print s_x, s_y
  koch(n-1, s_x, u_x, s_y, u_y)
  print u_x, u_y
  koch(n-1, u_x, t_x, u_y, t_y)
  print t_x, t_y
  koch(n-1, t_x, p2_x, t_y, p2_y)

print 0.0, 0.0
koch(n, 0, 100, 0, 0)
print 100.0, 0.0

Submission status: Runtime Error

Solution code:
import math
n = input()

def koch(n, p1_x, p2_x, p1_y, p2_y):
  if n == 0:
    return
  
  %p1, p2 ?????? s, t, u ????¨????

  s_x = (2*p1_x + p2_x) / 3
  s_y = (2*p1_y + p2_y) / 3
  t_x = (p1_x + 2*p2_x) / 3
  t_y = (p1_y + 2*p2_y) / 3

  u_x = (t_x - s_x)/2 - (t_y - s_y) * sqrt(3)/2 + s_x
  u_y = (t_x - s_x) * sqrt(3)/2 + (t_y - s_y)/2 + s_y

  koch(n-1, p1_x, s_x, p1_y, s_y)
  print s_x, s_y
  koch(n-1, s_x, u_x, s_y, u_y)
  print u_x, u_y
  koch(n-1, u_x, t_x, u_y, t_y)
  print t_x, t_y
  koch(n-1, t_x, p2_x, t_y, p2_y)

p1_x = 0.0
p1_y = 0.0
p2_x = 100.0
p2_y = 0.0

print p1_x, p1_y
koch(n, 0, 100, 0, 0)
print p2_x, p2_y

Submission status: Runtime Error

Solution code:
import math
n = input()

def koch(n, p1_x, p2_x, p1_y, p2_y):
  if n == 0:
    return

  s_x = (2*p1_x + p2_x) / 3
  s_y = (2*p1_y + p2_y) / 3
  t_x = (p1_x + 2*p2_x) / 3
  t_y = (p1_y + 2*p2_y) / 3

  u_x = (t_x - s_x)/2 - (t_y - s_y) * sqrt(3)/2 + s_x
  u_y = (t_x - s_x) * sqrt(3)/2 + (t_y - s_y)/2 + s_y

  koch(n-1, p1_x, s_x, p1_y, s_y)
  print s_x, s_y
  koch(n-1, s_x, u_x, s_y, u_y)
  print u_x, u_y
  koch(n-1, u_x, t_x, u_y, t_y)
  print t_x, t_y
  koch(n-1, t_x, p2_x, t_y, p2_y)

p1_x = 0.0
p1_y = 0.0
p2_x = 100.0
p2_y = 0.0

print p1_x, p1_y
koch(n, 0, 100, 0, 0)
print p2_x, p2_y

Submission status: Runtime Error

Solution code:
import math
from numpy import array

def koch(n, a, b):
	print '%.8f %.8f' % (a[0], a[1])
	if(n == 0):
		return
	x = (a*2 + b) / 3
	y = (a - b) * array([math.cos(math.pi/3), -math.sin(math.pi/3)],[math.sin(math.pi/3), math.cos(math.pi/3)]) + x
	z = (a + b*2) / 3
	koch(n-1, a, x)
	koch(n-1, x, y)
	koch(n-1, y, z)
	koch(n-1, z, b)

n = input()

p1 = array([0.0, 0.0])
p2 = array([100.0, 0.0])

koch(n, p1, p2)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
theta = math.pi / 3
p1 = [0, 0]
p2 = [100, 0]


def kock(d, p1, p2):
    if d == 0:
        return

    sx = (p1[0] + 2 * p2[0]) / 3
    tx = (2 * p1[0] + p2[0]) / 3
    sy = (p1[1] + 2 * p2[1]) / 3
    ty = (2 * p1[1] + p2[1]) / 3
    s = [sx, sy]
    t = [tx, ty]

    ux = (t[0] - s[0]) * math.cos(theta) + (t[1] - s[1]) * math.sin(theta) + sx
    uy = (t[1] - s[1]) * math.cos(theta) - (t[0] - s[0]) * math.sin(theta) + sy
    u = [ux, uy]

    kock(n - 1, p1, s)
    print("{0} {1}".format(s[0], s[1], '.8f'))
    kock(n - 1, s, u)
    print("{0} {1}".format(u[0], u[1], '.8f'))
    kock(n -1 ,u, t)
    print("{0} {1}".format(t[0], t[1], '.8f'))
    kock(n - 1, t, p2)

if __name__ == '__main__':
    print("0.0000000 0.0000000")
    kock(n, p1, p2)
    print("100.0000000 0.0000000")

Submission status: Runtime Error

Solution code:
# coding=utf-8
import math


def divide_segment(left, right):
    """divide segment

    Args:
        left: left edge coordinate
        right: right edge coordinate

    Returns:
        divided points
    """
    delta_x_quarter = (right[0] - left[0]) / 3.0
    delta_y_quarter = (right[1] - left[1]) / 3.0

    delta_x_quarter_rotated = (delta_x_quarter - math.sqrt(3) * delta_y_quarter) / 2.0
    delta_y_quarter_rotated = (math.sqrt(3) * delta_x_quarter + delta_y_quarter) / 2.0

    s = [left[0] + delta_x_quarter, left[1] + delta_y_quarter]
    t = [left[0] + delta_x_quarter * 2.0, left[1] + delta_y_quarter * 2.0]
    u = [s[0] + delta_x_quarter_rotated, s[1] + delta_y_quarter_rotated]

    return s, t, u


def make_coch_curve(depth, left, right):
    """make coch curve with depth iteration_number between point left, right
    each vertices positions are printed

    Args:
        depth: depth
        left: left edge point
        right: right edge point

    Returns:
        None
    """
    print("{0:2.8f} {1:2.8f}".format(left[0], left[1]))
    make_coch_curve_recursively(depth, left, right)


def make_coch_curve_recursively(depth, left, right):
    """recursion part of coch curve

    Args:
        depth: depth
        left: left edge coordinate
        right: right edge coordinate

    Returns:
        None
    """
    # get coordinate of divided points
    s, t, u = divide_segment(left, right)

    if depth == 1:
        print("{0:2.8f} {1:2.8f}".format(s[0], s[1]))
        print("{0:2.8f} {1:2.8f}".format(u[0], u[1]))
        print("{0:2.8f} {1:2.8f}".format(t[0], t[1]))
        print("{0:2.8f} {1:2.8f}".format(right[0], right[1]))
    else:
        make_coch_curve_recursively(depth - 1, left, s)
        make_coch_curve_recursively(depth - 1, s, u)
        make_coch_curve_recursively(depth - 1, u, t)
        make_coch_curve_recursively(depth - 1, t, right)


def main():
    depth = int(input().strip())
    make_coch_curve(depth, left=[0.0, 0.0], right=[100.0, 0.0])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import math

def kochCurve(p1, p2, n):
  if n == 0:
    print(p2[0], p2[1])
    return

  v = (p2 - p1)/3
  s = p1 + v
  t = s + v

  theta = math.atan2(v[1], v[0])

  a = np.linalg.norm(t - s)
  h = 3**(1/2)*a/2
  u = s + (t - s)/2 + np.array([h*math.sin(theta), h*math.cos(theta)])

#  print(n, p1, s, u, t, p2)

  n -= 1
  kochCurve(p1, s, n)
  kochCurve(s, u, n)
  kochCurve(u, t, n)
  kochCurve(t, p2, n)

if __name__ == "__main__":
  n = int(input())
  print([0, 0])
  kochCurve(np.array([0, 0]), np.array([100, 0]), n)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

def kochCurve(p1, p2, n):
  if n == 0:
    print(p2[0], p2[1])
    return

  v = (p2 - p1)/3
  s = p1 + v
  t = s + v

  theta = math.atan2(v[1], v[0])

  a = np.linalg.norm(t - s)
  h = 3**(1/2)*a/2
  u = s + (t - s)/2 + np.array([h*math.sin(theta), h*math.cos(theta)])

#  print(n, p1, s, u, t, p2)

  n -= 1
  kochCurve(p1, s, n)
  kochCurve(s, u, n)
  kochCurve(u, t, n)
  kochCurve(t, p2, n)

if __name__ == "__main__":
  n = int(input())
  print(0, 0)
  kochCurve(np.array([0, 0]), np.array([100, 0]), n)

Submission status: Runtime Error

Solution code:
import numpy as np

def koch_divide(p,q):
    v = q-p
    r = np.array([[0.866, 0.5],[-0.5, 0.866]])
    s = p + v/3
    t = q - v/3
    u = p + np.dot(v,r)/np.sqrt(3)
    return [s,u,t,q]

def koch_curve(previous):
    vertices = [previous[0]]
    for p,q in zip(previous[:-1], previous[1:]):
        vertices.append(koch_divide(p,q))
    return vertices

if __name__=='__main__':
    p_q = np.array([[0.0, 0.0], [100.0, 0.0]])
    n = int(input())
    for _ in range(n):
        p_q = koch_curve(p_q)
    for vertex in p_q:
        print(" ".join(map(str, vertex)))

Submission status: Runtime Error

Solution code:
import numpy as np

def koch_divide(p,q):
    v = q-p
    r = np.array([[np.sqrt(3)/2, 0.5],[-0.5, np.sqrt(3)/2]])
    s = p + v/3
    t = q - v/3
    u = p + np.dot(v,r)/np.sqrt(3)
    return [s,u,t,q]

def koch_curve(previous):
    vertices = [previous[0]]
    for p,q in zip(previous[:-1], previous[1:]):
        vertices.extend(koch_divide(p,q))
    return vertices

if __name__=='__main__':
    p_q = np.array([[0.0, 0.0], [100.0, 0.0]])
    n = int(input())
    for _ in range(n):
        p_q = koch_curve(p_q)
    for vertex in p_q:
        print(" ".join(map(str, vertex)))

Submission status: Runtime Error

Solution code:
import numpy as np

def koch_divide(p,q):
    v = q-p
    r = np.array([[np.sqrt(3)/2, 0.5],[-0.5, np.sqrt(3)/2]])
    s = p + v/3
    t = q - v/3
    u = p + np.dot(v,r)/np.sqrt(3)
    return [s,u,t,q]

def koch_curve(previous):
    vertices = [previous[0]]
    for p,q in zip(previous[:-1], previous[1:]):
        vertices.extend(koch_divide(p,q))
    return vertices

if __name__=='__main__':
    p_q = np.array([[0.0, 0.0], [100.0, 0.0]])
    n = int(input())
    for _ in range(n):
        p_q = koch_curve(p_q)
    for vertex in p_q:
        print(" ".join(np.vectorize("%.8f".__mod__)(vertex)))

Submission status: Runtime Error

Solution code:
import math

def koch(p2, n, points):
	p1 = points[-1]
	x, y = p2[0]-p1[0], p2[1]-p1[1]
	s = [p1[0]+x/3, p1[1]+y/3]
	t = [p1[0]+x*2/3, p1[1]+y*2/3]
	r = (x**2 + y**2) ** 0.5 / 3
	theta = math.atan(y/x) + math.pi/3
	u = [s[0]+r*math.cos(theta), s[1]+r*math.sin(theta)]
	
	if n == 1:
		points.extend([s,u,t,p2])
	else:
		koch(s, n-1, points)
		koch(u, n-1, points)
		koch(t, n-1, points)
		koch(p2, n-1, points)


if __name__ == '__main__':
	n = int(input())
	p1 = [0.0, 0.0]
	p2 = [100.0, 0.0]
	points = [p1]
	koch(p2, n, points)
	[print(*p) for p in points]

Submission status: Runtime Error

Solution code:
from math import sqrt
q3 = sqrt(3)
fmt = "%.8f %.8f"
def koch(x0, y0, x1, y1, c):
    xp = (x0*2 + x1) / 3
    yp = (y0*2 + y1) / 3

    xq = (x0 + x1*2) / 3
    yq = (y0 + y1*2) / 3

    dx = (x1 - x0) / 6
    dy = (y1 - y0) / 6

    xr = xp + (dx - dy * q3)
    yr = yp + (dx * q3 + dy)

    if c == n-1:
        return (fmt % (x0, y0), fmt % (xp, yp), fmt % (xr, yr), fmt % (xq, yq))
    return koch(x0, y0, xp, yp, c+1) + koch(xp, yp, xr, yr, c+1) + koch(xr, yr, xq, yq, c+1) + koch(xq, yq, x1, y1, c+1)
n = int(input())
print(*koch(0, 0, 100, 0, 0)+(fmt % (100, 0),), sep='\n')

Submission status: Runtime Error

Solution code:
import math

n = int(raw_input())

def vector_rot(vector, radian):
	new_x = vector[0] * math.cos(radian) - vector[1] * math.sin(radian)
	new_y = vector[0] * math.sin(radian) + vector[1] * math.cos(radian)
	return [new_x, new_y]

def vector_add(v1, v2):
	new_v = []
	for i in range(2):
		add = v1[i] + v2[i]
		new_v.append(add)
	return new_v

def makepoint(p_A1, p_A2):
	x_p_C1 = (p_A2[0] - p_A1[0]) / 3 + p_A1[0]
	y_p_C1 = (p_A2[1] - p_A1[1]) / 3 + p_A1[1]
	x_p_C3 = (p_A2[0] - p_A1[0]) * 2 / 3 + p_A1[0]
	y_p_C3 = (p_A2[1] - p_A1[1]) * 2 / 3 + p_A1[1]

	p_C1 = [x_p_C1, y_p_C1]
	p_C3 = [x_p_C3, y_p_C3]

	v01 = [x_p_C1 - p_A1[0], y_p_C1 - p_A1[1]]
	rot_v01 = vector_rot(v01, 60 * math.pi / 180)
	v02 = vector_add(v01, rot_v01)
	p_C2 = vector_add(p_A1, v02)	
	
	C = [p_C1, p_C2, p_C3]
	return C

A = [[0., 0.],[100., 0.]]
for i in range(n):
	B = []
	for j in range(len(A)-1): #A[j]??¨A[j+1]
		C = makepoint(A[j], A[j+1]) #C = [p_C1, p_C2, p_C3]
		B.append(A[j])
		for p in C:
			B.append(p)
		#A[j+1]????¬????makepoint?????????append??????
	B.append(A[-1]) #??????????????\?????\??????
	A = B

for x in A:
	print("{:.8f}".format(x[0])),
	print("{:.8f}".format(x[1]))

Submission status: Runtime Error

Solution code:
import numpy as np

n=int(input())

p1=[0,0]
p2=[100,0]

def Koch(d,p1,p2):
	if d==0:
		return
	
	sx=(2*p1[0]+p2[0])/3
	sy=(2*p1[1]+p2[1])/3
	tx=(p1[0]+2*p2[0])/3
	ty=(p1[1]+2*p2[1])/3
	ux=(tx-sx)*np.cos(np.pi/3)-(ty-sy)*np.sin(np.pi/3)+sx
	uy=(tx-sx)*np.cos(np.pi/3)+(ty-sy)*np.sin(np.pi/3)+sy
	
	Koch(d-1,p1,[sx,sy])
	print(sx,sy)
	Koch(d-1,[sx,sy],[ux,uy])
	print(ux,uy)
	Koch(d-1,[ux,uy],[tx,ty])
	print(tx,ty)
	Koch(d-1,[tx,ty],p2)
	
print(p1[0],p1[1])
Koch(n,p1,p2)
print(p2[0],p2[1])

Submission status: Runtime Error

Solution code:
import numpy as np

n=int(input())

p1=[float(0),float(0)]
p2=[float(100),float(0)]

def Koch(d,p1,p2):
	if d==0:
		return
	
	sx=(2*p1[0]+p2[0])/3
	sy=(2*p1[1]+p2[1])/3
	tx=(p1[0]+2*p2[0])/3
	ty=(p1[1]+2*p2[1])/3
	ux=(tx-sx)*np.cos(np.pi/3)-(ty-sy)*np.sin(np.pi/3)+sx
	uy=(tx-sx)*np.cos(np.pi/3)+(ty-sy)*np.sin(np.pi/3)+sy
	
	Koch(d-1,p1,[sx,sy])
	print(sx,sy)
	Koch(d-1,[sx,sy],[ux,uy])
	print(ux,uy)
	Koch(d-1,[ux,uy],[tx,ty])
	print(tx,ty)
	Koch(d-1,[tx,ty],p2)
	
print(p1[0],p1[1])
Koch(n,p1,p2)
print(p2[0],p2[1])