wxyz | f | g | h |
0000 | 0 | 0 | 0 |
0001 | 0 | 1 | 0 |
0010 | 0 | 1 | 0 |
0011 | 1 | 0 | 1 |
0100 | 0 | 1 | 0 |
0101 | 1 | 0 | 1 |
0110 | 1 | 0 | 1 |
0111 | 1 | 1 | 1 |
1000 | 0 | 0 | 1 |
1001 | 0 | 1 | 1 |
1010 | 0 | 1 | 1 |
1011 | 1 | 0 | 0 |
1100 | 0 | 1 | 0 |
1101 | 1 | 0 | 0 |
1110 | 1 | 0 | 0 |
1111 | 1 | 1 | 0 |
input add X store X add X add X Top, skipcond 800 jump Done output subt Decr jump Top Done, halt Decr, dec 3 X, dec 1 |
(defun f (N L) (cond ((not (listp L)) nil) ((not (integerp N)) nil) ((< N 0) nil) ((null L) nil) ((not (numberp (car L))) nil) ((= N 0) (car L)) (t (f (- N 1) (cdr L))))) |
f([], 0). f([H|T], Result) :- number(H), f(T, TR), R is H + TR, R = Result. f([_|T], Result) :- f(T,Result). |
Regular expression: ( 0 | (1 (0 1* 0)* 1)* )
State table:
Current state | Input | New state |
Start | 0 | Accept |
Start | 1 | B |
Accept | 0 | Accept |
Accept | 1 | B |
B | 0 | C |
B | 1 | Accept |
C | 0 | B |
C | 1 | C |
e.g. the result of getSmallerNums([13, 7, 7, 9, 11, 8], 9, R). would be R = [ 7, 7, 8 ]