Jump to content

Floyd's triangle: Difference between revisions

m
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>
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.