Author Topic: Oh that Floyd  (Read 3695 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Oh that Floyd
« on: October 16, 2018, 08:38:15 pm »
http://rosettacode.org/wiki/Floyd%27s_triangle
Code: QB64: [Select]
  1. floyd 20
  2. SUB floyd (row)
  3.     LOCATE row, 1
  4.     FOR i = ((row - 1) * row) / 2 + 1 TO row * (row + 1) / 2
  5.         PRINT RIGHT$("   " + STR$(i), 4);
  6.     NEXT
  7.     PRINT
  8.     IF row > 1 THEN floyd (row - 1)
  9.  
floyd.PNG
* floyd.PNG (Filesize: 25.88 KB, Dimensions: 660x571, Views: 338)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Oh that Floyd
« Reply #1 on: October 17, 2018, 10:11:55 am »
Dang! I missed the Rosetta spec about spacing, that makes it much more tricky.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Oh that Floyd
« Reply #2 on: October 17, 2018, 10:56:18 am »
John from All BASIC has nice version.
Code: QB64: [Select]
  1. _TITLE "Floyd John's version" ' from All BASIC 2018-10-17 looking pretty good!"
  2. l = 14 'number of rows for Floyd to process
  3. n = 1 ' number increment
  4. FOR r = 1 TO l
  5.     FOR c = 1 TO r
  6.         PRINT RIGHT$("    " + STR$(n), LEN(STR$(c + l * (l - 1) / 2)));
  7.         n = n + 1
  8.     NEXT
  9.     PRINT
  10.  

Notice how the spacing of columns is handled.
Floyd John's version.PNG
* Floyd John's version.PNG (Filesize: 21.34 KB, Dimensions: 752x515, Views: 285)