mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
readme e ristruttura
This commit is contained in:
parent
3ded8ee9a9
commit
1b4102cd46
10 changed files with 30 additions and 103 deletions
31
README.md
31
README.md
|
@ -1,3 +1,32 @@
|
||||||
# Buridan_donkey
|
# Buridan_donkey
|
||||||
Written in c++ and python, this program given some choices orders them in casual order.
|
Written in c++, c and python, this program given some choices orders them in casual order.
|
||||||
More info at: http://francescomecca.eu/index.php/archives/207
|
More info at: http://francescomecca.eu/index.php/archives/207
|
||||||
|
|
||||||
|
# C
|
||||||
|
|
||||||
|
The C version is the most complete. It makes a system call to get a random pool of numbers.
|
||||||
|
|
||||||
|
Compile including math library.
|
||||||
|
|
||||||
|
It supports cli arguments:
|
||||||
|
|
||||||
|
```
|
||||||
|
--urandom, -u: no arguments, uses /dev/urandom instead of /dev/random
|
||||||
|
--no-numbers, -n: no arguments, disable line numbers
|
||||||
|
```
|
||||||
|
|
||||||
|
# Example
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ls
|
||||||
|
|
||||||
|
asino.c asino.cpp asino.py README.md
|
||||||
|
|
||||||
|
$ ls | asino
|
||||||
|
|
||||||
|
1. asino.c
|
||||||
|
2. README.md
|
||||||
|
3. asino.py
|
||||||
|
4. asino.cpp
|
||||||
|
|
||||||
|
```
|
||||||
|
|
BIN
bin/asino
BIN
bin/asino
Binary file not shown.
Binary file not shown.
27
makefile
27
makefile
|
@ -1,27 +0,0 @@
|
||||||
ALL = src/asino.c
|
|
||||||
LOCPATH = ./bin
|
|
||||||
INSTALLPATH = /usr/local
|
|
||||||
LFLAGS = -lm
|
|
||||||
DEBFLAGS = -g -Wall -Wextra -pedantic
|
|
||||||
|
|
||||||
all:
|
|
||||||
mkdir -p $(LOCPATH)
|
|
||||||
gcc $(ALL) -o $(LOCPATH)/asino $(LFLAGS)
|
|
||||||
debug:
|
|
||||||
mkdir -p $(LOCPATH)/debug
|
|
||||||
gcc $(ALL) -o $(LOCPATH)/debug/asino_debug $(LFLAGS) $(DEBFLAGS)
|
|
||||||
asan:
|
|
||||||
gcc $(ALL) -o $(LOCPATH)/debug/asino_debug_asan $(LFLAGS) $(DEBFLAGS) -fsanitize=address
|
|
||||||
clean:
|
|
||||||
rm $(LOCPATH)/asino
|
|
||||||
rm $(LOCPATH)/debug/asino_debug
|
|
||||||
distclean:
|
|
||||||
rm -r $(LOCPATH)
|
|
||||||
install:
|
|
||||||
cp $(LOCPATH)/asino $(INSTALLPATH)/bin/asino
|
|
||||||
uninstall:
|
|
||||||
rm $(INSTALLPATH)/bin/asino
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
src/.asino.c.swp
BIN
src/.asino.c.swp
Binary file not shown.
|
@ -1,48 +0,0 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
import random
|
|
||||||
|
|
||||||
def parse_args ():
|
|
||||||
import argparse
|
|
||||||
parser = argparse.ArgumentParser ()
|
|
||||||
parser.add_argument ('-n', '--no-numbers', action = 'store_true', default = False,
|
|
||||||
help = 'do not display line numbers')
|
|
||||||
parser.add_argument ('choices', type = str, nargs= '*', default = [],
|
|
||||||
help = 'where the various choices belong')
|
|
||||||
parser.add_argument ('-l', '--limit', type = int, default = False,
|
|
||||||
help = 'display n lines')
|
|
||||||
return parser.parse_args ()
|
|
||||||
|
|
||||||
_cnt = -1
|
|
||||||
def enum ():
|
|
||||||
global _cnt
|
|
||||||
_cnt += 1
|
|
||||||
return (''.join ([str (_cnt), '. ']))
|
|
||||||
def null_string ():
|
|
||||||
return ''
|
|
||||||
|
|
||||||
def main ():
|
|
||||||
from sys import stdin
|
|
||||||
args = parse_args ()
|
|
||||||
|
|
||||||
if args.limit:
|
|
||||||
limit = args.limit - 2
|
|
||||||
if args.no_numbers:
|
|
||||||
fst = null_string
|
|
||||||
else:
|
|
||||||
fst = enum
|
|
||||||
|
|
||||||
if not stdin.isatty():
|
|
||||||
for line in stdin:
|
|
||||||
if line[-1] is '\n':
|
|
||||||
line = line[:-1]
|
|
||||||
args.choices.append(line)
|
|
||||||
|
|
||||||
argRange = len(args.choices)
|
|
||||||
for i in range (argRange):
|
|
||||||
print (''.join ([fst (), args.choices.pop(random.randrange(0, len(args.choices)))]))
|
|
||||||
if args.limit and i > limit:
|
|
||||||
exit ()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main ()
|
|
27
src/makefile
27
src/makefile
|
@ -1,27 +0,0 @@
|
||||||
ALL = asino.c
|
|
||||||
LOCPATH = ./bin
|
|
||||||
INSTALLPATH = /usr/local
|
|
||||||
LFLAGS = -lm
|
|
||||||
DEBFLAGS = -g -Wall -Wextra -pedantic
|
|
||||||
|
|
||||||
all:
|
|
||||||
mkdir -p $(LOCPATH)
|
|
||||||
gcc $(ALL) -o $(LOCPATH)/asino $(LFLAGS)
|
|
||||||
debug:
|
|
||||||
mkdir -p $(LOCPATH)/debug
|
|
||||||
gcc $(ALL) -o $(LOCPATH)/debug/asino_debug $(LFLAGS) $(DEBFLAGS)
|
|
||||||
asan:
|
|
||||||
gcc $(ALL) -o $(LOCPATH)/debug/asino_debug_asan $(LFLAGS) $(DEBFLAGS) -fsanitize=address
|
|
||||||
clean:
|
|
||||||
rm $(LOCPATH)/asino
|
|
||||||
rm $(LOCPATH)/debug/asino_debug
|
|
||||||
distclean:
|
|
||||||
rm -r $(LOCPATH)
|
|
||||||
install:
|
|
||||||
cp $(LOCPATH)/asino $(INSTALLPATH)/bin/asino
|
|
||||||
uninstall:
|
|
||||||
rm $(INSTALLPATH)/bin/asino
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue