• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Sep 17th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. r = open("skidesign.in", "r")
2. hillHeights = []
4. for k in range (1, len(vals)):
5.   hillHeights.append(int(vals[k]))
6. r.close()
7.
8. def hillIncrementer(hillHeights):
9.   tallestHill = 0
10.   smallestHill = 101
11.   totalCost = 1000000000
12.
13.   for x in hillHeights:
14.     if x > tallestHill:
15.       tallestHill = x
16.     elif x < smallestHill:
17.       smallestHill = x
18.
19.   for minimum in range (smallestHill, tallestHill - 17):
20.     cost = 0
21.     distance = minimum + 17
22.
23.     for hill in hillHeights:
24.       cost = cost + calculateCost(minimum, distance, hill)
25.     if (cost < totalCost):
26.         totalCost = cost
27.
29.
30. def calculateCost(minimum, distance, hill):
31.   cost = 0
32.
33.   if (hill > distance):
34.     val = distance - hill
35.     cost = val*val
36.   elif (hill < minimum):
37.     val = minimum - hill
38.     cost = val*val
39.   return cost
40.
41. k = open("skidesign.out", "w")
42. k.write(str(hillIncrementer(hillHeights)) + "\n")
43. k.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top