Last active
December 20, 2022 21:44
-
-
Save jpwagner/07f7b57678d9c2ba51301c12cb293cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TribSequence(): | |
def __init__(self, a, b, c): | |
self.seq = [a, b, c] | |
def next_term(self): | |
self.seq += [self.seq[-1] + self.seq[-2] + self.seq[-3]] | |
def contains(self, num): | |
if num in self.seq: | |
return True | |
if self.seq[-1] > num: | |
return False | |
self.next_term() | |
return self.contains(num) | |
def smallest_seq_containing(num): | |
a,b,c = 0,0,0 | |
for i in range(1,int(num/2)): | |
for j in range(1,i): | |
for k in range(1,j): | |
t = TribSequence(a+k, b+j, c+i) | |
if t.contains(num): | |
return (a+k, b+j, c+i) | |
print(smallest_seq_containing(2023)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment