Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at



実装はたくさんあって「FizzBuzz TensorFlow」でウェブ検索すればたくさん出てきます。最適化器で機械学習として解くのが多いけれどTensorFlowは「数値微分による最適化可能な実行可能な計算グラフを作成するフレームワーク」であり、かつ論理演算のオペレーションも文字列操作のオペレーションも備えているため素直に実装できます。



import tensorflow as tf

a = tf.Variable(0, name='counter')

with tf.control_dependencies([tf.assign_add(a, 1)]):
    b = tf.case({
        tf.equal(tf.mod(a, 15), 0): lambda: tf.constant("FizzBuzz"),
        tf.equal(tf.mod(a, 3), 0): lambda: tf.constant("Fizz"),
        tf.equal(tf.mod(a, 5), 0): lambda: tf.constant("Buzz"),
        }, default=lambda: tf.as_string(a))

sess = tf.Session()

for i in range(100):
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
Help us understand the problem. What are the problem?