CS 340 Programming
Language Workshop in Scala (1 Credit)
· Office Hrs
: MW, 3:30-4pm ,
395 Joshi (or
· One and Only Class :
Wednesday, 3-3:30pm, 399 Joshi
course is designed as a self-study in Scala. You are expected to learn
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 quarter.
However, I will be available in the posted office hours for
and discussions about the programming problems.
- Experience with
programming in C++/Java.
programming assignment will be graded as Pass/Unsatisfactory, and
letter grade 'P' or 'U' will be assigned at the end.
- All work must be
turned-in by May 23,
- Do not expect an
incomplete for any reason. Each assignment has separate
- You must pass all the
assignments to pass the course. The code you turnin
must be your own creation. Copying code from available books, or cutting and pasting code from the
Internet is strictly prohibited.
- Each program should be
well-documented and adequately tested.
- You must turnin the source code runnable
using Scala, a ReadMe.txt with a brief
description of the program, and where applicable instructions for
running and testing the program including sample test inputs
and outputs to indicate that you have tested your code adequately, as a
single zip-archive for each assignment. To turnin the ith assignment (where i = 1,2,...), create the archive asgi.zip, and execute the following shell command on unixapps1:
- You may also be
required to demonstrate your code in my office hours after the due
(Assignment 1 - due 4/16/12) Gray
-bit Gray code is a sequence of n
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.
res0 : List[String] = List(000, 001, 011, 010, 110, 111, 101, 100)
- (Assignment 2 - due
4/30/12) N-Queens problem
Eight Queens problem is a classical problem in computer science. The
to place eight queens on a chessboard so that no two queens are
attacking each other; i.e., no two queens are in the same row, the same
column, or on the same diagonal. Write a program for solving N-Queens
Hint: Represent the
positions of the queens as a list of numbers
1..N. For example:
List(4, 2, 7, 3, 6, 8, 5, 1)
that the queen in the first column is in row 4, the queen in the second
column is in row 2, etc. Use the generate-and-test paradigm. Avoid
copying the solution given in the text.
- (Assignment 3 - due
5/9/12) Verbalizing numbers in English.
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.
res3: String = zero
res4: String = one billion two hundred and thirty four million five hundred and sixty seven thousand
eight hundred and ninety
res5: String = one billion twenty thousand three hundred and forty
4 - due 5/23/12) Open Ended
Take a non-trivial Java application (say 150-200 lines of code in OOP
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