mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
first
This commit is contained in:
commit
5d690a73c1
3 changed files with 68 additions and 0 deletions
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Buridan_donkey
|
||||||
|
Written in c++ and python, this program given some choices orders them in casual order.
|
||||||
|
More info at: http://francescomecca.eu/index.php/archives/207
|
51
asino.cpp
Normal file
51
asino.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <random>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/poll.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct pollfd stdin_poll = {
|
||||||
|
.fd = fileno (stdin), .events = POLLIN
|
||||||
|
};
|
||||||
|
|
||||||
|
void read_from_piped_input (vector<string>& lst)
|
||||||
|
{
|
||||||
|
string x;
|
||||||
|
while (getline (cin, x)) {
|
||||||
|
lst.push_back (x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void read_from_arguments (const int& argc, char* argv[], vector<string>& lst)
|
||||||
|
{
|
||||||
|
if (argc == 1) {
|
||||||
|
cout << "Usage: asino [string] [string] ..." << endl;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
for (vector<string>::size_type i = 1; i < argc; ++i) {
|
||||||
|
lst.push_back (argv[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (int argc, char* argv[])
|
||||||
|
{
|
||||||
|
vector<string> lst;
|
||||||
|
int poll_ret = poll (&stdin_poll, 1, 0);
|
||||||
|
if (poll_ret > 0) {
|
||||||
|
read_from_piped_input (lst);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
read_from_arguments (argc, argv, lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
random_device rd;
|
||||||
|
mt19937 m(rd());
|
||||||
|
shuffle (lst.begin (), lst.end (), m);
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
for (vector<string>::iterator it = lst.begin (); it != lst.end (); ++it) {
|
||||||
|
cout << i++ << ". " << *it << endl;
|
||||||
|
}
|
||||||
|
}
|
14
asino.py
Normal file
14
asino.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import random, sys
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = list()
|
||||||
|
if not sys.stdin.isatty():
|
||||||
|
for line in sys.stdin:
|
||||||
|
if line[-1] is '\n':
|
||||||
|
line = line[:-1]
|
||||||
|
args.append(line)
|
||||||
|
else:
|
||||||
|
args = sys.argv[1:]
|
||||||
|
argRange = len(args)
|
||||||
|
for i in range(argRange):
|
||||||
|
print(str(i+1) + '.', args.pop(random.randrange(0, len(args))))
|
Loading…
Reference in a new issue