From e5ce286c632ede86640da881bad93e9f7d490e07 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Mon, 2 Mar 2015 21:55:41 +0100 Subject: [PATCH] NL file format with .nl extension --- lib/linguist/languages.yml | 7 ++++ samples/NL/assign0.nl | 84 ++++++++++++++++++++++++++++++++++++++ samples/NewLisp/queens.nl | 49 ++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 samples/NL/assign0.nl create mode 100644 samples/NewLisp/queens.nl diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 70d52869..65f012c3 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1923,6 +1923,13 @@ Myghty: tm_scope: none ace_mode: text +NL: + type: data + extensions: + - .nl + tm_scope: none + ace_mode: text + NSIS: type: programming extensions: diff --git a/samples/NL/assign0.nl b/samples/NL/assign0.nl new file mode 100644 index 00000000..9f1c58cf --- /dev/null +++ b/samples/NL/assign0.nl @@ -0,0 +1,84 @@ +g3 0 1 0 # problem assign0 + 9 6 1 0 6 # vars, constraints, objectives, ranges, eqns + 0 0 # nonlinear constraints, objectives + 0 0 # network constraints: nonlinear, linear + 0 0 0 # nonlinear vars in constraints, objectives, both + 0 0 0 1 # linear network variables; functions; arith, flags + 9 0 0 0 0 # discrete variables: binary, integer, nonlinear (b,c,o) + 18 9 # nonzeros in Jacobian, gradients + 0 0 # max name lengths: constraints, variables + 0 0 0 0 0 # common exprs: b,c,o,c1,o1 +C0 +n0 +C1 +n0 +C2 +n0 +C3 +n0 +C4 +n0 +C5 +n0 +O0 0 +n0 +r +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +b +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +k8 +2 +4 +6 +8 +10 +12 +14 +16 +J0 3 +0 1 +1 1 +2 1 +J1 3 +3 1 +4 1 +5 1 +J2 3 +6 1 +7 1 +8 1 +J3 3 +0 1 +3 1 +6 1 +J4 3 +1 1 +4 1 +7 1 +J5 3 +2 1 +5 1 +8 1 +G0 9 +0 1 +1 3 +2 3 +3 2 +4 3 +5 3 +6 3 +7 3 +8 2 diff --git a/samples/NewLisp/queens.nl b/samples/NewLisp/queens.nl new file mode 100644 index 00000000..61c04992 --- /dev/null +++ b/samples/NewLisp/queens.nl @@ -0,0 +1,49 @@ +#!/usr/bin/env newlisp + +(constant 'NUM 8) + +(define (intersects? q1 q2) + (or + (= (q1 0) (q2 0)) + (= (q1 1) (q2 1)) + (= (abs (- (q1 0) (q2 0))) (abs (- (q1 1) (q2 1)))))) + +(define (variant? alist) + (set 'logic nil) + (cond + ((= (length alist) 1) true) + ((> (length alist) 1) + (while (> (length alist) 1) + (set 'q (pop alist -1)) + (dolist (el alist) + (push + (intersects? + (list q (inc (length alist))) + (list el (+ 1 $idx))) + logic -1))) + (not (apply or logic))))) + +(define (fork-by-line alist) + (let (res '()) + (dolist (i (sequence 1 NUM)) + (set 'tmp alist) + (push i tmp -1) + (setf res (push tmp res -1))) + res)) + +(define (find-variants num) + (let (res '()) + (cond + ((< num 1) + (begin (println "num < 1") (exit))) + ((= num 1) + (dolist (i (sequence 1 NUM)) (push (list i) res -1))) + ((> num 1) + (dolist (v (find-variants (dec num))) + (set 'passed (filter variant? (fork-by-line v))) + (if (not (empty? passed)) (extend res passed))))) + res)) + +(set 'solutions (find-variants NUM)) +(println (length solutions)) +;;(exit) \ No newline at end of file