Harvard Pre-College Program CSCI S-14600, Session I
Week 0: Day 0, Day 1, Day 2, Day 3, Day 4
Week 1: Day 5, Day 6, Day 7, Day 8, Day 9
This course is an introduction to programming using Swift, Apple's new programming language for Macs and iOS devices. Through Swift, we explore the basics of programming and introduce fundamental computer science topics like abstraction, algorithms, basic data structures, and recursion. The course also features practical programming topics such as scripting, command line interfaces, application programming interfaces, debugging, integrated development environments, understanding documentation, and developing software both in isolation and as a team. By the end, each student designs and implements an app that can be deployed to iOS devices, like an iPhone or an iPad. Students must bring a MacBook, MacBook Air, or MacBook Pro running Mac OS10.11 or higher.
The Summer School is committed to providing an accessible academic community. The Accessibility Services Office offers a variety of accommodations and services to students with documented disabilities.
You are responsible for understanding Harvard Summer School policies on academic integrity and how to use sources responsibly. Please be sure to read through the responsibilities, as not knowing the rules or misunderstanding the rules are not acceptable excuses. Please contact the staff if you have any questions about academic honesty.
This course is held during Session I of the 2016 Harvard Pre-College Program which runs from Monday, 27 June through Friday, 8 July. Class is held Monday through Friday from 8:30am to 11:30am in 1 Story Street room 304.
Office Hours are held by one or more TFs from 7PM to 9PM in the Dunster House dining hall on the dates listed below!
Week | Days |
---|---|
0 | Monday, Tuesday, Wednesday, Thursday |
1 | Sunday, Tuesday, Wednesday, Thursday |
Abstraction, algorithms, pseudocode, source code, compilation and interpretation. Swift basics: variables, boolean expressions, logical operators, arithmetic, and control flow.
Attempt the below problems. You must complete one, try to complete two!
f
, to Celsius. And then implement the reverse, to convert back! Be sure to test your code. Below is a code fragment to get you started.// YOUR NAME HERE
// you@email.com
//
// Fahrenheit converter
var f = 32
let Celsius = // your code here, using the `f` variable
var c = 10
let Fahrenheit = // your reverse code here
The input should be the number of lines. To get you started, begin with this:
// YOUR NAME HERE
// you@email.com
//
// Diamonds!
let NUM_LINES = 11
// for loops here
Be sure to pay close attention to how many stars are on each line. Use for
loops to create this design! You might first try creating pyramid shapes to get started:
Hint: The print()
adds a line break to the end of the print statement by default. To turn this off, use the terminator:""
parameter, like so: print("your string here", terminator:"")
.
Note: Swift doesn't (easily) allow for input from standard in, so don't use the GetLongLong function (which doesn't exist anyway). Instead, just input it as a 64-bit int like so:
let card = 378282246310005
Loops, arrays, functions, optionals, tuples.
zip
student-supplied solution, modified to include tuplesAt a minimum, complete the first three.
zip
solution (finishing it, if necessary!) to return a type of [(Int?, Int?)]
, which will allow two lists of different lengths. You may optionally provide names to the tuple, like [(zeroth: Int?, first: Int?)]
.printGradeCount()
and average()
. We intentionally did not go over dictionaries in class so that you gain some experience reading documentation to achieve a particular programming goal!exam
grades, homework
grades, participation
grades, etc. You could model this with a dictionary by having a dictionary key represent every category.printGradeCount()
should accept a dictionary and it should then print the number of grades for each category. average()
should accept a dictionary and print the grade average for every category. For example:let grades = ["exams": [100, 90], "homework": [50, 85, 67]]
printGradeCount(grades)
average(grades)
Should print:
exams: 2
homework: 3
exams: 95
homework: 67.3333333333333
Theory of computation, programming paradigms. Closures, lambdas, higher-order functions.
Provided for fun, each offers a little more information on topics addressed in class.
Try to complete all of the below problems.
reduce
function that is higher-order. It should accept an array of doubles ([Double]
), an initial value i
of type Double
, and a function f
, which itself takes as parameter two Double
values and returns a Double
. The function calls f
first with the initial condition and the first element in the list, and stores the output. It then takes the output, and calls f
with the output and the next element in the list, and so on. In short, it combines all of the elements in the list to a single value by relying on a function f
to do the combination. Below is a sample of how you might call the function, which when run should return the value 10.0
, since it sums the values in the list.
reduce([1.0, 2.0, 3.0, 4.0], i: 0.0, f: { $0 + $1 })
mapper
, filter
, and reduce
HOFs to achieve the following:
[-0.5, 0, 8]
should become to [-2, 0.125]
quickSort
that takes in an unsorted Double
array and outputs a sorted [Double]
. Quicksort works by selecting a "pivot" element, partitioning the array into three categories: all elements smaller than or equal to the pivot, the pivot, and all elements larger than the pivot, and then recursively applying quicksort to each category. Because it is recursive, quicksort has a base case when the array size is 1: it should just return the array. As a small hint, this function should use at least one of the higher order functions we discussed in class!curry
, that accepts a function that normally requires two Double
parameters (like pow
), and allows partial application of that function. In other words, although we'd normally call pow(x, y)
, after we pass it to curry we should get a new function, exp
, that allows exp(x)(y)
. More specifically, although we'd normally run pow(2, 3)
, perhaps we only want to partially apply the function as follows:let exp = curry(pow)
let base = exp(2)
base(3) // outputs 8
ASCII, Unicode, representing values with binary and hexadecimal. Aliasing types, generics, inout
parameters.
inout
(Thanks, Jack, for generics and swap!)Provided for fun, each offers a little more information on topics addressed in class.
Complete at least the first two problems of this Day 3 Homework playground!
You may find the following YouTube videos useful to understand the homework problems:
Basic encryption. Algorithmic complexity, parallelism. Game of Fifteen, Xcode, iOS, Storyboards, constraints.
Attempt MapReduce exercise. Begin Game of Fifteen exercises. You may choose how far along you wish to complete the Game of Fifteen exercises, but keep in mind: the more of these you do now, the more time you will have to polish your Game of Fifteen iOS app next week!
aliceinwonderland.txt
file so it can be discovered by the Playground.4 July, 2016: Independence Day holiday
Swift classes, enums, and structs. iOS, continued, and the application lifecycle, multi-threaded applications. Programmatic creation of UI elements.
Having now switched to project mode, we're working towards implementing a Game of Fifteen app for iOS.
Debugging. UI element practice including bounds, frames, animation, timers.
isBoardSolvable()
Continue working on Game of Fifteen project, bundling the exercises into an app, drawing the board, and connecting the elements.
UI elements, continued: alerts and action sheets. Placing apps on your phone.
Complete and put finishing touches on your Game of Fifteen app!
Wrap-up.
Dan Armendariz | Instructor | Web, Instagram | ||
Hari Anbarasu | Teaching Fellow | |||
Annie Chen | Teaching Fellow | Chrome Store | ||
Jack Deschler | Teaching Fellow | |||
Arturo J. Real | Teaching Fellow | |||
Stelios Rousoglou | Teaching Fellow | LinkedIn, Facebook |