-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2Sum.lisp
More file actions
43 lines (43 loc) · 879 Bytes
/
Copy path2Sum.lisp
File metadata and controls
43 lines (43 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(defun stolist (linea )
(setf l1 '())
(setf linea (concatenate 'string linea " "))
(setf j 0)
(setf n (length linea))
(dotimes (i n)
(when (string-equal (subseq linea i (+ i 1)) " ")
(setf l1 (cons (parse-integer(subseq linea j (+ i 1))) l1))
(setf j i )
)
)
(return-from stolist l1)
)
(defun sum2 (lista)
(setf c1 1)
(setf lista2 (reverse lista))
(loop for i in lista2
do
(setf c2 (length lista))
(loop for j in lista
do
(when (= i (* j -1))
(format t "~A ~A ~%" c1 c2 )
(return-from sum2 '(1))
)
(setf c2 (- c2 1))
)
(setf c1 (+ c1 1))
)
(format t "-1~%" )
(return-from sum2 '(-1))
)
(setf inF (open "in.txt"))
(setf l (read-line inF nil))
(setf l '())
(loop for i =(read-line inF nil)
while i do
(setf l (cons '(i) l ))
)
(close inF)
(loop for i in l
(sum2 (stolist(i) )
)