diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-08-28 20:44:20 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-08-28 20:44:20 +0900 |
| commit | baa27f2adf0ad741add152bcbca6ffbd312ef066 (patch) | |
| tree | d4a345ec3cf0bcaccf1ac293cd6ad50802bf9224 /comparison/Python | |
| parent | e50f2cf8ccab628d0cc90823389355242a23a28a (diff) | |
| parent | b850b9d9e64c12a927bfc2692b4134b23ef79be5 (diff) | |
| download | inpla-baa27f2adf0ad741add152bcbca6ffbd312ef066.tar.gz inpla-baa27f2adf0ad741add152bcbca6ffbd312ef066.zip | |
Merge branch 'develop'
Diffstat (limited to 'comparison/Python')
| -rw-r--r-- | comparison/Python/Makefile | 2 | ||||
| -rw-r--r-- | comparison/Python/fib-38.py | 8 | ||||
| -rw-r--r-- | comparison/Python/nqueen-12.py | 27 |
3 files changed, 36 insertions, 1 deletions
diff --git a/comparison/Python/Makefile b/comparison/Python/Makefile index c77d677..5dd95fd 100644 --- a/comparison/Python/Makefile +++ b/comparison/Python/Makefile @@ -1,5 +1,5 @@ COMMAND = python3 -TARGET = dummy.py ack3-11.py fib38.py bsort-20000.py isort-20000.py qsort-260000.py msort-260000.py +TARGET = dummy.py nqueen-12.py ack3-11.py fib-38.py bsort-20000.py isort-20000.py qsort-260000.py msort-260000.py BENCHMARK = bash ../tools/sptest_scripts.sh LOG = log.txt diff --git a/comparison/Python/fib-38.py b/comparison/Python/fib-38.py new file mode 100644 index 0000000..efa5380 --- /dev/null +++ b/comparison/Python/fib-38.py @@ -0,0 +1,8 @@ +def fib(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fib(n-1) + fib(n-2) +print(fib(38)) diff --git a/comparison/Python/nqueen-12.py b/comparison/Python/nqueen-12.py new file mode 100644 index 0000000..494131f --- /dev/null +++ b/comparison/Python/nqueen-12.py @@ -0,0 +1,27 @@ +def threat(k, m, alist): + if alist == []: + return False + else: + x = alist[0] + if (k == x-m) or (k == m-x): + return True + else: + return threat(k+1, m, alist[1:]) + +def queen1(m, b, n): + if m == 0: + return [] + else: + if (m in b) or threat(1, m, b): + return queen1(m-1, b, n) + elif len(b) == n-1: + return [[m]+b] + (queen1(m-1, b, n)) + else: + return queen1(n, [m]+b, n) + (queen1(m-1, b, n)) + + +def queen(n): + return queen1(n,[],n) + +n=12 +print(len(queen(12))) |
