class hanoi
{
public static void main (String args[])
{
int numdisks = 3;
H_dohanoi(numdisks, 3, 1, 2);
System.exit(0);
}
static void H_dohanoi(int n, int t, int f, int u)
{
if (n > 0) {
H_dohanoi(n-1, u, f, t);
H_moveit(f, t);
H_dohanoi(n-1, t, u, f);
}
}
static void H_moveit(int from, int to)
{
System.out.print("move ");
System.out.print(from);
System.out.print(" --> ");
System.out.println(to);
}
}
Try running it with 6 pegs!
Monday, July 21, 2008
First blog post: Use paint to describe the steps in solving the Tower of Hanoi
Use three disks and show where everything is going!
Recursion
July 21st, 2008.
Tonight we will be learning recursion. The test will be postponed until Wednesday.
Tonight we will be learning recursion. The test will be postponed until Wednesday.
Wednesday, July 16, 2008
Test Four Review
Unlike last test which was multiple choice and had no coding, this test will be more like the first two tests and have actual coding! Here's a review with sample questions.
Monday, July 14, 2008
Where can you find code to read? Sourceforge.net!
Check out this cool clone Civilization (one of my favorite games of all time) http://sourceforge.net/projects/freecol/
Here's a direct link to the download.
I'd recommend downloading source code from different projects and reading through them. As you get to be a better programmer you can join projects. This looks very good on a resume!
http://sourceforge.net/
Blog reaction:
I'd like you to pick another project using Java (search for Java), download it, and check out the source code. Put your reactions to the site (http://sourceforge.net/) and the code you downloaded on your blog.
Here's a direct link to the download.
I'd recommend downloading source code from different projects and reading through them. As you get to be a better programmer you can join projects. This looks very good on a resume!
http://sourceforge.net/
Blog reaction:
I'd like you to pick another project using Java (search for Java), download it, and check out the source code. Put your reactions to the site (http://sourceforge.net/) and the code you downloaded on your blog.
Perfect Numbers and Prime Numbers! (Minor Project)
Please implement this method to determine whether a number is PERFECT!
For example: 6 is a perfect number because 6 = 1 + 2 + 3 (1, 2, 3 are divisors of 6)
28 is also a perfect number: 28 = 1 + 2 + 4 + 7 + 14
Make your method static and test it!
You need th % modulus operator to make this work.
The second part is to find all the prime numbers up to a certain number. For instance if a user enters in 5, you will find all the prime numbers up to 5. Would 5be included? Yes! It is prime. 1 is not prime. Create a new static method to determine all the prime numbers up to that point.
Here are some notes on the questions. Pseduocode to turn into code.
Due Friday July 18th, 2008.
For example: 6 is a perfect number because 6 = 1 + 2 + 3 (1, 2, 3 are divisors of 6)
28 is also a perfect number: 28 = 1 + 2 + 4 + 7 + 14
Make your method static and test it!
You need th % modulus operator to make this work.
The second part is to find all the prime numbers up to a certain number. For instance if a user enters in 5, you will find all the prime numbers up to 5. Would 5be included? Yes! It is prime. 1 is not prime. Create a new static method to determine all the prime numbers up to that point.
Here are some notes on the questions. Pseduocode to turn into code.
Due Friday July 18th, 2008.
BetterProgrammer.com
http://www.betterprogrammer.com/
Using Netbeans try this four problems. Save your work in Netbeans and comment your thought process. Even if you don't know how to do something, try your best to use the Internet to figure out the answer!
Using Netbeans try this four problems. Save your work in Netbeans and comment your thought process. Even if you don't know how to do something, try your best to use the Internet to figure out the answer!
Subscribe to:
Posts (Atom)
