Since in
is a string you read from standard in, you need to convert in
to a number first before the subtraction. Try this:
(defn parse-int [s]
(Integer. (re-find #"\d+" s )))
(- nimBoard (parse-int in))
Вопрос
I am trying to make a very simple Nim game that probably isn't even considered a proper implementation of Nim, but I am only starting Clojure. Not sure why this subtraction on line four doesn't work...
1. (def nimBoard 10)
2. (println "There are" nimBoard "objects left")
3. (def in (read-line))
4. (- nimBoard in)
I can't seem to come up with a solid algorithm for asking the user if they want to remove one or two "objects" from the board until it is empty. I am coming from Java, but loops in this language just confuse me a lot. I know what I am trying to make isn't exactly the Game of Nim, but it is for practice.
I would appreciate any help:)
Решение
Since in
is a string you read from standard in, you need to convert in
to a number first before the subtraction. Try this:
(defn parse-int [s]
(Integer. (re-find #"\d+" s )))
(- nimBoard (parse-int in))