Saturday, October 26, 2013



Sum Of Primes.

Difficulty: (2/5)

Write a program that will take an integer as a command line argument and print the sum of all primes less than that number. For example:
% java SumPrimes 10
would sum the primes below 10:
2 + 3 + 5 + 7 = 17
To test your program, calculate the sum of all primes below a million:

Hints: Use the Sieve of Eratosthenes. Also, realize that the sum of all primes below a million is too big to fit in an int.

CS1 Deadline: 11/8/2013
Use: handin cs1113 extra2 SumPrimes.java




Monday, October 21, 2013



Area of a Triangle.

Difficulty: (2/5)

Write a program that will take the coordinates of the vertices of a triangle in 3D as command line arguments and print out the area of the triangle. For example, given the input:
% java TriangleArea 0 0 0  1 0 0  0 1 0
The program should calculate the area of the triangle with vertices (0,0,0), (1,0,0), and (0,1,0), which happens to be 0.5. Hint: Use Heron's formula, or the cross product.

To test your program, calculate the area of the triangle with vertices
(1, 2, 3)  (7, 8, 9)  (4, -5, 10)

CS1 Deadline: 11/1/2013
Use: handin cs1113 extra1 TriangleArea.java




Sunday, October 20, 2013

A place for programming puzzles. I will try to publish about one per week. If you know what you are doing, you should be able to write a program that solves the program in a couple of hours or less. The hope is to introduce different topics related to programming techniques, useful math, etc.