Skip to content

Instantly share code, notes, and snippets.

@tangingw
Created July 20, 2017 08:20
Show Gist options
  • Save tangingw/50575a38024215c0e38a1918040028af to your computer and use it in GitHub Desktop.
Save tangingw/50575a38024215c0e38a1918040028af to your computer and use it in GitHub Desktop.
Algorithms for a tricky math problems
"""Synosis:
This is the algorithm that address the
following trick math question:
1 + 4 = 5
2 + 5 = 12
3 + 6 = 21
8 + 11 = ?
However this algorithm can also find the solution for such
132 + 135 = ???
"""
def counting(i, max_i):
result = 0
while i < max_i:
result += 2*i + 3
i +=1
return result
"""Synosis:
This is the algorithm that address the
following trick math question:
1 + 4 = 5
2 + 5 = 12
3 + 6 = 21
8 + 11 = ?
However this algorithm can find the solution for such
132 + 135 = ???
"""
def Count(i, max_i):
result = 0
for j in range(i, max_i):
result += 2*j + 3
return result
if __name__ == '__main__':
print Count(1, 132)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment