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: Wrong Answer

Solution code:
import math
n = input()
def koch(n, x, y, x2, y2):
    if n == 0:
        return
 
 
    sx = (2*x+x2)/3
    sy = (2*y+y2)/3
    tx = (2*x2+x)/3
    ty = (2*y2+y)/3
    ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) +sx
    uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sy
 
    koch( n-1 , x , y , 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 )
 

 
px = 0
py = 0
p_x = 100
p_y = 0
 
print px , py
koch( n , px , py , p_x , p_y )
print p_x , p_y

Submission status: Wrong Answer

Solution code:
import math
n = input()
def koch(n, x, y, x2, y2):
    if n == 0:
        return
 
 
    sx = (2*x+x2)/3
    sy = (2*y+y2)/3
    tx = (x+2*x2)/3
    ty = (y+2*y2)/3
    ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) +sx
    uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sy
 
    koch( n-1 , x , y , 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 )

Submission status: Wrong Answer

Solution code:
import math
n = input()
def koch(n, x, y, x2, y2):
    if n == 0:
        return
 
 
    sx = (2*x+x2)/3
    sy = (2*y+y2)/3
    tx = (x+2*x2)/3
    ty = (y+2*y2)/3
    ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) +sx
    uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sy
 
    koch( n-1 , x , y , 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 )
 

 
px = 0
py = 0
p_x = 100
p_y = 0
 
print px , py
koch( n , px , py , p_x , p_y )
print p_x , p_y

Submission status: Wrong Answer

Solution code:
import math

def koch(n, x, y, x2, y2):
    if n == 0:
        return
 
 
    sx = (2*x+x2)/3
    sy = (2*y+y2)/3
    tx = (x+2*x2)/3
    ty = (y+2*y2)/3
    ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) +sx
    uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sy
 
    koch( n-1 , x , y , 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 )
 

 
px = 0
py = 0
p_x = 100
p_y = 0
n = input() 
print px , py
koch( n , px , py , p_x , p_y )
print p_x , p_y

Submission status: Wrong Answer

Solution code:
import math

def koch(n, x, y, x2, y2):
    if n == 0:
      return
 
 
    sx = (2*x+x2)/3
    sy = (2*y+y2)/3
    tx = (x+2*x2)/3
    ty = (y+2*y2)/3
    ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) +sy
    uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sx
 
    koch( n-1 , x , y , 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 )
 

 
px = 0
py = 0
p_x = 100
p_y = 0
n = input() 
print px , py
koch( n , px , py , p_x , p_y )
print p_x , p_y

Submission status: Wrong Answer

Solution code:
import math

n=int(input())

def kock(n, p1x, p1y, p2x, p2y):

    m=math.radians(60)

    if(n == 0):
        return

    sx=(2*p1x+1*p2x)/3
    sy=(2*p1y+1*p2y)/3
    tx=(1*p1x+2*p2x)/3
    ty=(1*p1y+2*p2y)/3

    ux=(tx-sx)*math.cos(m)-(ty-sy)*math.sin(m)+sx
    uy=(tx-sx)*math.sin(m)-(ty-sy)*math.cos(m)+sy


    kock(n-1, p1x, p1y, 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, p2x, p2y)
    
    

p1x = 0.00000000
p1y = 0.00000000
p2x = 100.00000000
p2y = 0.00000000
 
print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
m=math.radians(60)

def kock(n, p1x, p1y, p2x, p2y):

    
    if(n == 0):
        return

    sx=(2*p1x+1*p2x)/3
    sy=(2*p1y+1*p2y)/3
    tx=(1*p1x+2*p2x)/3
    ty=(1*p1y+2*p2y)/3

    ux=(tx-sx)*math.cos(m)-(ty-sy)*math.sin(m)+sx
    uy=(tx-sx)*math.sin(m)-(ty-sy)*math.cos(m)+sy


    kock(n-1, p1x, p1y, 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, p2x, p2y)
    
    

p1x = 0.00000000
p1y = 0.00000000
p2x = 100.00000000
p2y = 0.00000000
 
print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
m=math.radians(60)

def kock(n, p1x, p1y, p2x, p2y):

    
    if(n == 0):
        return

    sx=(2*p1x+1*p2x)/3
    sy=(2*p1y+1*p2y)/3
    tx=(1*p1x+2*p2x)/3
    ty=(1*p1y+2*p2y)/3

    ux=(tx-sx)*math.cos(m)-(ty-sy)*math.sin(m)+sx
    uy=(tx-sx)*math.sin(m)-(ty-sy)*math.cos(m)+sy


    kock(n-1, p1x, p1y, sx, sy)
    print round(sx,8),round(sy, 8)
    kock(n-1, sx, sy, ux, uy)
    print round(ux, 8),round(uy, 8)
    kock(n-1, ux, uy, tx, ty)
    print round(tx, 8),round(ty, 8)
    kock(n-1, tx, ty, p2x, p2y)
    

p1x = 0.
p1y = 0.
p2x = 100.
p2y = 0.
 
print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:

import math

n=input()
m=math.radians(60)

def kock(n, p1x, p1y, p2x, p2y):

    
    if(n == 0):
        return

    sx=(2*p1x+1*p2x)/3
    sy=(2*p1y+1*p2y)/3
    tx=(1*p1x+2*p2x)/3
    ty=(1*p1y+2*p2y)/3

    ux=(tx-sx)*math.cos(m)-(ty-sy)*math.sin(m)+sx
    uy=(tx-sx)*math.sin(m)-(ty-sy)*math.cos(m)+sy


    kock(n-1, p1x, p1y, sx, sy)
    print round(sx,8),round(sy, 8)
    kock(n-1, sx, sy, ux, uy)
    print round(ux, 8),round(uy, 8)
    kock(n-1, ux, uy, tx, ty)
    print round(tx, 8),round(ty, 8)
    kock(n-1, tx, ty, p2x, p2y)
    

p1x = 0.
p1y = 0.
p2x = 100.
p2y = 0.
 
print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Submission status: Wrong Answer

Solution code:
import math
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: Wrong Answer

Solution code:
import math
n = int(raw_input())
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)
   
start = (0.0, 0.0)
end = (100.0, 0.0)
print_point(start)
koch(n, start, end)
print_point(end)

Submission status: Wrong Answer

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)
end = (100, 0)
print_point(start)
koch(n, start, end)
print_point(end)

Submission status: Wrong Answer

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

koch(n, 0, 100, 0, 0)

Submission status: Wrong Answer

Solution code:
import math

class KochCurve:
    def koch(self, d, p1, p2): 
        if d == 0:
            return
        th = math.pi * 60.0 / 180
        sx = (2.0 * p1[0] + 1.0 * p2[0]) / 3
        sy = (2.0 * p1[1] + 1.0 * p1[1]) / 3
        s = (sx, sy)
        tx = (1.0 * p1[0] + 2.0 * p2[0]) / 3
        ty = (1.0 * p1[1] + 2.0 * p2[1]) / 3
        t = (tx, ty)
        ux = (tx - sx) * math.cos(th) - (ty - sy) * math.sin(th) + sx
        uy = (tx - sx) * math.sin(th) + (ty - sy) * math.cos(th) + sy
        u = (ux, uy)
        self.koch(d-1, p1, s)
        print("{} {}".format(sx, sy))
        self.koch(d-1, s, u)
        print("{} {}".format(ux, uy))
        self.koch(d-1, u, t)
        print("{} {}".format(tx, ty))
        self.koch(d-1, t, p2)

if __name__ == '__main__':
    n = int(input().rstrip())
    p1 = (0, 0)
    p2 = (100, 0)
    print("{} {}".format(p1[0], p1[1]))
    x = KochCurve()
    x.koch(n, p1, p2)
    print("{} {}".format(p2[0], p2[1]))

Submission status: Wrong Answer

Solution code:
import math

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

    s = ((p1[0] + p2[0]) / 3, (p1[1] + p2[1]) / 3)
    t = ((p1[0] + p2[0]) * 2 / 3, (p1[1] + p2[1]) * 2 / 3)
    u = (math.cos(math.pi/3)*(t[0]-s[0])-math.sin(math.pi/3)*(t[1]-s[1])+s[0], math.sin(math.pi/3)*(t[0]-s[0])+math.cos(math.pi/3)*(t[1]-s[1])+s[1])

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

if __name__ == "__main__":
    n = int(input())
    p1 = (0, 0)
    p2 = (100, 0)
    print "%5f %5f" % (p1[0], p1[1])
    kochCurve(p1, p2, n)

Submission status: Wrong Answer

Solution code:
import math

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

    s = ((p2[0] - p1[0]) / 3.0 + p1[0], (p2[1] - p1[1]) / 3.0 + p2[1])
    t = ((p2[0] - p1[0]) * 2.0 / 3 + p1[0], (p2[1] - p1[1]) * 2.0 / 3 + p1[1])
    u = (math.cos(math.pi/3)*(t[0]-s[0])-math.sin(math.pi/3)*(t[1]-s[1])+s[0], math.sin(math.pi/3)*(t[0]-s[0])+math.cos(math.pi/3)*(t[1]-s[1])+s[1])

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

if __name__ == "__main__":
    n = int(input())
    p1 = (0, 0)
    p2 = (100, 0)
    print "%5f %5f" % (p1[0], p1[1])
    kochCurve(p1, p2, n)

Submission status: Wrong Answer

Solution code:
import math

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

    s = ((p2[0] - p1[0]) / 3.0 + p1[0], (p2[1] - p1[1]) / 3.0 + p2[1])
    t = ((p2[0] - p1[0]) * 2.0 / 3 + p1[0], (p2[1] - p1[1]) * 2.0 / 3 + p1[1])
    u = (math.cos(math.pi/3)*(t[0]-s[0])-math.sin(math.pi/3)*(t[1]-s[1])+s[0], math.sin(math.pi/3)*(t[0]-s[0])+math.cos(math.pi/3)*(t[1]-s[1])+s[1])

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

if __name__ == "__main__":
    n = int(input())
    p1 = (0, 0)
    p2 = (100, 0)
    print "%5f %5f" % (p1[0], p1[1])
    kochCurve(p1, p2, n)

Submission status: Wrong Answer

Solution code:
import math

def koch(a1, a2, b1, b2, n, max_n):
    if n >= max_n:
        return 0
    s1 = 2.0/3.0*a1 + 1.0/3.0*b1
    s2 = 2.0/3.0*a2 + 1.0/3.0*b2
    t1 = 1.0/3.0*a1 + 2.0/3.0*b1
    t2 = 1.0/3.0*a2 + 2.0/3.0*b2
    u1 = 1.0/6.0*(3.0*a1 + 3.0*b1 + math.sqrt(3.0)*a2 - math.sqrt(3.0)*b2)
    u2 = 1.0/6.0*(-1.0*math.sqrt(3.0)*a1 + math.sqrt(3.0)*b1 + 3.0*a2 + 3.0*b2)
    print a1, a2
    koch(a1, a2, s1, s2, n+1, max_n)
    print s1, s2
    koch(s1, s2, u1, u2, n+1, max_n)
    print u1, u2
    koch(u1, u2, t1, t2, n+1, max_n)
    print t1, t2
    koch(t1, t2, b1, b2, n+1, max_n)
    print b1, b2
    
if __name__ == '__main__':
    max_n = int(raw_input())
    a1, a2, b1, b2 = 0.0, 0.0, 100.0, 0.0
    koch(a1, a2, b1, b2, 0, max_n)

Submission status: Wrong Answer

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(d - 1, p1, s)
    print("{0:.8f} {1:.8f}".format(s[0], s[1]))
    kock(d - 1, s, u)
    print("{0:.8f} {1:.8f}".format(u[0], u[1]))
    kock(d -1 ,u, t)
    print("{0:.08f} {1:.8f}".format(t[0], t[1]))
    kock(d - 1, t, p2)

if __name__ == '__main__':
    print("0.00000000 0.00000000")
    kock(n, p1, p2)
    print("100.00000000 0.00000000")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

class KochCurve(object):
	x = 0.0
	y = 0.0

	# ?§£???
	def koch(self, n, a, b):
		if n == 0:
			return 

		s = KochCurve()
		t = KochCurve()
		u = KochCurve()
		th = math.pi * 60.0 / 180.0

		s.x = (2.0 * a.x + 1.0 * b.x) / 3.0
		s.y = (2.0 * a.y + 1.0 * b.y) / 3.0
		t.x = (1.0 * a.x + 2.0 * b.x) / 3.0
		t.y = (1.0 * a.y + 2.0 * b.y) / 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
		
		KochCurve().koch(n - 1, a, s)
		msg = "%.8f %.8f" % (s.x, s.y)
		print(msg)
		KochCurve().koch(n - 1, s, u)
		msg = "%.8f %.8f" % (u.x, u.y)
		print(msg)
		KochCurve().koch(n - 1, u, t)
		msg = "%.8f %.8f" % (t.x, t.y)
		print(msg)
		KochCurve().koch(n - 1, t, b)


if __name__ == '__main__':
	a = KochCurve()
	b = KochCurve()

	n = int(input())

	a.x = 0
	a.y = 0
	b.x = 100
	b.y = 0

	msg = "%.8f %.8f" % (a.x, a.y)
	print(msg)
	KochCurve().koch(n, a, b)
	msg = "%.8f %.8f" % (b.x, b.y)
	print(msg)

Submission status: Wrong Answer

Solution code:
import math


def koch(m, p1, p2):
    if m == 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(math.pi / 3) - (t[1] - s[1]) * math.sin(math.pi / 3) + s[0],
         (t[0] - s[0]) * math.sin(math.pi / 3) - (t[1] - s[1]) * math.cos(math.pi / 3) + s[1]]

    koch(m-1, p1, s)
    print(s[0], s[1])
    koch(m-1, s, u)
    print(u[0], u[1])
    koch(m-1, u, t)
    print(t[0], t[1])


n = int(input())
print(0, 0)
koch(n, [0, 0], [100, 0])
print(100, 0)

Submission status: Wrong Answer

Solution code:
import math


def koch(m, p1, p2):
    if m == 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(math.pi / 3) - (t[1] - s[1]) * math.sin(math.pi / 3) + s[0],
         (t[0] - s[0]) * math.sin(math.pi / 3) - (t[1] - s[1]) * math.cos(math.pi / 3) + s[1]]

    koch(m-1, p1, s)
    print(s[0], s[1])
    koch(m-1, s, u)
    print(u[0], u[1])
    koch(m-1, u, t)
    print(t[0], t[1])
    koch(m-1, t, p2)


n = int(input())
print(0, 0)
koch(n, [0, 0], [100, 0])
print(100, 0)

Submission status: Wrong Answer

Solution code:
import math
def Koch(initialx,endx,initialy,endy,repeat):
    if repeat > num:
        return 0
    else:
        onex,secondx = (endx-initialx) / 3 + min(initialx,endx),(endx-initialx) * 2 / 3 + min(initialx,endx)
        if initialy <= endy:
            oney,secondy = abs(endy-initialy) / 3 +initialy,abs(endy-initialy) * 2 / 3 + initialy
        else:
            oney,secondy = initialy - abs(endy-initialy) / 3 ,initialy - abs(endy-initialy) * 2 / 3

        if initialy == endy:
            thirdy = math.sqrt(3) / 2 * (secondx-onex) + oney
            thirdx = (onex + secondx) / 2
        else:
            if initialy > endy:
                if initialx > endx:
                    thirdx = initialx
                    thirdy = secondy
                else:
                    thirdx = endx
                    thirdy = oney
            else:
                if initialx > endx:
                    thirdx = endx
                    thirdy = oney
                else:
                    thirdx = initialx
                    thirdy = secondy
        if [round(initialx,8),round(initialy,8)] not in ans:
            ans.append([round(initialx,8),round(initialy,8)])
        #print(initialx,endx,onex,oney,secondx,secondy,thirdx,thirdy)
        Koch(initialx,onex,initialy,oney,repeat+1)
        Koch(onex,thirdx,oney,thirdy,repeat+1)
        Koch(thirdx,secondx,thirdy,secondy,repeat+1)
        Koch(secondx,endx,secondy,endy,repeat+1)
global num
num = int(input())
ans = []
Koch(0,100,0,0,0)
for n in range(len(ans)):
    print(*ans[n])
print("100.00000000 0.0")

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

def three(p1x, p1y, p2x, p2y):
    dx = (p2x - p1x)
    dy = (p2y - p1y)
    sx = dx / 3 + p1x
    sy = dy / 3 + p1y
    tx = p2x - (dx / 3)
    ty = p2y - (dy / 3)

    mtx = tx - sx
    mty = ty - sy

    rad = math.radians(60)
    mux = mtx * math.cos(rad) - (mty * math.sin(rad))
    muy = mtx * math.sin(rad) + (mty * math.cos(rad))

    ux = mux + sx
    uy = muy + sy

    return [sx, sy, ux, uy, tx, ty]

def koch(p1x, p1y, p2x, p2y, n):
    if 0 == n:
        print(*[p1x, p1y])
    if 0 < n:
        sx, sy, ux, uy, tx, ty = three(p1x, p1y, p2x, p2y)
        koch(p1x, p1y, sx, sy, n - 1)
        koch(sx, sy, ux, uy, n - 1)
        koch(ux, uy, tx, ty, n - 1)
        koch(tx, ty, p2x, p2y, n - 1)

koch(0.00000000, 0.00000000, 100.00000000, 0.00000000, n)
print(*[100.00000000, 100.00000000])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

def three(p1x, p1y, p2x, p2y):
    dx = (p2x - p1x)
    dy = (p2y - p1y)
    sx = dx / 3 + p1x
    sy = dy / 3 + p1y
    tx = p2x - (dx / 3)
    ty = p2y - (dy / 3)

    mtx = tx - sx
    mty = ty - sy

    rad = math.radians(60)
    mux = mtx * math.cos(rad) - (mty * math.sin(rad))
    muy = mtx * math.sin(rad) + (mty * math.cos(rad))

    ux = mux + sx
    uy = muy + sy

    return [sx, sy, ux, uy, tx, ty]

def koch(p1x, p1y, p2x, p2y, n):
    if 0 == n:
        print('{:.8f} {:.8f}'.format(p1x, p1y))
    if 0 < n:
        sx, sy, ux, uy, tx, ty = three(p1x, p1y, p2x, p2y)
        koch(p1x, p1y, sx, sy, n - 1)
        koch(sx, sy, ux, uy, n - 1)
        koch(ux, uy, tx, ty, n - 1)
        koch(tx, ty, p2x, p2y, n - 1)

koch(0.00000000, 0.00000000, 100.00000000, 0.00000000, n)
print('{:.8f} {:.8f}'.format(100.00000000, 100.00000000))

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
import math
def get_koch_curve_points(curve_num, points):

    result = points
    for i in range(curve_num):
        next_list = []
        for j in range(len(result) - 1):
            next_list.extend(koch_curve(result[j], result[j + 1]))
        result = next_list
        
    return result

def koch_curve(left_points, right_points):
    len_x = right_points[0] - left_points[0]
    len_y = right_points[1] - left_points[1]

    distance_x = len_x / 3
    distance_y = len_y / 3

    s = (left_points[0] + distance_x, left_points[1] + distance_y)
    t = (right_points[0] - distance_x, right_points[1] - distance_y)

    cos60 = math.cos(math.radians(60))
    sin60 = math.sin(math.radians(60))
    u = (s[0] + distance_x * cos60 - distance_y * sin60, s[1] + distance_x * sin60 + distance_y * cos60)
    return [left_points, s, u, t, right_points]

if __name__ == "__main__":

    curve_num = int(input())
    res = get_koch_curve_points(curve_num, [(0,0),(100,0)])
    print("\n".join([str(x) + " " + str(y) for x,y in res]))

Submission status: Wrong Answer

Solution code:
# encoding: utf-8


import sys
import math

_input = sys.stdin.readlines()
depth = int(_input[0])
sin_60, cos_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)


class Point(object):
    def __init__(self, x=0.0, y=0.0):
        """
        initialize the point
        """
        self.x = float(x)
        self.y = float(y)


def koch_curve(d, p1, p2):
    if not d:
        return None

    s, t, u = Point(), Point, Point()
    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) * cos_60 - (t.y - s.y) * sin_60 + s.x
    u.y = (t.x - s.x) * sin_60 + (t.y - s.y) * cos_60 + s.y

    koch_curve(d - 1, p1, s)
    print(format(s.x, '.8f'), '', format(s.y, '.8f'))

    koch_curve(d - 1, s, u)
    print(format(u.x, '.8f'), '', format(u.y, '.8f'))

    koch_curve(d - 1, u, t)
    print(format(t.x, '.8f'), '', format(t.y, '.8f'))

    koch_curve(d - 1, t, p2)


if __name__ == '__main__':
    p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
    print(format(p1_start.x, '.8f'), '', format(p1_start.y, '.8f'))
    koch_curve(depth, p1_start, p2_end)
    print(format(p2_end.x, '.8f'), '', format(p2_end.y, '.8f'))

Submission status: Wrong Answer

Solution code:
from math import sin, cos, pi
def koch(px, py, qx, qy, n):
    if n == 0:
        return True
    sx = (2 * px + qx) / 3
    sy = (2 * py + qy) / 3
    tx = (px + 2 * qx) / 3
    ty = (py + 2 * qy) / 3
    ux = sx + (tx - sx) * cos(pi / 3) - (ty - sy) * sin(pi / 3)
    uy = sy + (tx - sx) * sin(pi / 3) - (ty - sy) * cos(pi / 3)
    koch(px, py, sx, sy, n - 1)
    print("{:.8f} {:.8f}".format(sx, sy))
    koch(sx, sy, ux, uy, n - 1)
    print("{:.8f} {:.8f}".format(ux, uy))
    koch(ux, uy, tx, ty, n - 1)
    print("{:.8f} {:.8f}".format(tx, ty))
    koch(tx, ty, qx, qy, n - 1)
print("{:.8f} {:.8f}".format(0, 0))
koch(0, 0, 100, 0, 2)
print("{:.8f} {:.8f}".format(100, 0))

Submission status: Wrong Answer

Solution code:
from math import sin, cos, pi
def koch(px, py, qx, qy, n):
    if n == 0:
        return True
    sx = (2 * px + qx) / 3
    sy = (2 * py + qy) / 3
    tx = (px + 2 * qx) / 3
    ty = (py + 2 * qy) / 3
    ux = sx + (tx - sx) * cos(pi / 3) - (ty - sy) * sin(pi / 3)
    uy = sy + (tx - sx) * sin(pi / 3) - (ty - sy) * cos(pi / 3)
    koch(px, py, sx, sy, n - 1)
    print("{:.8f} {:.8f}".format(sx, sy))
    koch(sx, sy, ux, uy, n - 1)
    print("{:.8f} {:.8f}".format(ux, uy))
    koch(ux, uy, tx, ty, n - 1)
    print("{:.8f} {:.8f}".format(tx, ty))
    koch(tx, ty, qx, qy, n - 1)
n = int(input())
print("{:.8f} {:.8f}".format(0, 0))
koch(0, 0, 100, 0, n)
print("{:.8f} {:.8f}".format(100, 0))

Submission status: Wrong Answer

Solution code:
from math import radians, cos, sin


def calc_koch(depth, p1, p2):
    if depth == 0:
        return

    s = ((2 * p1[0] + 1 * p2[0]) / 3.0, (2 * p1[1] + 1 * p2[1]) / 3.0)
    t = ((1 * p1[0] + 2 * p2[0]) / 3.0, (1 * p1[1] + 2 * p2[1]) / 3.0)
    ux = (t[0]-s[0]) * cos(radians(60)) - (t[1] - s[1]) * sin(radians(60)) + s[0]
    uy = (t[0]-s[0]) * sin(radians(60)) - (t[1] - s[1]) * cos(radians(60)) + s[1]
    u = (ux, uy)

    calc_koch(depth-1, p1, s)
    print('{0:.8f} {1:.8f}'.format(*s))
    calc_koch(depth-1, s, u)
    print('{0:.8f} {1:.8f}'.format(*u))
    calc_koch(depth-1, u, t)
    print('{0:.8f} {1:.8f}'.format(*t))
    calc_koch(depth-1, t, p2)


if __name__ == '__main__':
    # ??????????????\???
    depth = int(input())

    # ??????
    p1 = (0.0, 0.0)
    p2 = (100.0, 0.0)

    print('{0:.8f} {1:.8f}'.format(*p1))
    result = calc_koch(depth, p1, p2)
    print('{0:.8f} {1:.8f}'.format(*p2))

Submission status: Wrong Answer

Solution code:
import math

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

    s = ((p1[0] * 2 + p2[0]) / 3, (p1[1] * 2 + p2[1]) / 3)
    t = ((p1[0] + p2[0] * 2) / 3, (p1[1] + p2[1] * 2) / 3)
    u = ((t[0] - s[0]) * math.cos(60) - (t[1] - s[1]) * math.sin(60) + s[0],
         (t[0] - s[0]) * math.sin(60) + (t[1] - s[1]) * math.cos(60) + s[1])

    kock(n-1, p1, s)
    print(*s)
    kock(n-1, s, u)
    print(*u)
    kock(n-1, u, t)
    print(*t)
    kock(n-1, t, p2)

n = int(input())
p1 = (0, 0)
p2 = (0, 100)
print(*p1)
kock(n, p1, p2)
print(*p2)

Submission status: Wrong Answer

Solution code:
import math

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

    s = ((p1[0] * 2 + p2[0]) / 3, (p1[1] * 2 + p2[1]) / 3)
    t = ((p1[0] + p2[0] * 2) / 3, (p1[1] + p2[1] * 2) / 3)
    u = ((t[0] - s[0]) * math.cos(60) - (t[1] - s[1]) * math.sin(60) + s[0],
         (t[0] - s[0]) * math.sin(60) + (t[1] - s[1]) * math.cos(60) + s[1])

    kock(n-1, p1, s)
    print(*s)
    kock(n-1, s, u)
    print(*u)
    kock(n-1, u, t)
    print(*t)
    kock(n-1, t, p2)

n = int(input())
p1 = (0.0, 0.0)
p2 = (0.0, 100.0)
print(*p1)
kock(n, p1, p2)
print(*p2)

Submission status: Wrong Answer

Solution code:
import math

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

    s = ((p1[0] * 2 + p2[0]) / 3, (p1[1] * 2 + p2[1]) / 3)
    t = ((p1[0] + p2[0] * 2) / 3, (p1[1] + p2[1] * 2) / 3)
    u = ((t[0] - s[0]) * math.cos(60) - (t[1] - s[1]) * math.sin(60) + s[0],
         (t[0] - s[0]) * math.sin(60) + (t[1] - s[1]) * math.cos(60) + s[1])

    kock(n-1, p1, s)
    print(*s)
    kock(n-1, s, u)
    print(*u)
    kock(n-1, u, t)
    print(*t)
    kock(n-1, t, p2)

n = int(input())
p1 = (0.0, 0.0)
p2 = (100.0, 0.0)
print(*p1)
kock(n, p1, p2)
print(*p2)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

def koch(n,x_0,y_0,x_1,y_1):
    if n == 0:
        return    
    x_m1 = x_0 + (x_1- x_0)/3
    y_m1 = y_0 + (y_1 -y_0)/3
    x_m2 = x_0 + (x_1- x_0)* 2/3
    y_m2 = y_0 + (y_1 -y_0) *2/3
    x_m =  (x_m2 - x_m1) * math.cos(math.pi/3) - (y_m2 - y_m1) * math.sin(math.pi/3) + x_m1
    y_m =  (x_m2 - x_m1) * math.sin(math.pi/3) + (y_m2 - y_m1) * math.cos(math.pi/3) + y_m1

    koch(n-1,0,0,x_m1,y_m1)
    print(x_m1,y_m1)
    koch(n-1,x_m1,y_m1,x_m,y_m)
    print(x_m,y_m)
    koch(n-1,x_m,y_m,x_m2,y_m2)
    print(x_m2,y_m2)
    koch(n-1,x_m2,y_m2,100,0)
    
print(0,0)
koch(n,0,0,100,0)
print(100,0)

Submission status: Wrong Answer

Solution code:
import sys
import math

def calc_pdr(pd):
	theta = math.pi / 3
	pdr_x = math.cos(theta) * pd[0] - math.sin(theta) * pd[1]
	pdr_y = math.sin(theta) * pd[0] - math.cos(theta) * pd[1]

	return [pdr_x, pdr_y]

def make_coch(l):
	num_points = len(l) 
	if num_points == 2:
		p0 = l[0]
		p1 = l[1]

		pd = [(x1 - x0) / 3 for (x1, x0) in zip(p1, p0)]
		pa = [x0 + xd for (x0, xd) in zip(p0, pd)]
		pc = [x0 + 2 * xd for (x0, xd) in zip(p0, pd)]
		pdr = calc_pdr(pd)

		pb = [xa + xdr for (xa, xdr) in zip(pa, pdr)]

		return [p0, pa, pb, pc, p1]
	else:
		l_ret = []
		
		for i in range(0, num_points - 1):
			nl = make_coch([l[i], l[i + 1]])
			l_ret += nl
		
		return l_ret
	
#fin = open("test.txt", "r")
fin = sys.stdin

n = int(fin.readline())

p0 = [0.0, 0.0]
p1 = [100.0, 0.0]	
l = [p0, p1]

for i in range(n):
	l = make_coch(l)

for p in l:
	print("{0:.5f} {1:.5f}".format(p[0], p[1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math


n = int(input())
p0 = (0, 0)
p1 = (100, 0)

def koch(depth, p0, p1):
    if depth == 0:
        return

    print(*p0)
    # s = 2/3 p0 + 1/3 p1
    sx = 2 / 3 * p0[0] + 1 / 3 * p1[0]
    sy = 2 / 3 * p0[1] + 1 / 3 * p1[1]
    s = (sx, sy)

    tx = 1 / 3 * p0[0] + 2 / 3 * p1[0]
    ty = 1 / 3 * p0[1] + 2 / 3 * p1[1]
    t = (tx, ty)

    theta = math.radians(60)
    ux = math.cos(theta) * (tx - sx) - math.sin(theta) * (ty - sy) + sx
    uy = math.sin(theta) * (tx - sx) + math.cos(theta) * (ty - sy) + sy
    u = (ux, uy)

    koch(depth - 1, p0, s)
    print(*s)
    koch(depth - 1, s, u)
    print(*u)
    koch(depth - 1, u, t)
    print(*t)
    koch(depth - 1, t, p1)


koch(n, p0, p1)
print(*p1)

Submission status: Wrong Answer

Solution code:
import math
def koch(d, p1, p2):
    if d == 0:
        return
    s = (2 * p1[0] + 1 * p2[0] / 3.0, 2 * p1[1] + 1 * p2[1] / 3.0)
    t = (1 * p1[0] + 2 * p2[0] / 3.0, 1 * p1[1] + 2 * p2[1] / 3.0)
    u= ( (t[0] - s[0])*math.cos(math.radians(60)) -(t[1] - s[1])*math.sin(math.radians(60)) +s[0],
         (t[0] - s[0])*math.sin(math.radians(60)) -(t[1] - s[1])*math.cos(math.radians(60)) +s[1] )


    koch(d-1, p1, s)
    print(*s)
    koch(d-1, s, u)
    print(*u)
    koch(d-1, u, t)
    print(*t)
    koch(d-1, t, p2)


i = int(input())
a = (0.0, 0.0)
b = (100.0, 0.0)
print(*a)
koch(1, a, b)
print(*b)

Submission status: Wrong Answer

Solution code:
import math
def koch(d, p1, p2):
    if d == 0:
        return
    s = ((2 * p1[0] + 1 * p2[0]) / 3.0, (2 * p1[1] + 1 * p2[1]) / 3.0)
    t = ((1 * p1[0] + 2 * p2[0]) / 3.0, (1 * p1[1] + 2 * p2[1]) / 3.0)
    u= ( (t[0] - s[0])*math.cos(math.radians(60)) -(t[1] - s[1])*math.sin(math.radians(60)) +s[0],
         (t[0] - s[0])*math.sin(math.radians(60)) -(t[1] - s[1])*math.cos(math.radians(60)) +s[1] )


    koch(d-1, p1, s)
    print(*s)
    koch(d-1, s, u)
    print(*u)
    koch(d-1, u, t)
    print(*t)
    koch(d-1, t, p2)


i = int(input())
a = (0.0, 0.0)
b = (100.0, 0.0)
print(*a)
koch(i, a, b)
print(*b)