25
loading...
This website collects cookies to deliver better user experience
$s
containing mathematical expression.+ - * ()
.eval
or qx
to parse the string. Maybe that is what is expected. That's probably what I would have done in the real world™. I was very tempted to see other peoples results before submitting my own, but I never do that, and I'm not about to start now :)$ ./ch-1.pl "20 + 10 - 5"
25
$ ./ch-1.pl "(20 + 10 - 5) * 2"
50
$n
.i
that counts from one to √n
. If n % i
is 0, we have a possible combination for a/b or c/d. I then compare this value to any previous values. If they have a absolute different of one, then I print 1. If we don't find any possible a/b/c/d combinations, then I print 0. $ ./ch-2.py 24
1
$ ./ch-2.py 12
1
$ ./ch-2.py 6
0