Really embarrassing in two ways:
- Could not remove my previous post. :-)
- I should have tried to create such a big number (at least after
reading all the answers here) before posting... It is possible to
crate a 5 digit big integer.
PS: Watch out though. The aim of the problem is to add up t
Looks like you are doing the 13th Project Euler problem. That means
you have exactly one hundred 50 digit numbers. I am new to Clojure but
AFAIK you wont be able to handle a 5000 digit number in it. You have
to find another way. There is at least one... ;-)
--Feka
On Mar 25, 11:40 pm, Glen Rubin
> You want (java.math.BigInteger. "2342343..."). java.lang.Integer is
> limited to 2^31-1.
Clojure has a "bigint" function, so (bigint (apply str (re-seq
#"[0-9]+" big-num-str))) will work as well.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To
In those hills yonder in the lands of Common Lisp, it's usually
considered good practice to blast the entire read table save for what
you need when you deal with untrusted data. Barring that, a better
option might be a more modular reader: read-number, read-symbol, etc.
Clojure doesn't have a us
In those hills yonder in the lands of Common Lisp, it's usually
considered good practice to blast the entire read table save for what
you need when you deal with untrusted data. Barring that, a better
option might be a more modular reader: read-number, read-symbol, etc.
-Per
On Fri, Mar 26, 2010
Another unadvertised function that is useful to be aware of is
clojure.lang.Numbers/reduce which will simplify a number to its most simple
type. I often find that I want to use some BigInteger function, but then it
is important to turn it back into a "typical Clojure number" at the end.
For examp
Of course, it might also pose a bit of a security threat:
user> (read-string "#=(println \"I OWN YOU NOW!\")")
I OWN YOU NOW!
nil
:)
user=> (binding [*read-eval* false]
(read-string "#=(println \"I OWN YOU NOW!\")"))
java.lang.RuntimeException: java.lang.Exception: EvalReader not
allowed w
Though it might not be the best option here, the Clojure reader is
always ready to serve:
user> (type (read-string "123"))
java.lang.Integer
user> (type (read-string "123123123123123"))
java.lang.Long
user> (type (read-string "123123123123123123123123123123123123"))
java.math.BigInteger
Of course
Glen,
You want (java.math.BigInteger. "2342343..."). java.lang.Integer is
limited to 2^31-1.
- Chas
On Mar 25, 2010, at 6:40 PM, Glen Rubin wrote:
I am trying to convert a long string of numbers to a number, but get a
java.lang.numberformatexception
My long string of numbers has new lin
I am trying to convert a long string of numbers to a number, but get a
java.lang.numberformatexception
My long string of numbers has new line characters in it, so I am
filtering out the newline characters before converting it back to a
string. Then I try to use Integer. on it but get the above e
10 matches
Mail list logo