53
loading...
This website collects cookies to deliver better user experience
$a
and $b
.value
, which is a decimal number. I make a check that this value contains only ones and zeros.__add__
method which overloads addition operator that adds two BinaryDecimal values together. Python does make a distinction between integers and strings so there will be no short cuts to be had :)carry
value and add them up. If the result is two or 3, I set carry
to be one. If the result is one or 3, I add the appropriate value to the result
variable. I then divide both numbers by ten and continue until we have exhausted both numbers and the carry value.my
, dollar signs, semi-colons and brackets does make me appreciate Python. The only major change is that you use the overload
module to overload operators, and we use package
instead of class
.$ ./ch-1.py 11 1
100
$ ./ch-1.py 101 1
110
$ ./ch-1.py 100 11
111
$i
, $j
and $k
.$k
th element in the sorted multiplication table of $i
and $j
.$k
$i
using the variable $m
$k
items, then the result of the last value divided by $m
is the maximum.$k
and $j
3) Push to the array the product of these numbers multiplied by $m
4) Sort the array and trim it.$ ./ch-2.py 2 3 4
3
$ ./ch-2.py 3 3 6
4
$ ./ch-2.pl 2 3 4
3
$ ./ch-2.pl 3 3 6
4