mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 06:46:18 -04:00
reorganize dir
Signed-off-by: Mia Steinkirch <mia.steinkirch@gmail.com>
This commit is contained in:
parent
1b6f705e7c
commit
a8e71c50db
276 changed files with 23954 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/python3
|
||||
# mari von steinkirch @2013
|
||||
# steinkirch at gmail
|
||||
|
||||
import math
|
||||
|
||||
def find_div(n):
|
||||
''' find the divisor of a given n'''
|
||||
set_div = {1, n}
|
||||
for i in range(2, int(math.sqrt(n))+ 1):
|
||||
if not n % i:
|
||||
set_div.add(i)
|
||||
set_div.add(n//i)
|
||||
l1 = list(set_div)
|
||||
return len(l1)
|
||||
|
||||
|
||||
def find_trian(l):
|
||||
''' find the lth trian number'''
|
||||
return sum(range(1, l+1))
|
||||
|
||||
|
||||
def highly_divisible_trian_num(d):
|
||||
thtriangle, n_div, count = 1, 0, 1
|
||||
while n_div < d:
|
||||
count += 1
|
||||
thtriangle += count
|
||||
n_div = find_div(thtriangle)
|
||||
return (thtriangle, count)
|
||||
|
||||
|
||||
def main():
|
||||
import time
|
||||
start = time.time()
|
||||
assert(highly_divisible_trian_num(6) == (28, 7))
|
||||
print(highly_divisible_trian_num(500))
|
||||
|
||||
elapsed = (time.time() - start)
|
||||
print('Tests Passed!\n It took %s seconds to run them.' % (elapsed))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue