Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lab 1: The Doomsday Algorithm

Item
Released Week 2
Due See the course schedule
Progress Grade

Computers can predict the future, at least as far as the day of the week is concerned. The Doomsday Algorithm is a trick for calculating which weekday any date falls on. By the end of this lab you will have a program that does it, and you will be able to do a rough version in your head.

Course learning outcomes

This lab addresses the following course learning outcomes:

CLO 1. Apply Python programming fundamentals to execute and explain computer code that implements interactive, novel solutions to a variety of computable problems.

CLO 2. Implement code consistent with industry-standard practices using professional-grade integrated development environments (IDEs), command-line tools, and version control systems.

Specifically, by the end of this lab you should be able to:

  • store a value in a variable and explain what type it holds
  • convert a string to an integer with int(), and say why that conversion is necessary
  • split one string into several pieces with .split()
  • use +, -, *, //, and % to build a multi-step calculation
  • call a function that somebody else wrote, passing it the arguments it expects
  • print a formatted result with an f-string

The problem

Given a date, report its day of the week. The formula needs four things:

  • a set of anchor days, one per month, that all fall on the same weekday within a year
  • the century and the two-digit year pulled out of the full year
  • the offset between the day you were asked about and that month's anchor day
  • the remainder after dividing by 7, because a week has seven days

Anchor days

Month Anchor Month Anchor
January 3 (4 in a leap year) July 11
February 28 (29 in a leap year) August 8
March 0 September 5
April 4 October 10
May 9 November 7
June 6 December 12

You do not have to build this table. It is already written for you in src/DayFunctions.py, as a function you call. It takes a month and a full year, and hands back a number:

anchor_day = get_anchor_day(1, 2026)    # anchor_day is now 3

A second provided function takes a number from 0 to 6 and hands back a weekday name:

weekday = get_day_of_week(3)            # weekday is now "Wednesday"

Both are already imported for you at the top of src/main.py, so you can call them the same way you call int() or print().

The formula

Work in pieces rather than one long line:

part_one     = 5 * ((century % 4) + (decade % 4) - 1)
part_two     = 10 * decade
sum_of_parts = part_one + part_two

day_offset   = day - get_anchor_day(month, full_year)
total_offset = sum_of_parts + day_offset

weekday      = total_offset % 7

For the year 2026, the century is 20, the decade is 26, and the full year is 2026.

Important

Separating 2026 into 20 and 26 is the one part of this that is genuinely up to you. Integer division (//) is the tool.

Expected output

1-23-2026: Friday

The date is echoed exactly as the user typed it, then a colon, then the weekday.

Getting started

Open src/main.py and work through the TODO markers top to bottom. Run it as you go:

uv run python src/main.py

Important

Run every command in this README from the assignment's working directory, which is the top-level folder you land in right after cloning, for example .../lab01-doomsday-algorithm. Notice that the command above says src/main.py: you stay at the top level and point into src, rather than using cd to move inside it.

Run pwd if you are not sure where you are. Two signs you are in the wrong directory:

  • can't open file ... src/src/main.py means you already moved into src
  • The path gatorgrade.yml either does not exist or is not valid means the checks below cannot find their configuration

Evaluation

This lab is worth 4.5 points, which is the standard value for a lab in this course.

Component Points What it measures
Programming 3.0 The 8 code checks below. Your score is the fraction passed, times 3.0
Code quality and style 1.0 Descriptive names (0.3), clear organization (0.3), useful comments (0.4)
Summary writing 0.5 A complete, thoughtful docs/summary.md
Total 4.5

Programming, 3.0 points

Run the checks yourself, as many times as you like, before you submit. This one also runs from the working directory, not from inside src:

uv run gatorgrade --config gatorgrade.yml

Eight of the checks are about your code:

  • the program runs and prints a result
  • it reports the correct weekday for a set of dates, including a November date and a leap day
  • no TODO markers remain in src/main.py
  • the program contains at least 5 comments
  • it uses .split() and int()

Partial credit is proportional: passing 6 of 8 checks earns (6 ÷ 8) × 3.0 = 2.25 points.

The remaining two checks look at docs/summary.md. They confirm the document is finished, and they count toward Summary writing below rather than toward these 3.0 points.

Note

Automated results are preliminary. Your instructor sets the final grade.

Code quality and style, 1.0 point

Graded by a human reading your code. Descriptive variable names, sensible organization, and comments that explain why rather than restating what the line already says. A comment that misdescribes its code counts against you.

Summary writing, 0.5 points

Complete docs/summary.md. Every question answered fully. Minimum word count is 150.

Choosing your test cases

Two of the checks single out November and leap days. That is deliberate. A version of this algorithm can be wrong for exactly one month, or only in leap years, and still look perfectly correct on every date you happen to try. Choose your test cases to attack your code, not to flatter it.

Code review

A Technical Leader or the instructor will conduct a code review with you on this lab. Code reviews are graded separately from the 4.5 points above, under the Code Reviews category on the syllabus.

Two things happen, with you present:

  1. You run your program for the reviewer, on a date they may choose
  2. You answer questions about your own code, including the concepts behind it

The reviewer opens a Code Review issue on your repository and fills it out during the conversation. Come prepared to explain:

  • how you separated the century and decade out of the full year
  • how the anchor day and the day offset combine to produce the final weekday
  • a demonstration date, traced through the calculation, including why the result is taken mod 7

Your review must be completed during the lab session on the day this lab is due. If you cannot attend that lab and complete your review then, make arrangements to complete it beforehand at office hours:

Submitting

Commit and push often. The last version pushed before the deadline is the one that gets graded. If you need more time, apply a late token with this form.

In the terminal:

git add src/main.py docs/summary.md
git commit -m "Complete the Doomsday Algorithm"
git push

In VS Code, the Source Control panel in the left sidebar does the same three steps:

  1. Click + next to a changed file to stage it (this is git add)
  2. Type a message in the box at the top, then click the checkmark (this is git commit)
  3. Click Sync Changes (or the ↑ arrow) to push

Either way, then open your repository on GitHub and confirm your latest changes are actually there.

About

Lab version of the doomsday algorithm activity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages