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

Submission status: Wrong Answer

Solution code:
import math

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

  v = [(p2[0]-p1[0])/3, (p2[1]-p1[1])/3]
  s = [p1[0]+v[0], p1[1]+v[1]]
  t = [s[0]+v[0], s[1]+v[1]]

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

  a = math.sqrt((t[0]-s[0])**2+(t[1]-s[1])**2)
  h = 3**(1/2)*a/2
  u = [s[0]+(t[0]-s[0])/2+h*math.sin(theta), s[1]+(t[1]-s[1])/2+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([0, 0], [100, 0], n)

Submission status: Wrong Answer

Solution code:
import math

def main():
    n = input()

    p1 = [0., 0.]
    p2 = [100., 0.]
    a = [p1,p2]
    a = rec(a,n)

    for item in a:
        print item[0], item[1]

def rec(a,n):
    if n == 0:
        return a
    else:
        n -= 1
        b = []
        for i in range(len(a)-1):
            p1 = a[i]
            p2 = a[i+1]
            b += koch(p1,p2)
        b.append(a[-1])
        return rec(b,n)

def koch(p1,p2):
    s = [(p2[0]-p1[0])/3., (p2[1]-p1[1])/3.]
    t = [2.*(p2[0]-p1[0])/3., 2.*(p2[1]-p1[1])/3.]
    st = [t[0]-s[0],t[1]-s[1]]
    u = [s[0]+(st[0]-math.sqrt(3)*st[1])/2., s[1]+(math.sqrt(3)*st[0]+st[1])/2.]
    return [p1,s,u,t]
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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 == 0:
		points.append(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: Wrong Answer

Solution code:
import math
th = math.pi/3

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]
	s0t = [t[0]-s[0], t[1]-s[1]]
	s0u = [math.cos(th)*s0t[0] - math.sin(th)*s0t[1],
	       math.sin(th)*s0t[0] + math.cos(th)*s0t[1]]
	u = [s[0]+s0u[0], s[1]+s0u[1]]
	
	if n == 0:
		points.append(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)

Submission status: Wrong Answer

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])*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(n-1, p1, s)
    print(*s)
    koch(n-1, s , u)
    print(*u)
    koch(n-1, u ,t)
    print(*t)

p1=(0,0)
p2=(100,0)

print(*p1)
koch(2, p1, p2)
print(*p2)

Submission status: Wrong Answer

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])*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(n-1, p1, s)
    print(*s)
    koch(n-1, s , u)
    print(*u)
    koch(n-1, u ,t)
    print(*t)

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

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

Submission status: Wrong Answer

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

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

print("{0:.8f}".format(p1[0]), "{0:.8f}".format(p1[1]))
koch(n, p1, p2)
print("{0:.8f}".format(p2[0]), "{0:.8f}".format(p2[1]))

Submission status: Wrong Answer

Solution code:
import math as mt

def kock(n, p1, p2):
    if n == 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])*mt.cos(mt.radians(60))
        -(t[1]-s[1])*mt.sin(mt.radians(60)) + s[0],
         (t[0]-s[0])*mt.sin(mt.radians(60))
         +(t[1]-s[1])*mt.cos(mt.radians(60)) + s[1]]

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


if __name__ == '__main__':
    n = 2
    p1 = (0,0)
    p2 = (0,100)
    print("{0:.8f} {1:.8f}".format(p1[0],p1[1]))
    kock(n, p1, p2)
    print("{0:.8f} {1:.8f}".format(p2[0],p2[1]))

Submission status: Wrong Answer

Solution code:
import math as mt

def kock(n, p1, p2):
    if n == 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])*mt.cos(mt.radians(60))
        -(t[1]-s[1])*mt.sin(mt.radians(60)) + s[0],
         (t[0]-s[0])*mt.sin(mt.radians(60))
         +(t[1]-s[1])*mt.cos(mt.radians(60)) + s[1]]

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


if __name__ == '__main__':
    n = int(input())
    p1 = (0,0)
    p2 = (100,0)
    print("{0:.8f} {1:.8f}".format(p1[0],p1[1]))
    kock(n, p1, p2)
    print("{0:.8f} {1:.8f}".format(p2[0],p2[1]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
import math
r=math.radians(60)
cos_60=math.cos(r)
sin_60=math.sin(r)

n=int(input())
start_point=(0,0)
end_point=(100,0)

def koch_curve(num,p1,p2):
    if num==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
    
    vertex_x=(tx-sx)*cos_60 - (ty-sy)*sin_60 + sx
    vertex_y=(tx-sx)*sin_60 - (ty-sy)*cos_60 + sy
    
    koch_curve(num-1, p1, (sx,sy))
    print(sx,sy)
    koch_curve(num-1, (sx,sy), (vertex_x,vertex_y))
    
    print(vertex_x,vertex_y)
    koch_curve(num-1, (vertex_x,vertex_y), (tx,ty))
    
    print(tx,ty)
    koch_curve(num-1, (tx,ty), p2)
  

print(*start_point)
koch_curve(n, start_point, end_point)
print(*end_point)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
import math
r=math.radians(60)
cos_60=math.cos(r)
sin_60=math.sin(r)

n=int(input())
start_point=(0,0)
end_point=(100,0)

def koch_curve(num,p1,p2):
    if num==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
    
    vertex_x=(tx-sx)*cos_60 - (ty-sy)*sin_60 + sx
    vertex_y=(tx-sx)*sin_60 - (ty-sy)*cos_60 + sy
    
    koch_curve(num-1, p1, (sx,sy))
    print("{:8f} {:8f}".format(sx,sy))
    koch_curve(num-1, (sx,sy), (vertex_x,vertex_y))
    
    print("{:8f} {:8f}".format(vertex_x,vertex_y))
    koch_curve(num-1, (vertex_x,vertex_y), (tx,ty))
    
    print("{:8f} {:8f}".format(tx,ty))
    koch_curve(num-1, (tx,ty), p2)
  

print(*start_point)
koch_curve(n, start_point, end_point)
print(*end_point)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
import math
r=math.radians(60)
cos_60=math.cos(r)
sin_60=math.sin(r)

n=int(input())
start_point=(0,0)
end_point=(100,0)

def koch_curve(num,p1,p2):
    if num==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
    
    vertex_x=(tx-sx)*cos_60 - (ty-sy)*sin_60 + sx
    vertex_y=(tx-sx)*sin_60 - (ty-sy)*cos_60 + sy
    
    koch_curve(num-1, p1, (sx,sy))
    print("{:.8f} {:.8f}".format(sx,sy))
    koch_curve(num-1, (sx,sy), (vertex_x,vertex_y))
    
    print("{:.8f} {:.8f}".format(vertex_x,vertex_y))
    koch_curve(num-1, (vertex_x,vertex_y), (tx,ty))
    
    print("{:.8f} {:.8f}".format(tx,ty))
    koch_curve(num-1, (tx,ty), p2)
  

print(*start_point)
koch_curve(n, start_point, end_point)
print(*end_point)

Submission status: Wrong Answer

Solution code:
import math

pi = math.pi

n = int(input())
p1 = [0,0]
p2 = [100,0]

def koch(n, p1, p2):
    if n == 0:
        return
    s = [(2*p1[0]+p2[0])/3.0,(2*p1[1]+p2[1])/3.0]
    t = [(1*p1[0]+2*p2[0])/3.0,(p1[1]+2*p2[1])/3.0]
    u = [(t[0]-s[0])*math.cos(pi/3) - (t[1]-s[1])*math.sin(pi/3) + s[0], 
         (t[0]-s[0])*math.sin(pi/3) + (t[1]-s[1])*math.cos(pi/3) + s[1]]
         

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

koch(n, p1, p2)

Submission status: Wrong Answer

Solution code:
import math

pi = math.pi

n = int(input())
p1 = [0,0]
p2 = [100,0]

def koch(n, p1, p2):
    if n == 0:
        print(*p2)
        return
    s = [(2*p1[0]+p2[0])/3.0,(2*p1[1]+p2[1])/3.0]
    t = [(1*p1[0]+2*p2[0])/3.0,(p1[1]+2*p2[1])/3.0]
    u = [(t[0]-s[0])*math.cos(pi/3) - (t[1]-s[1])*math.sin(pi/3) + s[0], 
         (t[0]-s[0])*math.sin(pi/3) + (t[1]-s[1])*math.cos(pi/3) + s[1]]
         

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

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

Submission status: Wrong Answer

Solution code:
import math

def kock(n,p1x,p1y,p2x,p2y):
    if n==0:
        pass
    else:
        sx=(2*p1x+p2x)/3
        sy=(2*p1y+p2y)/3
        tx=(p1x+2*p2x)/3
        ty=(p1y+2*p2y)/3

        ux=(tx-sx)*math.cos(math.pi*1/3)-(ty-sy)*math.sin(math.pi*1/3)+sx
        uy=(tx-sx)*math.sin(math.pi*1/3)+(ty-sy)*math.cos(math.pi*1/3)+sy
        print(sx,ux)
        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)

n=int(input().strip())

print("0.0 0.0")
kock(n,0,0,100,0)
print("0.0 0.0")

Submission status: Wrong Answer

Solution code:


import math

def kock(n,p1x,p1y,p2x,p2y):
    if n==0:
        pass
    else:
        sx=(2*p1x+p2x)/3
        sy=(2*p1y+p2y)/3
        tx=(p1x+2*p2x)/3
        ty=(p1y+2*p2y)/3

        ux=(tx-sx)*math.cos(math.pi*1/3)-(ty-sy)*math.sin(math.pi*1/3)+sx
        uy=(tx-sx)*math.sin(math.pi*1/3)+(ty-sy)*math.cos(math.pi*1/3)+sy
        print(sx,ux)
        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)

n=int(input().strip())

zero=0.0
hundred=100.0
print(zero,zero)
kock(n,0,0,100,0)
print(hundred,zero)

Submission status: Wrong Answer

Solution code:
# coding=utf-8
import math


def cut_into_three(start: list, end: list) -> list:
    x1 = (2*start[0]+end[0])/3
    y1 = (2*start[1]+end[1])/3
    mid_point1 = [x1, y1]

    x2 = (start[0]+2*end[0])/3
    y2 = (start[1]+2*end[1])/3
    mid_point2 = [x2, y2]

    points_list = [start, mid_point1, mid_point2, end]
    return points_list


def equil_triangle(point1: list, point2: list) -> list:
    cos60 = math.cos(math.pi / 3)
    sin60 = math.sin(math.pi / 3)

    x = (point2[0] - point1[0])*cos60 - (point2[1]-point1[1])*sin60 + point1[0]
    y = (point2[0] - point1[0])*sin60 + (point2[1]-point1[1])*cos60 + point1[1]

    return [x, y]


def make_projection(start: list, end: list) -> list:
    points_list = cut_into_three(start, end)
    projection_point = equil_triangle(points_list[1], points_list[2])
    points_list.insert(2, projection_point)
    return points_list


def koch_curve(start: list, end: list, number: int) -> list:
    if number == 0:
        return [start, end]
    else:
        points_list = make_projection(start, end)
        list1 = koch_curve(points_list[0], points_list[1], number-1)
        list2 = koch_curve(points_list[1], points_list[2], number-1)
        list3 = koch_curve(points_list[2], points_list[3], number-1)
        list4 = koch_curve(points_list[3], points_list[4], number-1)
        new_points_list = list1 + list2[1:] + list3[1:] + list4[1:]
        return new_points_list


if __name__ == '__main__':
    n = int(input())
    p1 = [0, 0]
    p2 = [100, 0]
    fractal_points = koch_curve(p1, p2, n)
    print(fractal_points)

Submission status: Wrong Answer

Solution code:
import math
dig_six = math.radians(60)

def koch(d, p1, p2):
    if d == 0:
        return d
    #calc s, u, t from p1, p2
    s_x = (2*p1[0]+1 * p2[0]) / 3
    s_y = (2*p1[1]+1 * p2[1]) / 3
    s = (s_x, s_y)
    t_x = (1*p1[0]+2 * p2[0]) / 3
    t_y = (1*p1[1]+2 * p2[1]) / 3
    t = (t_x, t_y)
    u_x = (t_x - s_x)*math.cos(dig_six) - (t_y - s_y)*math.sin(dig_six) + s_x
    u_y = (t_x - s_x)*math.sin(dig_six) + (t_y - s_y)*math.cos(dig_six) + s_y
    u = (u_x, u_y)
    
    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)

if __name__ == '__main__':
    iterate = int(input())
    p1 = (0.0, 0.0)
    p2 = (100.0, 0.0)
    print (p1)
    koch(iterate, p1, p2)
    print (p2)

Submission status: Wrong Answer

Solution code:
import math
angle = math.pi / 3 # 60度

def koch(p1, p2, n):
    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(angle) - (t[1] - s[1]) * math.sin(angle) + s[0], \
        (t[0] - s[0]) * math.sin(angle) - (t[1] - s[1]) * math.cos(angle) + s[1])

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

n = int(input())
print(0.0, 0.0)
koch((0.0, 0.0), (100.0, 0.0), n)
print(100.0, 0.0)

Submission status: Wrong Answer

Solution code:
import math
angle = math.pi / 3 # 60度

def koch(p1, p2, n):
    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(angle) - (t[1] - s[1]) * math.sin(angle) + s[0], \
        (t[0] - s[0]) * math.sin(angle) - (t[1] - s[1]) * math.cos(angle) + s[1])

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

n = int(input())
print("{0:.8f} {1:.8f}".format(0.0, 0.0))
koch((0.0, 0.0), (100.0, 0.0), n)
print("{0:.8f} {1:.8f}".format(100.0, 0.0))

Submission status: Wrong Answer

Solution code:
import math


def koch(p1, p2, count):
    """Find points in koch curve after count times operations.

    >>> ps = koch((0, 0), (100, 0), 1)
    >>> cs = ["({:.4f}, {:.4f})".format(*p) for p in ps]
    >>> print("\\n".join(cs))
    (0.0000, 0.0000)
    (33.3333, 0.0000)
    (50.0000, 28.8675)
    (66.6667, 0.0000)
    (100.0000, 0.0000)
    """

    if count == 0:
        return []

    (x1, y1) = p1
    (x2, y2) = p2

    r, t = cartesian_to_polar(x2-x1, y2-y1)

    x3, y3 = polar_to_cartesian(r/3, t)
    p3 = (x3+x1, y3+y1)

    x4, y4 = polar_to_cartesian(r / (2*math.cos(math.pi/6)), t + math.pi/6)
    p4 = (x4+x1, y4+y1)

    x5, y5 = polar_to_cartesian(2*r/3, t)
    p5 = (x5+x1, y5+y1)

    return (koch(p1, p3, count-1)
            + [p3] + koch(p3, p4, count-1)
            + [p4] + koch(p4, p5, count-1)
            + [p5] + koch(p5, p2, count-1))


def polar_to_cartesian(x, y):
    return (x * math.cos(y), x * math.sin(y))


def cartesian_to_polar(x, y):
    return (math.sqrt(x**2 + y**2), math.atan2(y, x))


def run():
    n = int(input())
    p1 = (0.0, 0.0)
    p2 = (100.0, 0.0)
    ps = [p1] + koch(p1, p2, n) + [p2]

    print("\n".join(["({:.5f} {:.5f})".format(*p) for p in ps]))


if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
from math import sin, cos, pi

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

    x1, y1 = p1[0], p1[1]
    x2, y2 = p2[0], p2[1]

    lengthX = x2 - x1
    lengthY = y2 - y1

    trisectX = lengthX / 3.
    trisectY = lengthY / 3.

    sX = x1 + trisectX
    sY = y1 + trisectY
    tX = x2 - trisectX
    tY = y2 - trisectY

    theta = pi / 3.

    uX = (tX - sX) * cos(theta) - (tY - sY) * sin(theta) + sX
    uY = (tX - sX) * sin(theta) + (tY - sY) * cos(theta) + sY

    s = [sX, sY]
    t = [tX, tY]
    u = [uX, uY]

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

n = int(input())
p1 = [0,0]
p2 = [100, 0]
Koch(n, p1, p2)

Submission status: Wrong Answer

Solution code:
from math import sin, cos, pi

def Koch(n, p1, p2):
    if n == 0:
        print(*p1)
        print(*p2)
        return

    x1, y1 = p1[0], p1[1]
    x2, y2 = p2[0], p2[1]

    lengthX = x2 - x1
    lengthY = y2 - y1

    trisectX = lengthX / 3.
    trisectY = lengthY / 3.

    sX = x1 + trisectX
    sY = y1 + trisectY
    tX = x2 - trisectX
    tY = y2 - trisectY

    theta = pi / 3.

    uX = (tX - sX) * cos(theta) - (tY - sY) * sin(theta) + sX
    uY = (tX - sX) * sin(theta) + (tY - sY) * cos(theta) + sY

    s = [sX, sY]
    t = [tX, tY]
    u = [uX, uY]

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

n = int(input())
p1 = [0,0]
p2 = [100, 0]
Koch(n, p1, p2)

Submission status: Wrong Answer

Solution code:
from math import sin, cos, pi

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

    x1, y1 = p1[0], p1[1]
    x2, y2 = p2[0], p2[1]

    lengthX = x2 - x1
    lengthY = y2 - y1

    trisectX = lengthX / 3.
    trisectY = lengthY / 3.

    sX = x1 + trisectX
    sY = y1 + trisectY
    tX = x2 - trisectX
    tY = y2 - trisectY

    theta = pi / 3.

    uX = (tX - sX) * cos(theta) - (tY - sY) * sin(theta) + sX
    uY = (tX - sX) * sin(theta) + (tY - sY) * cos(theta) + sY

    s = [sX, sY]
    t = [tX, tY]
    u = [uX, uY]

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


n = int(input())
p1 = [0,0]
p2 = [100, 0]
print(*p1)
Koch(n, p1, p2)
print(*p2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Kannoudou
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168
 # 右中央

import math
import copy

def EqualParts(a,b):
    li = []
    s = [0,0]
    t = [0,0]
    s[0] = (2*a[0]+b[0])/3.0
    s[1] = (2*a[1]+b[1])/3.0
    t[0] = (a[0]+2*b[0])/3.0
    t[1] = (a[1]+2*b[1])/3.0
    li.append(s)
    li.append(t)
    return li

def triangle(a,b):
    u = [0,0]
    if a[1] == b[1]:
        u[0] = (a[0]+b[0])/2.0
        u[1] = (b[0]-a[0])/2.0*math.sqrt(3)
    else:
        li = EqualParts(a,b)
        if a[0] < b[0]:
            if a[1] > b[1]:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = b[1]
        else:
            if a[1] > b[1]:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = b[1]
    return u

def koch(n):
    if n == 0:
        return ([[0.0,0.0],[100.0, 0.0]])
    else:
        li = koch(n-1)
        answer = copy.copy(li)
        for i in range(len(li)-1):
            temp = EqualParts(li[i],li[i+1])
            s = temp[0]
            t = temp[1]
            u = triangle(s,t)
            answer.insert(3*i+1+i,s)
            answer.insert(3*i+2+i,u)
            answer.insert(3*i+3+i,t)
        return answer

n = int(input())
answer = koch(n)
for j in range(len(answer)):
    print(' '.join(map(str,answer[j])))

Submission status: Wrong Answer

Solution code:
import math
import copy

def EqualParts(a,b):
    li = []
    s = [0,0]
    t = [0,0]
    s[0] = (2*a[0]+b[0])/3.0
    s[1] = (2*a[1]+b[1])/3.0
    t[0] = (a[0]+2*b[0])/3.0
    t[1] = (a[1]+2*b[1])/3.0
    li.append(s)
    li.append(t)
    return li

def triangle(a,b):
    u = [0,0]
    if a[1] == b[1]:
        u[0] = (a[0]+b[0])/2.0
        u[1] = (b[0]-a[0])/2.0*math.sqrt(3)
    else:
        li = EqualParts(a,b)
        if a[0] < b[0]:
            if a[1] > b[1]:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = b[1]
        else:
            if a[1] > b[1]:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = b[1]
    return u

def koch(n):
    if n == 0:
        return ([[0.0,0.0],[100.0, 0.0]])
    else:
        li = koch(n-1)
        answer = copy.copy(li)
        for i in range(len(li)-1):
            temp = EqualParts(li[i],li[i+1])
            s = temp[0]
            t = temp[1]
            u = triangle(s,t)
            answer.insert(3*i+1+i,s)
            answer.insert(3*i+2+i,u)
            answer.insert(3*i+3+i,t)
        return answer

n = int(input())
answer = koch(n)
for j in range(len(answer)):
    print(' '.join(map(str,answer[j])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Kannoudou
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168
 # 右中央

import math
import copy

def EqualParts(a,b):
    li = []
    s = [0,0]
    t = [0,0]
    s[0] = (2*a[0]+b[0])/3.0
    s[1] = (2*a[1]+b[1])/3.0
    t[0] = (a[0]+2*b[0])/3.0
    t[1] = (a[1]+2*b[1])/3.0
    li.append(s)
    li.append(t)
    return li

def triangle(a,b):
    u = [0,0]
    if a[1] == b[1]:
        u[0] = (a[0]+b[0])/2.0
        u[1] = (b[0]-a[0])/2.0*math.sqrt(3)
    else:
        li = EqualParts(a,b)
        if a[0] < b[0]:
            if a[1] > b[1]:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = b[1]
        else:
            if a[1] > b[1]:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = li[0][1]
            else:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = li[1][1]
    return u

def koch(n):
    if n == 0:
        return ([[0.0,0.0],[100.0, 0.0]])
    else:
        li = koch(n-1)
        answer = copy.copy(li)
        for i in range(len(li)-1):
            temp = EqualParts(li[i],li[i+1])
            s = temp[0]
            t = temp[1]
            u = triangle(s,t)
            answer.insert(3*i+1+i,s)
            answer.insert(3*i+2+i,u)
            answer.insert(3*i+3+i,t)
        return answer

n = int(input())
answer = koch(n)
for j in range(len(answer)):
    print(' '.join(map(str,answer[j])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Kannoudou
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168
 # 右中央

import math
import copy

def EqualParts(a,b):
    li = []
    s = [0,0]
    t = [0,0]
    s[0] = (2*a[0]+b[0])/3.0
    s[1] = (2*a[1]+b[1])/3.0
    t[0] = (a[0]+2*b[0])/3.0
    t[1] = (a[1]+2*b[1])/3.0
    li.append(s)
    li.append(t)
    return li

def triangle(a,b):
    u = [0,0]
    if a[1] == b[1]:
        u[0] = (a[0]+b[0])/2.0
        u[1] = (b[0]-a[0])/2.0*math.sqrt(3)
    else:
        if a[0] < b[0]:
            if a[1] > b[1]:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = (2*a[1]+b[1])/3.0
            else:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = (a[1]+2*b[1])/3.0
        else:
            if a[1] > b[1]:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = (2*a[1]+b[1])/3.0
            else:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = (a[1]+2*b[1])/3.0
    return u

def koch(n):
    if n == 0:
        return ([[0.0,0.0],[100.0, 0.0]])
    else:
        li = koch(n-1)
        answer = copy.copy(li)
        for i in range(len(li)-1):
            temp = EqualParts(li[i],li[i+1])
            s = temp[0]
            t = temp[1]
            u = triangle(s,t)
            answer.insert(3*i+1+i,s)
            answer.insert(3*i+2+i,u)
            answer.insert(3*i+3+i,t)
        return answer

n = int(input())
answer = koch(n)
for j in range(len(answer)):
    print(' '.join(map(str,answer[j])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Kannoudou
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168
 # 右中央

import math
import copy

def EqualParts(a,b):
    li = []
    s = [0,0]
    t = [0,0]
    s[0] = (2*a[0]+b[0])/3.0
    s[1] = (2*a[1]+b[1])/3.0
    t[0] = (a[0]+2*b[0])/3.0
    t[1] = (a[1]+2*b[1])/3.0
    li.append(s)
    li.append(t)
    return li

def triangle(a,b):
    u = [0,0]
    if a[1] == b[1]:
        u[0] = (a[0]+b[0])/2.0
        u[1] = (b[0]-a[0])/2.0*math.sqrt(3)
    else:
        if a[0] < b[0]:
            if a[1] > b[1]:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = b[1]
        else:
            if a[1] > b[1]:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = b[1]
    return u

def koch(n):
    if n == 0:
        return ([[0.0,0.0],[100.0, 0.0]])
    else:
        li = koch(n-1)
        answer = copy.copy(li)
        for i in range(len(li)-1):
            temp = EqualParts(li[i],li[i+1])
            s = temp[0]
            t = temp[1]
            u = triangle(s,t)
            answer.insert(3*i+1+i,s)
            answer.insert(3*i+2+i,u)
            answer.insert(3*i+3+i,t)
        return answer

n = int(input())
answer = koch(n)
for j in range(len(answer)):
    print(' '.join(map(str,answer[j])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 # 宇都宮涼
 # J5-170029
 # Kannoudou
 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168
 # 右中央

import math
import copy

def EqualParts(a,b):
    li = []
    s = [0,0]
    t = [0,0]
    s[0] = (2*a[0]+b[0])/3.0
    s[1] = (2*a[1]+b[1])/3.0
    t[0] = (a[0]+2*b[0])/3.0
    t[1] = (a[1]+2*b[1])/3.0
    li.append(s)
    li.append(t)
    return li

def triangle(a,b):
    u = [0,0]
    if a[1] == b[1]:
        u[0] = (a[0]+b[0])/2.0
        u[1] = (b[0]-a[0])/2.0*math.sqrt(3)
    else:
        if a[0] < b[0]:
            if a[1] > b[1]:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = b[1]
        else:
            if a[1] > b[1]:
                u[0] = a[0]-(b[0]-a[0])
                u[1] = a[1]
            else:
                u[0] = b[0]+(b[0]-a[0])
                u[1] = a[1]
    return u

def koch(n):
    if n == 0:
        return ([[0.0,0.0],[100.0, 0.0]])
    else:
        li = koch(n-1)
        answer = copy.copy(li)
        for i in range(len(li)-1):
            temp = EqualParts(li[i],li[i+1])
            s = temp[0]
            t = temp[1]
            u = triangle(s,t)
            answer.insert(3*i+1+i,s)
            answer.insert(3*i+2+i,u)
            answer.insert(3*i+3+i,t)
        return answer

n = int(input())
answer = koch(n)
for j in range(len(answer)):
    print(' '.join(map(str,answer[j])))