Basicprogramming(.org) > Code and examples

Floyd's Triangle

(1/3) > >>

Tomaaz:
Here is my version of Floyd's Triangle. I wanted to make it as compact as possible and created this one line in Ruby:


--- Code: ---(1..14).each {|x| puts (((1 + x) * (x / 2.0) - (x - 1)).to_i..((1 + x) * (x / 2.0)).to_i).to_a.to_s.split(",").join}

--- End code ---

Anyone wants to post something in BASIC? But please, try to do something different than two loops and couple of variables.  ;)

B+:
Here's what I have:

B+:
SmallBASIC version:

--- Code: ---floyd 20
sub floyd (r)
locate r, 1
for i in seq(((r - 1) * r) / 2 + 1, r * (r + 1) / 2, r * (r + 1) / 2 - (r - 1) * r / 2 ) do ? right("   " + str(i), 4);
? : if r > 0 then floyd (r - 1) else locate 1, 4 : ? 1
end

--- End code ---

Tomaaz:
Recursion. Nice. Anyone else?  ;)

B+:
Dang! I missed the Rosetta spec about spacing, that probably eliminates a recursive method or makes it very ugly.

Navigation

[0] Message Index

[#] Next page

Go to full version