User Tools

Site Tools


Sidebar

projects

wcp1 (due 20240828)
btt0 (due 20240904)
wcp2 (due 20240904)
pct0 (bonus; due 20240905)
pct1 (bonus; due 20240905)
pct2 (due 20240905)
abc0 (due 20240906)
msi0 (due 20240911)
pct3 (bonus; due 20240911)
wcp3 (due 20240911)
msi1 (due 20240918)
pct4 (due 20240918)
wcp4 (due 20240918)
dsr0 (due 20240926)
pct5 (bonus; due 20240926)
wcp5 (due 20240926)
gfo0 (due 20241002)
pct6 (due 20241002)
pnc0 (due 20241002)
wcp6 (due 20241002)
dsr1 (due 20241009)
pct7 (bonus; due 20241009)
wcp7 (due 20241009)
bwp1 (bonus; due 20241016)
pct8 (due 20241016)
pnc1 (due 20241016)
wcp8 (due 20241016)
pct9 (bonus; due 20241023)
pnc2 (due 20241023)
wcp9 (due 20241023)
gfo1 (due 20241030)
mag0 (due 20241030)
pctA (due 20241030)
wcpA (due 20241030)
mag1 (due 20241106)
pctB (bonus; due 20241106)
wcpB (due 20241106)
mag2 (due 20241113)
pctC (due 20241113)
wcpC (due 20241113)
pctD (bonus; due 20241120)
wcpD (bonus; due 20241120)
bwp2 (bonus; due 20241204)
gfo2 (due 20241204)
pctE (bonus; due 20241204)
wcpE (bonus; due 20241204)
EoCE (due 20241216)
haas:fall2024:discrete:projects:ewn0

Corning Community College

CSCS2330 Discrete Structures

Project: EXPLORING WEIRD NUMBERS (ewn0)

Objective

To apply your skills in implementing an algorithm that determines certain attributes of a number based on its factor composition.

Background: Numerology

In ancient times, numbers and properties of numbers carried certain mystical qualities. In the Pythagorean tradition (at least as history attributes it), we have the following classifications:

  • abundant number: a number wherein the sum of its factors is greater than itself
    • for example, in the number 12, we have:
      • the factors: 1, 2, 3, 4, 6
      • the sum thereof: 1 + 2 + 3 + 4 + 6 = 16
      • as 16 is greater than 12, 12 is considered an abundant number
  • perfect number: a number wherein the sum of its factors is equal to itself
    • for example, in the number 6, we have:
      • the factors: 1, 2, 3
      • the sum thereof: 1 + 2 + 3 = 6
      • as 6 is equal to 6, 6 is considered a perfect number
  • deficient number: a number wherein the sum of its factors is less than itself
    • for example, in the number 21, we have:
      • the factors: 1, 3, 7
      • the sum thereof: 1 + 3 + 7 = 11
      • as 11 is less than 21, 21 is considered a deficient number

There are two activities at play here:

  1. the knowledge of the factors of a number (which we've had some experience with in our prime number endeavors)
  2. the sum of those factors to make the above determination of attribute

We will be writing a program that will perform these actions for a range of numbers.

Program: Description and Specifications

You are to write a program that:

  • accepts two values via command-line arguments
    • argv[1]: the starting value
    • argv[2]: the ending value
    • proper error checking should be performed so that the program cannot proceed (and should display an appropriate error) if the following conditions are encountered:
      • values less than 2 are provided, with an error “invalid range specification”
      • missing argv[2], with the error “missing upper bound”
      • missing both argv[1] and argv[2]: “insufficient data provided”
    • assumptions: as inferred in the error checking above, processing can start at 2, and proceed up to the maximum value of the data type.
      • while we are including 1 as a factor, we are not including the number itself in the list of factors.
    • perform the necessary calculations to determine the factors, from (and including) argv[1] through (and including) argv[2]
      • be sure to STORE the factors
      • sum the factors, and determine its abundant/perfect/deficient quality
      • NOTE: the starting value does NOT have to be less than the ending value. We are merely connecting the two.
    • display the results for that number, in the following format:
      • [NUMBER] quality: F1+F2+...+FN = SUM
      • for example: [8] deficient: 1+2+4 = 7

Grabit Integration

For those familiar with the grabit tool on lab46, I have made some skeleton files and a custom Makefile available for this project.

To “grab” it:

lab46:~/src/discrete$ grabit discrete ewn0
make: Entering directory '/var/public/SEMESTER/CLASS/ewn0'

‘/var/public/SEMESTER/CLASS/ewn0/Makefile’ -> ‘/home/USERNAME/src/CLASS/ewn0/Makefile’
‘/var/public/SEMESTER/CLASS/ewn0/ewn0.c’ -> ‘/home/USERNAME/src/CLASS/ewn0/ewn0.c’

make: Leaving directory '/var/public/SEMESTER/CLASS/ewn0'
lab46:~/src/discrete$ cd ewn0
lab46:~/src/discrete/ewn0$ ls
Makefile          ewn0.c
lab46:~/src/discrete/ewn0$ 

Just another “nice thing” we deserve.

NOTE: You do NOT want to do this on a populated ewn0 project directory– it will overwrite files. Only do this on an empty directory.

Makefile fun

With the Makefile, we have your basic compile and clean-up operations:

  • make: compile everything
  • make debug: compile everything with debug support
  • make clean: remove all binaries
  • make save: make a backup of your project
  • make submit: submit project (uses submit tool)

Execution

Your program output should be as follows (given the specific inputs via the command-line):

lab46:~/src/discrete/ewn0$ ./ewn0 2 16
[2] deficient: 1 = 1
[3] deficient: 1 = 1
[4] deficient: 1+2 = 3
[5] deficient: 1 = 1
[6] perfect:   1+2+3 = 6
[7] deficient: 1 = 1
[8] deficient: 1+2+4 = 7
[9] deficient: 1+3 = 4
[10] deficient: 1+2+5 = 8
[11] deficient: 1 = 1
[12] abundant:  1+2+3+4+6 = 16
[13] deficient: 1 = 1
[14] deficient: 1+2+7 = 10
[15] deficient: 1+3+5 = 9
[16] deficient: 1+2+4+8 = 15
lab46:~/src/discrete/ewn0$ 

And we don't have to start at 2:

lab46:~/src/discrete/ewn0$ ./ewn0 37 42
[37] deficient: 1 = 1
[38] deficient: 1+2+19 = 22
[39] deficient: 1+3+13 = 17
[40] abundant:  1+2+4+5+8+10+20 = 50
[41] deficient: 1 = 1
[42] abundant:  1+2+3+6+7+14+21 = 54
lab46:~/src/discrete/ewn0$ 

Additionally, we can also do this:

lab46:~/src/discrete/ewn0$ ./ewn0 30 17
[30] abundant:  1+2+3+5+6+10+15 = 42
[29] deficient: 1 = 1
[28] perfect:   1+2+4+7+14 = 28
[27] deficient: 1+3+9 = 13
[26] deficient: 1+2+13 = 16
[25] deficient: 1+5 = 6
[24] abundant:  1+2+3+4+6+8+12 = 36
[23] deficient: 1 = 1
[22] deficient: 1+2+11 = 14
[21] deficient: 1+3+7 = 11
[20] abundant:  1+2+4+5+10 = 22
[19] deficient: 1 = 1
[18] abundant:  1+2+3+6+9 = 21
[17] deficient: 1 = 1
lab46:~/src/discrete/ewn0$ 

Submission

Project Submission

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

lab46:~/src/discrete/ewn0$ make submit
removed 'ewn0'

Project backup process commencing

Taking snapshot of current project (ewn0)      ... OK
Compressing snapshot of ewn0 project archive   ... OK
Setting secure permissions on ewn0 archive     ... OK

Project backup process complete

Submitting discrete project "ewn0":
    -> ../ewn0-DATESTRING-HOUR.tar.gz(OK) 

SUCCESSFULLY SUBMITTED

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.

haas/fall2024/discrete/projects/ewn0.txt · Last modified: 2019/10/21 11:38 by 127.0.0.1