{ "cells": [ { "cell_type": "raw", "id": "99d5db9e", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. _interactive-programs:\n", "\n", "Interactive Programs\n", "====================\n", "\n", "We define an interactive Cicada program as one that prompts a human for secret input to be used in a computation. Because handling secret interactive input can be tricky, Cicada includes the :func:`cicada.interactive.secret_input` function, which prompts one player for input from a console, which could then be secret-shared with the group. You can use it for simple demos and as a starting-point for more sophisticated interaction. Here are some examples:\n", "\n", ".. tip::\n", "\n", " These programs can't be run in a notebook, they need to be run in separate windows\n", " using the :ref:`cicada` command ... see :ref:`running-programs` for some helpful examples of\n", " how to run interactive programs." ] }, { "cell_type": "raw", "id": "66c0fe98", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Here's a minimal program that prompts player 0 for a secret. Note that the startup timeout for the communicator has been increased to five minutes (300 seconds) to allow enough time to manually start all of the player processes:\n", "\n", ".. literalinclude:: ../../examples/interactive-input.py\n", " :language: python\n", " :lines: 17-" ] }, { "cell_type": "raw", "id": "62543a83", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "In this example, every player provides a secret, and the group computes the sum:\n", "\n", ".. literalinclude:: ../../examples/interactive-sum.py\n", " :language: python\n", " :lines: 17-" ] }, { "cell_type": "raw", "id": "ab3672ea", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Finally, the following is an interactive version of :ref:`the millionaire's dilemma` ... every player provides a secret, and the group determines which person entered the largest value:\n", "\n", ".. literalinclude:: ../../examples/interactive-millionaires.py\n", " :language: python\n", " :lines: 17-" ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }