CS 3190 Programming
Language Workshop in Scala (1 Credit)
· Office Hrs
: TTh, 11:15am-12:15pm
,
395 Joshi (or
by appointment)
· One and Only
Meeting (Attendance Optional): September 6, Wednesday, 11:30am-12pm, 399 Joshi
Course Description
This
course is designed as a self-study in Scala. You are expected to learn
the
language and solve a set of programming problems assigned to you using
Scala available from http://www.scala-lang.org/.
There are no exams. We officially meet only once in the semester (and
attending this meeting is optional if the online document is
clear).
However, I will be available in the posted office hours for
clarifications
and discussions about the programming problems. Typically, most of
the comunication is via emails.
Prerequisite
- Experience with
programming in Java.
Reference Texts
Grading
Each
programming assignment will be graded as Pass/Unsatisfactory, and
the
letter grade 'P' or 'U' will be assigned at the end of the course.
Course Policies
- All work must be
turned-in by December 08,
2017.
- Do not expect an
incomplete for any reason. Each assignment has separate
deadlines.
- You must pass all the
assignments to pass the course. The code you turnin
must be your own creation. Copying code from available books, and/or cutting and pasting code from the
Internet is strictly prohibited.
- Each program should be
well-documented and adequately tested.
- You must turnin well-documented source code runnable
using Scala. You should include (i) instructions for
running and testing the program, and (ii) sample test inputs
and outputs to indicate that you have tested your code adequately, in the source file as comments or as a separate ReadMe.txt . If you have multiple files, submit them as a
single zip-archive. To turnin the ith assignment (where i = 1,2,...), create asgi.scala
or the archive asgi.zip, and upload it to the corresponding assignment DropBox on
Pilot before or on the due date.
- You may also be
required to demonstrate your code in my office hours after the due
date.
Assignments
(Assignment 1 - due 09/18) Gray
Code Generation
An
n-bit Gray code is a sequence of
n-bit
strings constructed according to certain rules. For example,
n = 1: C(1) = ("0", "1").
n = 2: C(2) = ("00", "01", "11", "10").
n = 3: C(3) = ("000", "001", "011", "010", "110",
"111", "101", "100").
Find out the construction rules and write a
function to generate Gray codes.
scala> gray(3)
res0 : List[String] = List(000, 001, 011, 010, 110, 111, 101, 100)
- (Assignment 2 - due 10/16) Random walk problem
1) A classic problem in statistics is the
random walk. Imagine a
drunken man standing on the center square of a sidewalk consisting of
11 squares. At each step, the drunk can elect to go right or left. How
long will it be until he reaches the end of the sidewalk, and how many
times will he have stood on each square? To solve the problem,
represent the number of times the drunk has stood on a square as an
array, and use random number generating function for simulation.
Display the value of the array at the beginning, at the end, and a few
intermediate steps. (Make the latter programmable by defining a
constant increment at the beginning of the program.)
(2) Now repeat the same for a two-dimensional variation on the random
walk using an 11-by-11 array, and four moves: up, down, left, and
right.
- (Assignment 3 - due 11/13) Encrypting Messages + Verbalizing numbers in English.
(1) In this exercise, we explore cyclic cipher to encrypt
messages. This type of cipher was used by Julius Caesar to communicate
with his generals. It is very simple to generate and can be easily
broken. The key idea behind the Caesar cipher is to replace each letter
by a letter some fixed number of positions down the alphabet. For
example, if we want to create a cipher shifting by 3, you will get the
following mapping:
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher: DEFGHIJKLMNOPQRSTUVWXYZABC
Write a program that takes a string and a shift value to generate the
Cipher. Read up and check out ROT13, an invertible cipher.
(2) On financial documents, like cheques, numbers must sometimes be
written in full words. For example: 175 must be written as 'one hundred
and seventy five'.
Write a function verbalize(num: Int) to print (non-negative) integer
numbers in words.
scala> verbalize(0)
res3: String = zero
scala> verbalize(1234567890)
res4: String = one billion two hundred and thirty four million five
hundred and sixty seven thousand eight hundred and ninety
scala> verbalize(1000020345)
res5: String = one billion twenty thousand three hundred and forty five
- (Assignment
4 - due 12/08) Open Ended
Problem.
Take a non-trivial Java application (say 150-200 lines of code in OOP
style)
that interests you and rewrite it in Scala. Turnin both the versions.
Document and critique the generic changes to be made to the Java
program to obtain the corresponding Scala program and the resulting
reduction in code size in
ReadMe.txt.