The program is run via the sequence of commands: (clear)(load "...")(reset)(assert spoj-non-interactive)(run). Don't make any assumptions about the strategy of inferrence (it is currently DFS, but subject to change to BFS at any moment).

(defrule readin
	?f<-(initial-fact)
=>
	(retract ?f)
	(assert (number (read)))
)
(defrule writeout
	?f<-(number ?n)(test (<> ?n 42))
=>
	(retract ?f)
	(printout t ?n crlf)
	(assert (initial-fact))
)