Last active
August 29, 2015 14:28
Reddit Daily Programmer Challenge 229 [Easy]
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
#https://www.reddit.com/r/dailyprogrammer/comments/3i99w8/20150824_challenge_229_easy_the_dottie_number/ | |
import math | |
import random | |
# 4 functions that are all pretty close in nature | |
def f_cos(x): | |
while x != math.cos(x): | |
x = math.cos(x) | |
print(x) | |
def f_tan(x): | |
while x != (x - math.tan(x)): | |
x = (x - math.tan(x)) | |
print(x) | |
def f_1x(x): | |
while x != (1 + 1 / x): | |
x = (1 + 1 / x) | |
print(x) | |
def log_map(x): | |
while float(x) != (4 * x * (1 - x)): | |
x = (4 * x * (1 - x)) | |
print(x) | |
# lets try making 1 function that can work all of this logic | |
def dottie(x, f): | |
while x != f(x): | |
x = f(x) | |
return x | |
print(dottie(2, lambda x: math.cos(x))) | |
print(dottie(2, lambda x: x - math.tan(x))) | |
print(dottie(2, lambda x: 1 + 1 / x)) | |
#print(dottie(random.random(), lambda x: (4 * x * (1 - x)))) | |
f_cos(7) | |
f_tan(2) | |
f_1x(7) | |
# log_map(random.random()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment