The Buridan’s donkey is an illustration of a paradox regarding the philosophy of moral determinism and free will.
The paradox shows an hypothetical situation in which a donkey searching for food is caught in the middle of two equally appealing stacks of hay located at the same distance from the donkey. Because the donkey has no real reason to choose one over the other he dies of starvation.(https://en.wikipedia.org/wiki/Buridan's_ass)I have decided to write a cli program that chooses for me when I can’t make up my mind. The program is written in C++ and when invoked along with two or more arguments it puts them in a vector and then changes the order randomly. .. code:: c #include
One of the challenges was to read from stdin instead of arguments when the program is piped after another program in the shell:.. code:: sh ls /media/my_movies/ | buridan So I have used poll() that checks for a specified amount of time if the selected device (/dev/stdin in my case) can perform I/O operations; in my code: .. code:: bash poll (&stdin_poll, 1, 0) I selected the POLLIN as event so poll() only checks if there is data to read, 1 as the number of items in the fds array, 0 milliseconds of timeout because when the program is invoked /dev/stdin may already contain input. The program should be compiled this way: .. code:: bash g++ -std=c++11 ./program.cpp -o output You are free to reuse this little piece of code as you wish. EDIT: 02-04-2016 The original idea for the Buridan's donkey came from my mentor [Simone Basso](https://twitter.com/bassosimone) who wrote the original one in haskell.