Floyd's triangle: Difference between revisions
m
→{{header|J}}
m (→{{header|Ada}}) |
m (→{{header|J}}) |
||
Line 201:
Then, we format the matrix as text (which gives us the required vertical alignment), and in each row we replace each space followed by a zero with two spaces.
Efficiency note: In a measurement of time used: in floyd 100, 80% the time here goes into the string manipulations -- sequential additions and multiplications are cheap. In floyd 1000 this jumps to 98% of the time. Here's a faster version (about 3x on floyd 1000) courtesy of Aai of the J forums:
<lang J>floyd=: [: ({.~ i.&1@E.~&' 0')"1@":@(* ($ $ +/\@,)) >:/~@:i.</lang>
=={{header|Java}}==
<lang java>
|