childishbeat Posted April 26, 2020 Share Posted April 26, 2020 With some help from some other forums on the Internet, especially the NesDev forums, the code of my one-line guess the number game with feedback in Family BASIC is down to being 131 characters long (simply referred to as "the code" from now on in this comment) (solution courtesy of Controllerhead over at the NesDev forums (simply referred to as Controllerhead from now on in this comment)). Here's the code: 0N=RND(10)+1:F.T=0TO0:I."WHAT'S MY NUMBER? (1-10) ",G:T=G<>N:RES.0:F.I=0TO(-(G>N)-T):READC$:N.:?C$:N.:D.CORRECT.,TOO LOW.,TOO HIGH. I'm looking for a shorter solution to the code. For me to accept any solution I get*: Each line of text must render below the previous line. The aforementioned code does that correctly. The same text must be printed if your code were to print the same text. I'd prefer the code to be on one line. If the code is on multiple lines, it'll be accepted, but in a different category, which might have a lesser status to me. Any solutions that break any of the other three rules can still be posted. However, I'd still rather any solutions you share fit within those rules. Controllerhead also suggested how the code could be made shorter (quote from https://forums.nesdev.com/viewtopic.php?f=2&t=19950&p=248910#p249009, which is on the same thread Controllerhead helped me get the code down to 131 characters): Quote Anyway, i still think the loading / storing / displaying of the messages could be shrunk, somehow. I was hoping to just load everything into your array without having to declare each spot specifically. I noticed the DATA command in the manual, and went with that instead. I tried to avoid using the RESTORE command by declaring the DATA every time before the READ, but that didn't work. The DATA had to be at the end of the line, or its own line. The way the READ pointer is incremented now could probably be more elegant, instead of the nested FOR loop. The only real savings i ended up with was avoiding the double quotes in the responses, because of how the DATA / READ work, but i was hoping to get it down more, and i still think it can be improved, somehow... After that, Controllerhead says they think they're probably done with looking for new solutions for now, but wishes me or anyone else luck for whoever tries to find any shorter solutions (I do.) (quote from the same NesDev forums thread, and even comment, linked to in this comment): Quote I think i'm probably done with this challenge, for now, but i wish you (or anyone else) luck if you pursue it further! By the way, I'm using Family BASIC V3.0 running under Nestopia v1.40 to run the code. P.S. Here's some documentation you could use to help me reduce the length of the code: https://gamefaqs.gamespot.com/nes/938747-family-basic-v3/faqs/59317 * Fun fact: If you can see the bold letters in the list, you should find a coincidence in the list in which the first letters of some of the points spell TIA, the name of a chip in the Atari 2600. I said the fact, partially because this website has the Atari name in it. Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.