Commit 4a897878 authored by Mark Daoust's avatar Mark Daoust
Browse files

Fix FizzBuzz

parent c3e61cb5
......@@ -365,24 +365,26 @@
"cell_type": "code",
"source": [
"@autograph.convert()\n",
"def fizzbuzz(num):\n",
" if num % 3 == 0 and num % 5 == 0:\n",
" return 'FizzBuzz'\n",
" elif num % 3 == 0:\n",
" return 'Fizz'\n",
" elif num % 5 == 0:\n",
" return 'Buzz'\n",
" else:\n",
" return tf.as_string(num)\n",
"def fizzbuzz(i, n):\n",
" while i < n:\n",
" msg = ''\n",
" if i % 3 == 0:\n",
" msg += 'Fizz'\n",
" if i % 5 == 0:\n",
" msg += 'Buzz'\n",
" if msg == '':\n",
" msg = tf.as_string(i)\n",
" print(msg)\n",
" i += 1\n",
" return i\n",
"\n",
"with tf.Graph().as_default():\n",
" final_i = fizzbuzz(tf.constant(10), tf.constant(16))\n",
" # The result works like a regular op: takes tensors in, returns tensors.\n",
" # You can inspect the graph using tf.get_default_graph().as_graph_def()\n",
" num = tf.placeholder(tf.int32)\n",
" result = fizzbuzz(num)\n",
" with tf.Session() as sess:\n",
" for n in range(10,16):\n",
" print(sess.run(result, feed_dict={num:n}))"
" sess.run(final_i)\n",
"\n"
],
"execution_count": 0,
"outputs": []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment