Added new benches and will add the rest of them

This commit is contained in:
Sharjeel Khan
2022-11-08 22:49:43 -05:00
parent 7eb8465f64
commit a7248daca0
7 changed files with 127 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env newlisp
;;
;; fibonacci series
;; mostly from http://www.newlisp.org/syntax.cgi?benchmarks/fibo.newlisp.txt
;; modified slightly to match others
;;
(define (fib n)
(my-match (0 1)
(1 1)
(n (let (a (fib (- n 1))
b (fib (- n 2))
) (+ a b)))))
(define (my-match-helper x_sym cases i) (cond ((< i (- (length cases) 1)) (let (test__body_func (evaluate_case x_sym (cases i)))
(append (list (list (test__body_func 0) ((test__body_func 1) (cases (+ i 1))))) (my-match-helper x_sym cases (+ i 2)))))
(true '((true ("none matched"))))))
(macro (my-match X) X)
(constant 'my-match (lambda-macro (X) (expand (list let (list '__MATCH_SYM 'X) (cons cond (my-match-helper '__MATCH_SYM (args) 0))) 'X)))
(println (fib (integer (main-args 2))))
(exit)

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env newlisp
;;
;; fibonacci series
;; mostly from http://www.newlisp.org/syntax.cgi?benchmarks/fibo.newlisp.txt
;; modified slightly to match others
;;
(define (fib n)
(my-match (0 1)
(1 1)
(n (+ (fib (- n 1)) (fib (- n 2))))))
(define (my-match-helper x_sym cases i) (cond ((< i (- (length cases) 1)) (let (test__body_func (evaluate_case x_sym (cases i)))
(append (list (list (test__body_func 0) ((test__body_func 1) (cases (+ i 1))))) (my-match-helper x_sym cases (+ i 2)))))
(true '((true ("none matched"))))))
(macro (my-match X) X)
(constant 'my-match (lambda-macro (X) (expand (list let (list '__MATCH_SYM 'X) (cons cond (my-match-helper '__MATCH_SYM (args) 0))) 'X)))
(println (fib (integer (main-args 2))))
(exit)

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env newlisp
;;
;; fibonacci series
;; mostly from http://www.newlisp.org/syntax.cgi?benchmarks/fibo.newlisp.txt
;; modified slightly to match others
;;
(define (fib n)
(my-match (0 1)
(1 1)
(n (let (a (fib (- n 1))
b (fib (- n 2))
) (+ a b)))))
(define (my-match-helper x_sym cases i) (cond ((< i (- (length cases) 1)) (let (test__body_func (evaluate_case x_sym (cases i)))
(append (list (list (test__body_func 0) ((test__body_func 1) (cases (+ i 1))))) (my-match-helper x_sym cases (+ i 2)))))
(true '((true ("none matched"))))))
(define-macro (my-match x) (eval (list let (list '__MATCH_SYM x) (cons cond (my-match-helper '__MATCH_SYM (args) 0)))))
(println (fib (integer (main-args 2))))
(exit)

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env newlisp
;;
;; fibonacci series
;; mostly from http://www.newlisp.org/syntax.cgi?benchmarks/fibo.newlisp.txt
;; modified slightly to match others
;;
(define (fib n)
(my-match (0 1)
(1 1)
(n (+ (fib (- n 1)) (fib (- n 2))))))
(define (my-match-helper x_sym cases i) (cond ((< i (- (length cases) 1)) (let (test__body_func (evaluate_case x_sym (cases i)))
(append (list (list (test__body_func 0) ((test__body_func 1) (cases (+ i 1))))) (my-match-helper x_sym cases (+ i 2)))))
(true '((true ("none matched"))))))
(define-macro (my-match x) (eval (list let (list '__MATCH_SYM x) (cons cond (my-match-helper '__MATCH_SYM (args) 0)))))
(println (fib (integer (main-args 2))))
(exit)

View File

@@ -8,7 +8,7 @@ exec pil $0 $1
(de fib (N) (cond ((= 0 N) 1)
((= 1 N) 1)
(1 (let (A (fib (- N 1))
(T (let (A (fib (- N 1))
B (fib (- N 2))
) (+ A B)))))

View File

@@ -8,6 +8,6 @@ exec pil $0 $1
(de fib (n) (cond ((= 0 n) 1)
((= 1 n) 1)
(1 (+ (fib (- n 1)) (fib (- n 2))))))
(T (+ (fib (- n 1)) (fib (- n 2))))))
(bye (println (fib (car (str (opt))))))

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
#{
# Thanks to http://rosettacode.org/wiki/Multiline_shebang#PicoLisp
exec pil $0 $1
# }#
(de safe (Q D S) (let (C (car S))
(case C
(NIL T)
(T (and (<> Q C) (<> Q (+ C D)) (<> Q (- C D)) (safe Q (+ D 1) (cdr S)) ))
)
)
)
(de appendS (Q S X) (cond ((<= Q 0) X)
((safe Q 1 S) (appendS (- Q 1) S (cons (cons Q S) X)))
(T (appendS (- Q 1) S X) )
)
)
(de extendS (Q A X) (let (S (car X))
(case S
(NIL A)
(T (extendS Q (appendS Q S A) (cdr X)))
)
)
)
(de findS (N Q) (cond ((= 0 Q) (cons (cons NIL NIL) NIL))
(T (extendS N NIL (findS N (- Q 1))))))
(de nqueens (N) (length (findS N N)))
(bye (println (nqueens (car (str (opt))))))