CS245

Homework 6

Overview

In this assignment you will work with a partner. The task is to produce two programs that do exactly the same thing (in slightly different ways.) One version in Go and the other using Rust. Then, based on your experience with the programs answer the questions posed at the end of the assignment. I imagine that you will do the following:
  1. Find a partner
  2. With your partner, sketch out program flow for the Go and Rust programs.
  3. Split work, one person do the program in Go, the other in Rust (Alternately you could use paired programming. If you do this, I highly encourage you to switch off the person who is typing and the person who is thinking / researching.)
  4. Answer the summary questions.
You are not required to work with a partner. If you do not, then you must write the program in Rust. There is a special set of summary questions a for people working solo. You should answer only those questions.

S Perfect numbers

According to Wikipedia "in number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number." All of that you know from an assignment earlier in the semester. In this assignment you will actually write a program to find "S Perfect" numbers (and numbers very close to "S Perfect").

The set "S" consists of all integers such that the sum their factors that are in the S set -- call these S-factors -- is less than or equal to the number. (Exclude the number itself when considering factors.) For example, the smallest number NOT is S is 12, because its S-factors are {1,2,3,4,6} which sum to 16 which is greater than 12.

An "S-Perfect number" is a number whose S-factors sum to itself. S-Perfect numbers are more common than Perfect numbers, but they are still rare (Perfect numbers are a subset of S-Perfect numbers). Here are all S-perfect numbers less than 1,000,000,000

        
        [6, 24, 28, 96, 126, 224, 384, 496, 1536, 1792, 6144, 8128, 14336, 15872, 24576, 98304, 114688, 393216, 507904, 917504, 1040384, 1572864, 5540590, 6291456, 7340032, 9078520, 16252928, 22528935, 25165824, 33550336, 56918394, 58720256, 100663296, 133169152, 246650552, 402653184, 469762048, 520093696]
    

Here is a C program to find S-Perfect numbers.

        #include 
        #include 
            
        #define MAX_SIZE_SSET 1000000
            
        int main(int argc, char* argv[]) {
            int Sset[MAX_SIZE_SSET] ;
            int Ssetsize = 1;
            Sset[0] = 1 ;
            
            for(int n = 2; n < MAX_SIZE_SSET; n++) {
                int dsum = 0 ;
            
                for(int i = 0; i < Ssetsize; i++) {
                  if( n % Sset[i] == 0 && Sset[i] < n) dsum += Sset[i] ;
                  if (dsum > n || Sset[i] >= n) break ;
                }
            
                if(dsum <= n) {
                  if(dsum == n) printf("%d    %d\n", n, Ssetsize) ;
                  Sset[Ssetsize++ ] = n ;
                }
              }
        }
    
Note that in order to find S-Perfect numbers you must build up the S set along the way. This C program is limited by the size of stack memory; your program should not be so limited. (As an aside, there are far more integers in S than not in S.) If you are interested, an executable for this is available at
        /home/gtowell/bin/sperfect
    
This C program is correct; it works; but it is slow. It runs in O(n2) time.

Task 0

Find a partner.

Send the names of the two people in your group to gtowell@brynmawr.edu.

Actual Task

Write programs in Rust and Go that run with multiple threads to find S-Perfect, and close to S-Perfect, numbers. Your program need not be super efficient -- a brute force approach as exemplified by the C program above that runs in O(n2) time is OK. Even better (and worth extra credit), would be code that runs in O(n * n0.5) time; still brute force but a lot faster.

Parallelization Suggestion

Two properties of this problem render it tractable for parallelization. First, to compute whether a number N is in S (or is S-Perfect) it seems like you need to know all of the elements of S that are less than N. This is not true. You only need to know all of the elements of S that are less than (N+1)/2. Second, let H(N) be the difficulty of computing whether a number N is in S (or is S-Perfect). Then for any number M>N, H(M)>=H(N). As a result, it takes less time to compute all the members of S in the range 10,000-20,000 than it does to compute all of the members of S in the range 20,000-30,000. (and so forth)

Program Requirements

Questions

Once you complete your programs, write answers to the following questions. Please note that I am often asking you for opinions; so correctness is not an issue. Rather I am looking for well-thought statements based on you experience with writing these programs. Also, in all cases the portion of the response that address why is far more important than the part that address what. (For instance, suppose each response is worth 10 points, then what is worth no more than 1 or 2 points, why no less than 8 or 9.)

Questions for people who worked in pairs

Questions for people who worked Individually

Electronic Submissions

Your submission will be handed in using the submit script.

If you write your program on computers other than those in the lab, be aware that your program will be graded based on how it runs on the department’s Linux server, not how it runs on your computer. The most likely problem is not submitting everything or hard coding file locations that are not correct on the Linux servers.

The submission should include the following items:

README:
This file should follow the format of this sample README
Names of both people in a group. You need only submit once.
Source files
All of them (you might have only one)
Data files used:
Be sure to include any non-standard data files uses. (Rare)
DO NOT INCLUDE:
Data files that are read from the class site. Do include any of your own data files.

Again: Once you have everything you want to submit in the a6 directory within /home/YOU/cs245/

  1. Go to the directory /home/YOU/cs245
  2. Enter /home/gtowell/bin/submit -c 245 -p 6 -d a6
If this worked you will get a message with the word "success". If you cannot achieve success and the deadline is approaching, send me email. We can set up a meeting to work out your problems. The email will establish that you intended to submit. Once you send the email, do not change the files that you were trying to submit.