|
Forum Index : Microcontroller and PC projects : Adding MMBasic to Rossetta Code
| Author | Message | ||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
Always on the lookout to give students an audience for their code, we have been looking at the code on Rosetta Code. TL;DR - Rosetta Code is a multi-language (language as in code) site that exemplifies "common" coding challenges in various languages - for comparison / learning. Having promoted the Online Encyclopedia of Integer Sequences to students to see who can code sequences in MMBasic (now on the PicoMite) - we are now looking at Rosetta Code - and I have just added the first one drawn from the class suggestions. The first entry is here: Harshad Numbers - Using MMBasic I have set up the "Category" page for MMBasic - but the Wiki is still updating that by the look of it. When that is updated and editable, I will add links / attribution to the origins of MMBasic. The plan is to see if we can add MMBasic as an entry into as many of the other Rosetta Code challenges. The nice thing about a Wiki is that the code can be edited, so students may get the experience of people editing / updating / tweaking / improving their code ---- or creating a whole new, different ("better" - but how do you define better??) version. Part of an ongoing thought to get MMBasic / PicoMites into education - in this case, attempting to give students an audience and the experience of "code review". N Code, as added to Rosetta Code: number = 1 tally = 0 print "First 20 Harshad numbers:" do while tally < 20 if isHarshad(number) = 0 then print number; tally = tally + 1 endif number = number + 1 loop number = 1001 endloop = 0 print "" do if isHarshad(number) = 0 then print "The first Harshad number greater than 1000 is"; number endloop = 1 endif number = number + 1 loop until endloop = 1 function digitSum(x) let y$ = str$(x) for i = 1 to len(y$) digitSum = digitSum + val(mid$(y$,i,1)) next i end function function isHarshad(num) isHarshad = num MOD digitSum(num) end function In case any Shedders want to add to the MMBasic, you need to do the following when you edit one of the existing entries: Start a section in the appropriate alphabetical location: =={{header|MMBasic}}== <syntaxhighlight lang="bbcbasic"> Enter your MMBasic Code here end with >>> </syntaxhighlight> Add this at the end with a sample of what the output looks like: {{out}} <pre>First 20 Harshad numbers: 1 2 3 4 5 6 7 8 9 10 12 18 20 21 24 27 30 36 40 42 The first Harshad number greater than 1000 is 1002</pre> Edit: There isnt a syntax highlighter for MMBasic in Rosetta Code. Appraently you can add one to a fork? in Github -- as it uses https://pygments.org/languages/ -- but I looked and gave up!!! Edited 2022-10-29 23:34 by Nimue Entropy is not what it used to be |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |