Help! My QL has entered the Matrix !!!

A place to discuss general QL issues.
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Help! My QL has entered the Matrix !!!

Post by Tinyfpga »

Blimey! 2-3 minutes for a FizzBuzz program. I can't even open my laptop in that time. I found FizzBuzz quite difficult to write. It took me 70 minutes. Thank god I don't have to apply for programming jobs. I was so annoyed by my performance that I have not really checked that it is accurate.
FixxBuzz.jpg


User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by pjw »

dilwyn wrote:<>
I don't remember that one (maybe I did try and made a fool of myself - I'm sure you can find the evidence in the archive if I did). Out of interest, and wanting something to pass a few minutes just now, I had a go and it's certainly possible in S*BASIC in a very few lines in a couple of minutes, which for me included writing it out on paper and typing it in and correcting a minor typo (one letter in different case to the rest). I'm sure that with a little rewrite it would, like the Matrix ones, go down to just a line or two with a little thought.
You were certainly part of the discussion. The ultimate solution (to my mind) was a single line of a mere 69b!
But back on topic, I haven't tried writing a Matrix one as plenty of good attempts have been listed here, so a bit pointless me trying to go further!
The well isnt quite dry yet! This, somewhat stupid early attempt by me, trying to avoid using SCROLL, could be optimised much further. But since she isnt pretty, and could probably never be, I didnt take it further:

Code: Select all

wx = scr_xlim: x = int(wx / 6)
wy = scr_ylim: y = wy / 20 - 1
dim scr$(y, x)
:
randomise
for i = 0 to y
 scr$(i, 0) = x
 for j = 1 to x
  if j && 1 then
   if rnd(4): scr$(i, j) = ' ': else: scr$(i, j) = chr$(rnd(31,191))
  else
   scr$(i, j) = ' '
  endif
 endfor j
endfor i
:
window wx, wy, 0, 0: ink 4: cls
p = 0
rep lp
 for i = y to 0 step -1
  at i+i, 0: print scr$(p);
  p = (p + 2) mod y
  if inkey$(0) = chr$(27): exit lp
 endfor i
endrep lp
:
:
(Only tested in QPC2)
I do agree with what you say, though, that often in cases like this it's about lateral thinking rather than pure programming knowledge or which language you try to use, or whatever. After all, many a QL program program over the years has successfully shown that a hell of a lot can be achieved just from S*BASIC. I'm thinking of those short programs in Quanta mag by people like Steve Poole who write a whole working game or utility in just a page or so of BASIC code. While S*BASIC is often good enough for very large programs, it's also easy to write short, simple programs for your own use in minutes. Assembler, C, etc all have their places, but as we've seen here you can achieve a lot with a few lines of BASIC too.
Hear, hear!
One of the people who wrote some really cool FIZZBUZZ suggestions was Marcos Cruz. I dont think hes here, is he?
Last edited by pjw on Tue Dec 28, 2021 8:38 pm, edited 1 time in total.


Per
dont be happy. worry
- ?
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by pjw »

Tinyfpga wrote:Blimey! 2-3 minutes for a FizzBuzz program. I can't even open my laptop in that time. I found FizzBuzz quite difficult to write. It took me 70 minutes. Thank god I don't have to apply for programming jobs. I was so annoyed by my performance that I have not really checked that it is accurate.
FixxBuzz.jpg
It certainly looks the ticket! Are you sure youre not just having us on that you "cant program"? ;)


Per
dont be happy. worry
- ?
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Help! My QL has entered the Matrix !!!

Post by Tinyfpga »

pjw wrote:- Are you sure your'e not just having us on that you "can't program"?
I hope I did not say that I couldn't program. In a very recent post on this topic, I wrote that "I enjoy programming for fun" and wrote:- "For this activity to become more fluid I need to better understand how the whole thing work".

My knowledge and skills are very limited and I find writing software difficult; also I can only currently write programs in SBASIC.

Although my questions and problems are not always answered or perhaps seen,(e.g. above post) I do appreciate the help that is provided by forum members.


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: Help! My QL has entered the Matrix !!!

Post by dilwyn »

Tinyfpga wrote:Blimey! 2-3 minutes for a FizzBuzz program. I can't even open my laptop in that time. I found FizzBuzz quite difficult to write. It took me 70 minutes. Thank god I don't have to apply for programming jobs. I was so annoyed by my performance that I have not really checked that it is accurate.
FixxBuzz.jpg
Don't want to start wandering too far off topic on here - you went to more trouble to "pretty up" the layout than I did - I read Per's quote a bit too literally, maybe - yours puts the entire result on a well laid out screen, mine just scrolls them all up the screen. I didn't save my effort, but I found the piece of paper. Hope I typed it in correctly, it produced the same results. This goes to show that even simple challenges like this are open to interpretation to a degree, as Per suggested. And as for "2 minutes" to do this, that didn't include any "thinking time" between reading Per's post and writing it down on paper - the idea was most likely at least partly in my head before I started writing. Definitely didn't include time to "open my laptop" :ugeek:

I'm sure that with a bit of will, you could shorten this using single line definitions and/or possibly logical operators to shorten the IFs.

Code: Select all

FOR a = 1 TO 100
  PRINT a;" ";
  IF (a MOD 3) = 0 THEN PRINT "FIZZ";
  IF (a MOD 5) = 0 THEN PRINT " BUZZ";
  PRINT
END FOR a
Sorry to stray off topic, I wanted to use this to expand on what Per said earlier about different ways of approaching the same programming challenge.


Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Help! My QL has entered the Matrix !!!

Post by Tinyfpga »

Just one last wander:- Dilwyn's use of MOD (an instruction I was not aware existed) is an example of what I mean by:- needing to better understand programming and SBASIC.
I have modified my code accordingly and saved 98 bytes and three lines of code.


User avatar
1024MAK
Super Gold Card
Posts: 592
Joined: Sun Dec 11, 2011 1:16 am
Location: Looking forward to summer in Somerset, UK...

Re: Help! My QL has entered the Matrix !!!

Post by 1024MAK »

Where the function MOD does not exist, you can use something like this:

Code: Select all

IF a/3 = INT(a/3) THEN …
Then it’s even possible to write a short program on most versions of BASIC on most machines, especially as nowhere does it say that the output has to be neatly lined up :lol:

Mark


:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer in Somerset later in the year :)

QL, Falcon, Atari 520STFM, Atari 1040STE, more PC's than I care to count and an assortment of 8 bit micros (Sinclair and Acorn)(nearly forgot the Psion's)
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by pjw »

1024MAK wrote:Where the function MOD does not exist, you can use something like this:<>
MOD exists in all versions of SuperBASIC and SBASIC. (Are there others?) The only difference is that SBASIC's DIV/MOD work on 32 bits while SuperBASIC's only does 16 bits.


Per
dont be happy. worry
- ?
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Help! My QL has entered the Matrix !!!

Post by NormanDunbar »

tinyfpga wrote:Just one last wander:- Dilwyn's use of MOD (an instruction I was not aware existed) is an example of what I mean by:- needing to better understand programming and SBASIC.
Hmmmm, it sounds like you might not be aware that the entire QL Manual, as supplied when a QL was purchased, is available in a few sections on Dilwyn's Web Site:

http://www.dilwyn.me.uk/docs/manuals/in ... l#qlmanual


That will show you the built in commnads, functions and procedures for the original QDOS based QL. SMSQ/E is slightly different, but does have the same commands plus a couple more.

There is also Rich's Online SBASIC/SuperBASIC Manual, at https://superbasic-manual.readthedocs.io/en/latest/ which has all the commands in SuperBASIC, SBASIC plus numerous different toolkits. There is more information as well as just a list of commands tec though -- have a read. You can also download the Online Manul as a PDF, EPUB or HTML:

1. On the left sidebar, scroll to the bottom of the subjects and you will see "Read the Docs latest" with a small down arrow, or 'V'. Click that.
2. When the window opens up a bit, click on the desired format -- PDF, EPUB, HTML -- to download it.
3. Pour a coffee or three, grab some chocolate biscuits, and dive right in!


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Post Reply