Skip to the content.

Introduction to Algorithms, Programming, and Compilers

Hack 1: Create Your Own Algorithm

  1. Activity chosen: Setting up a new phone

  2. Algorithm: Setting up a New Phone

  3. Unbox the new phone and remove protective covers.

  4. Press and hold the power button until the screen lights up.

  5. Choose your preferred language and region.

  6. Connect to a Wi-Fi network for setup.

  7. Log in with your Google or Apple account.

  8. Restore data from a previous backup (if available).

  9. Set up security options (PIN, fingerprint, or face ID).

  10. Install essential apps from the app store.

  11. Customize home screen and settings.

  12. Test calling, texting, and internet to confirm setup success.

Hack 2: Identify the Bug

Original Algorithm: Send an Email

  1. Click “Send”

  2. Open email application

  3. Type the message

  4. Log into your account

  5. Enter recipient’s email address

  6. Write subject line

Corrected Algorithm: Send an Email

  1. Open email application

  2. Log into your account

  3. Click “Compose” or “New Email”

  4. Enter recipient’s email address

  5. Write subject line

  6. Type the message

  7. Review the email for mistakes

  8. Click “Send”

Hack 3: Code the Algorithm

def calculate_grade(score1, score2, score3):
    """
    Calculate letter grade from three test scores
    
    Args:
        score1, score2, score3: Test scores (integers)
    
    Returns:
        grade: Letter grade (string)
    """
    # Step 1: Add the three scores together
    total = score1 + score2 + score3

    # Step 2: Calculate the average
    average = total / 3

    # Step 3: Determine the letter grade using if-elif-else
    if average >= 90:
        grade = "A"
    elif average >= 80:
        grade = "B"
    elif average >= 70:
        grade = "C"
    elif average >= 60:
        grade = "D"
    else:
        grade = "F"
    
    # Step 4: Return the grade
    return grade

# Test your function!
print("Test 1:", calculate_grade(95, 92, 88))  # Should be 'A'
print("Test 2:", calculate_grade(85, 80, 82))  # Should be 'B'
print("Test 3:", calculate_grade(75, 70, 72))  # Should be 'C'
print("Test 4:", calculate_grade(65, 60, 62))  # Should be 'D'
print("Test 5:", calculate_grade(55, 50, 52))  # Should be 'F'
Test 1: A
Test 2: B
Test 3: C
Test 4: D
Test 5: F