Project Euler, Part 1

Applying what we’ve learned in different ways.

Jason Oswald
Learning Computer Science with Swift
2 min readAug 20, 2017

--

Project Euler is a set of problems designed to be solved with programming. The subset of problems presented here can be completed efficently (relatively, at least) using the tools and skills we have developed thus far using Playgrounds:

  • Commands and Sequences
  • Debugging
  • Functions
  • Loops
  • Conditionals
  • Logic
  • Variables
  • Types
  • Parameters

Algorithmic Thinking

The key to effectively solving these problems is to plan out your solution before you start coding. The general strategy is this:

  • Think/talk/write/draw your way through a solution. Avoid code, or anything close to it.
  • Translate your idea into what we call pseudocode. You can write or type this, but don’t code it.
  • Run through your pseudocode and see where it might break down. Adjust and try it again.
  • Translate your psuedocode into Swift.
  • If your code did’t work, you’ll need to investigate why, adjust your code and try again.

Optimize Late

While we do want to seek efficient solutions, work on solving the problem and then optimizing your solution later.

What to Do

I’d recommend setting up an account at Project Euler. This will allow you to check your answers and, after you complete a puzzle, see a discussion about the puzzle.

Once you’re ready to begin a problem, tap “Get Playground” in Swift Playgrounds, then tap “Starting Points” and choose “Blank.” This gives you a blank playground. You’re now ready to start writing Swift.

I would copy the text of the problem into your playground, or at least a brief description of the problem, as a comment in the playground.

Next, follow the steps listed in “Algorithmic Thinking” above. When you’re done

Easy Problems (20 points, each)

Problem 1

Problem 6

Problem 7

Problem 10

Medium Problems (8 points, each)

Problem 2

Problem 3

Problem 9

Hard Problems (5 points, each)

Problem 5

Problem 12

--

--