Advertisement
Guest User

Ranking_matematikk.net

a guest
Feb 21st, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. from math import floor, ceil
  2.  
  3. b = 3
  4. def func(a, x):
  5.     return float(a*x**b)
  6.  
  7. def round_to(num, string='round', cutoff=0):
  8.     try:
  9.         1/float(cutoff)
  10.     except:
  11.         digits = len(str(int(floor(num))))
  12.         cutoff = 5**(max(digits-1,1))
  13.     if string == 'round':
  14.         return int(cutoff*round(num/float(cutoff)))
  15.     elif string == 'ceil':
  16.         return int(cutoff*ceil(num/float(cutoff)))
  17.     elif string == 'floor':
  18.         return int(cutoff*floor(num/float(cutoff)))
  19.  
  20. def R(a, N):
  21.     if N == 1:
  22.         return 0
  23.     return round_to(func(a, N+1))
  24.  
  25. def find_a(num):
  26.     return max(round_to(num, 'floor'), 3500)/float(26**b)
  27.  
  28. if __name__ == '__main__':
  29.  
  30.     # Apner en tekstfil med gjeldende grenser og navn
  31.     with open('grenser.txt') as f:
  32.         mylist = [tuple(map(str, i.rstrip('\n').split(' '))) for i in f]
  33.    
  34.    # Bestemmer verdien av a, hvis femteplass > 3500.
  35.     femte_plass = 3870
  36.     a = find_a(femte_plass)
  37.  
  38.     for i, elem in enumerate(mylist):
  39.         print elem[0], R(a, i+1)
  40.     print "Tittel", R(a, (i+1)+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement