Skip to content

Instantly share code, notes, and snippets.

@keiji
Last active July 3, 2018 02:22
Show Gist options
  • Select an option

  • Save keiji/c8fdc405f21d51426ceaa66a597e4de0 to your computer and use it in GitHub Desktop.

Select an option

Save keiji/c8fdc405f21d51426ceaa66a597e4de0 to your computer and use it in GitHub Desktop.
Twitterで流れていた問題のアレ
# https://twitter.com/kaityo256/status/904279527353749509
import tensorflow as tf
a = tf.Variable(0.1)
b = tf.Variable(0.2)
c = tf.Variable(0.3)
result = a / (b + c) + b / (c + a) + c / (a + b)
groundtruth = tf.constant(4.0)
loss = tf.squared_difference(result, groundtruth)
global_step = tf.Variable(0, trainable=False)
opt = tf.train.GradientDescentOptimizer(0.0001)
train_op = opt.minimize(loss, global_step=global_step)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
while True:
_, step, value, a_value, b_value, c_value = sess.run([train_op, global_step, result, a, b, c])
print('%d - a:%f, b:%f, c:%f, result:%f' % (step, a_value, b_value, c_value, value))
if value == 4.0:
break
@keiji
Copy link
Author

keiji commented Sep 4, 2017

115 - a:-0.006626, b:0.045163, c:0.142721, result:4.000000

@keiji
Copy link
Author

keiji commented Sep 4, 2017

自然数の解はないと思ったらちゃんとあった。

https://twitter.com/kaityo256/status/904279898507771905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment