# 使用ASCII艺术显示长乘法

12

## 挑战

``````14, 11
``````

``````     14
x11
_____
14
14
______
154
``````

``````-7, 20
``````

``````     -7
x20
_____
00
14
_____
-140
``````

3

## Perl，108个字符

``````(\$x,\$y)=<>=~/[-\d]+/g;printf"%7s
",\$_ for\$x,x.\$y,"-"x7,(map{abs(\$x*\$_).\$"x\$i++}reverse\$y=~/\d/g),"-"x7,\$x*\$y
``````

``````sub P{sprintf"%*d",@_}
(\$x,\$y)=<>=~/[^,]+/g;\$,=\$/;
print P(7,\$x),"  x".P(4,\$y),"-"x7,(map{P 7-\$i++,abs\$_*\$x}reverse\$y=~/\d/g),
"-"x7,P 7,\$x*\$y
``````

/ me鞠躬...我没有看到将地图包括在printf部分中的可能性。而`\$y=~/\d/g`招很聪明
Orabîg

5

# 数学213 217 197 193 186 184 193 184 177

``````a_~g~b_ :=
With[{e = IntegerDigits@b}, Column[Flatten@{a, UnderBar["x " <> IntegerString[b]],
Table[Row @@ {PadRight[{a Reverse[e][[i]]}, i, " "]}, {i, Length@e}], OverBar[a b]},
Alignment -> Right]]
``````

``````g[845, 921]
``````

David Zhang

DavidC 2014年

ɐɔıʇǝɥʇuʎs

DavidC 2014年

1

Python，174170

``````a,b=input();r,s=str(a),str(b);h=len(r+s)*'-';print'\n'.join(["%9s\n%9s\n%9s"%(r,'x'+s,h)]+["%%%ii"%(9-i)%(int(d)%10*a)for i,d in enumerate(s[::-1])]+["%9s\n%9i"%(h,a*b)])
``````

``````     1234
x5678
--------
9872
8638
7404
6170
--------
7006652
``````

beary605

1

Python，145，另一个答案，输出有些不同。

``````a,b=input();h=6*'-';print'\n'.join(["%6i\nx%5i\n%s"%(a,b,h)]+["%%%ii"%(6-i)%(int(d)%10*a)for i,d in enumerate(str(b)[::-1])]+["%s\n%6i"%(h,a*b)])
``````

``````   999
x  999
------
8991
8991
8991
------
998001
``````

1

Perl中157个 151 150 144 141 133字符：

``````(\$x,\$y)=<>=~/[-\d]+/g;map{\$z=~s/z/ z/g;\$z=(abs\$x*\$_)."z\$z"}split//,abs\$y;map{printf"%6s
",\$_}\$x,"x\$y",\$b="-"x6,(split/z/,\$z),\$b,\$x*\$y
``````

``````>echo "-123, 456" | perl mult.pl
-123
x456
-------
738
615
492
-------
-56088
``````

Orabîg