-
Notifications
You must be signed in to change notification settings - Fork 0
/
assorted.py
55 lines (47 loc) · 936 Bytes
/
assorted.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
Assorted Helper Functions
@author: dsisson
"""
def rotate(n):
"""
Takes the last digit of a number and moves it to the front
"""
if(n<10):
return n
n = str(n)
n = n[-1] + n[:-1]
n = int(n)
return n
def gen_triangle():
"""
Generator for triangular numbers
"""
n = 1
while True:
yield int((n)*(n+1)/2)
n += 1
def gen_pentagon():
"""
Generator for pentagonal numbers
"""
n = 1
while True:
yield int((n)*((3*n)-1)/2)
n += 1
def gen_hexagon():
"""
Generator for hexagonal numbers
"""
n = 1
while True:
yield int((n)*((2*n)-1))
n += 1
def gen_dblSqr():
"""
Generator for double the squares of positive integers
"""
n = 1
while True:
yield 2*n*n
n += 1