Rosetta Code:Solve a Task: Difference between revisions

From Rosetta Code
Line 8: Line 8:
Rich Love, Carnation Software. 2022
Rich Love, Carnation Software. 2022
Arithmetic numbers
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic number because the average of its divisors is 1.5.
30 is an arithmetic number because its 7 divisors are: [1, 2, 3, 5, 6, 10, 15, 30], their sum is 72 and average 9 which is an integer.
Calculate and show here:
1. The first 100 arithmetic numbers.
2. The xth arithmetic number where x = 1,000 and x = 10,000.
3. How many of the first x arithmetic numbers are composite.
Note that, technically, the arithmetic number 1 is neither prime nor composite.
Carry out the same exercise in 2. and 3. above for x = 100,000 and x = 1,000,000.
==Adding Code==
==Adding Code==

Revision as of 15:39, 21 September 2022

So you'd like to solve a task? Great! Here's a brief walkthrough on how you might do that. While you may already have a task and a language in mind, we're going to assume the language is "Ayrch", and the task is Hello world. If the language you're familiar with doesn't already have a presence on Rosetta Code, consider going through the motions of adding a language. If you don't have a task in mind, check out our lists of unsolved tasks.

The Basics

Quickly getting started, this is all you really need to do.


Rich Love, Carnation Software. 2022

Adding Code

Language examples on each page are in alphabetical order, so you need to find where your example would fit. Once you've found that, click the "edit" link closest above the area where you want to insert your code on the task page, and add something like this to the bottom of the edit field:

<lang Ayrch>PRINT "Goodbye, World!"</lang>

Remember, for the sake of simplicity, we're assuming your language is Ayrch, and the task is Hello world. We're also assuming, for the moment, that Ayrch looks a lot like BASIC. Once you've added your code, hit the preview button to make sure you crossed all your T's and closed all your tags. If the language name shows up in red (a broken link), then either the language doesn't exist on the site yet (as a category), or you misspelled/mis-capitalized the name. Check your spelling against the one in Category:Programming Languages. That's all you really need to do!

Going a little further

If you want to give your code that spit and polish shine, there are a few more steps you can take.

Comments and Description

Consider adding descriptions to your code examples, to help the reader understand what's going on. This is particularly helpful if your code or language paradigms are very unlike ones that are already commonly known. Regardless, it's considered good practice in any environment where you would like other people to understand what you've written.


It's perfectly all right to depend on external (or even non-standard) libraries in your code examples. However, it can be problematic for others if they don't know they need to use a library, or don't know where to find it. There's a template for that: libheader.


{{libheader|Ayrch Console Extensions}}

<lang ayrch>PRINT "Goodbye World!"</lang>

Works With

Not all code works with all versions of a language, all versions of a compiler, interpreter or other implementation, or even all operating systems that the language may run on. If you're aware of certain constraints or other prerequisites that haven't already been mentioned, try using the works with template.


{{works with|Ayrch Virtual Machine|6.2}}

<lang ayrch>PRINT "Goodbye World!"</lang>


Thank you for adding code, and even more thanks if you added the spit and polish to make your code shine!

Where to go?

Now that you've solved one task, you might like to be reminded that there are lists of all the unsolved tasks for all of the languages that have a presence on Rosetta Code. If your preferred language isn't there, then you may need to go through the motions of adding a language in order to get the site software to automatically generate the list.