Multiplication tables: Difference between revisions

Content deleted Content added
Line 53: Line 53:
<lang AppleScript >set n to 12 -- Size of table.
<lang AppleScript >set n to 12 -- Size of table.
repeat with x from 0 to n
repeat with x from 0 to n
if x = 0 then set {R, x} to {{return}, -1}
if x = 0 then set {table, x} to {{return}, -1}
repeat with y from 0 to n
repeat with y from 0 to n
if y's contents = 0 then
if y's contents = 0 then
if x > 0 then set RR to {f(x as string)}
if x > 0 then set row to {f(x)}
if x = -1 then set {RR, x} to {{f("x")}, 1}
if x = -1 then set {row, x} to {{f("x")}, 1}
else
else
if y ≥ x then set end of RR to f(x * y)
if y ≥ x then set end of row to f(x * y)
if y < x then set end of RR to f("")
if y < x then set end of row to f("")
end if
end if
end repeat
end repeat
set end of R to RR & return
set end of table to row & return
end repeat
end repeat
return R as string
return table as string


-- Handler/Function for formatting fixed width integer string.
-- Handler/Function for formatting fixed width integer string.
Line 71: Line 71:
set text item delimiters to ""
set text item delimiters to ""
return (characters -4 thru -1 of (" " & x)) as string
return (characters -4 thru -1 of (" " & x)) as string
end f
end f</lang>Output:
</lang>Output:
<pre>"
<pre>"
x 1 2 3 4 5 6 7 8 9 10 11 12
x 1 2 3 4 5 6 7 8 9 10 11 12