Monday, October 31, 2011

CS106B - Free Course from Stanford


CS106B is a free course from Stanford available online. This course is about data structures and recursion.

The latest free video lectures are made last 2011 Spring Quarter and you can access them at ClassX - CS106B: Programming Abstractions. The professor during this quarter is Steve Cooper. You can visit the CS106B's website in this quarter here. All lecture handouts, codes, the course reader, assignments and many other materials for the course are available in the website.

An older set of video lectures are available at SEE (Stanford Engineering Everywhere) - Programming Abstractions. Go to the bottom part of the web page to download the complete course materials.

If you are planning to do the assignments and compile the example codes during the lectures you'll need Visual Studio 2005 and the CS106 Library. If you have Visual Studio 2008 instead, please read Dani's article on how you can make the CS106B Library work with Visual Studio 2008.

Enjoy!

I have done some of the assignments last 2011 Spring Quarter. You can view my solutions here. Please pardon my code because they are not well structured and not commented. Thanks.



  
Free Lessons for Chruch Pianists:
Free lessons, tips and downloads for church pianists

DVD Courses (Reharmonization, Play by Ear!, Arranging, Accompanying, Theory for Church Pianists, etc.):
Over 30 hours of DVD instruction for church pianists
 


Visit Vitabase for Quality Health Supplements


Saturday, October 1, 2011

Your Ride Is Here

This is the problem specification of "Your Ride is Here" from USACO.

It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet which, along with the name of the group, can be used to determine if it is a particular group's turn to go (who do you think names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the names of a group and a comet and then determines whether the group should go with the UFO behind that comet.

Both the name of the group and the name of the comet are converted into a number in the following manner: the final number is just the product of all the letters in the name, where "A" is 1 and "Z" is 26. For instance, the group "USACO" would be 21 * 19 * 1 * 3 * 15 = 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you need to tell the group to get ready! (Remember that "a mod b" is the remainder left over after dividing a by b; 34 mod 10 is 4.)

Write a program which reads in the name of the comet and the name of the group and figures out whether according to the above scheme the names are a match, printing "GO" if they match and "STAY" if not. The names of the groups and the comets will be a string of capital letters with no spaces or punctuation, up to 6 characters long.

Examples:
Input
Output
COMETQ
HVNGAT
GO
ABSTAR
USACO 
STAY

PROGRAM NAME: ride

This means that you fill in your header with:
PROG: ride

INPUT FORMAT

Line 1: An upper case character string of length 1..6 that is the name of the comet.

Line 2: An upper case character string of length 1..6 that is the name of the group.

NOTE: The input file has a newline at the end of each line but does not have a "return". Sometimes, programmers code for the Windows paradigm of "return" followed by "newline"; don't do that! Use simple input routines like "readln" (for Pascal) and, for C/C++, "fscanf" and "fid>>string".


SAMPLE INPUT (file ride.in) 
COMETQ
HVNGAT

OUTPUT FORMAT

A single line containing either the word "GO" or the word "STAY".

SAMPLE OUTPUT (file ride.out)
GO

You can view my solution at PlanetSourceCode.com

 

Validation of viewstate MAC failed - ASP.NET Error




  
Free Lessons for Chruch Pianists:
Free lessons, tips and downloads for church pianists

DVD Courses (Reharmonization, Play by Ear!, Arranging, Accompanying, Theory for Church Pianists, etc.):
Over 30 hours of DVD instruction for church pianists
 



Server Error in '/Login' Application.

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.


What I did to solve this.


I removed the action attribute in the <form> tag.

I changed

<form id="form1" action="DisplayName.aspx" runat="server">

into

<form id="form1" runat="server">

and placed

Response.Redirect("DisplayName.aspx");

in code behind file.

Saturday, September 10, 2011

Milking Cows


This is the problem specification of the Milking Cows Programming Problem From USACO.

Milking Cows

Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer begins milking his cow at time 300 (measured in seconds after 5 am) and ends at time 1000. The second farmer begins at time 700 and ends at time 1200. The third farmer begins at time 1500 and ends at time 2100. The longest continuous time during which at least one farmer was milking a cow was 900 seconds (from 300 to 1200). The longest time no milking was done, between the beginning and the ending of all milking, was 300 seconds (1500 minus 1200).

Your job is to write a program that will examine a list of beginning and ending times for N (1 <= N <= 5000) farmers milking N cows and compute (in seconds):

  • The longest time interval at least one cow was milked.
  • The longest time interval (after milking starts) during which no cows were being milked.

PROGRAM NAME: milk2


INPUT FORMAT

Line 1:
The single integer
Lines 2..N+1:
Two non-negative integers less than 1000000, the starting and ending time in seconds after 0500

SAMPLE INPUT (file milk2.in)

3
300 1000
700 1200
1500 2100

OUTPUT FORMAT

A single line with two integers that represent the longest continuous time of milking and the longest idle time.

SAMPLE OUTPUT (file milk2.out)

900 300
 
 
You can view my solution (source code) to this problem at PlanetSourceCode.com

Sunday, September 4, 2011

When the Siants Go Marching In By Greg Howlett and Andi Leftwich


Greg Howlett - Piano
Andi Leftwich - Fiddle

This is an excerpt from Greg Howlett's "Live in Charleston" DVD.

Click here for Greg Howlett's Explanation of "When the Saints".


Enjoy!

Friday, September 2, 2011

Recursion


This is Assignment #3 of Stanford's CS106B class last Spring Quarter 2011.

It consists of four problems and 2 warm-up problems.
(I only did 3 of the 4 problems because the last one was fairly difficult). Click here here to download the assignment handout.

The link for downloads below might not work. Please use this link to download all solutions to the problems.

Warm-up problem 0a. Binary encoding
Write a recursive function GenerateBinaryCode(nBits) that generates the bit patterns
for the standard binary representation of all integers that can be represented using the
specified number of bits. For example, calling GenerateBinaryCode(3) should produce
the following output:
000
001
010
011
100
101
110
111
Download my solution for Warm-up problem 0a here.
Warm-up problem 0b. Subset sum
The subset sum problem is an important and classic problem in computer theory. Given  a set of integers and a target number, your goal is to find a subset of those numbers that sum to that target number. For example, given the numbers {3, 7, 1, 8, -3} and the target sum 4, the subset {3, 1} sums to 4. On the other hand, if the target value were 2, the result is false since there is no subset that sums to 2.
 Download my solution for Warm-up problem 0b here.
Problem 1. Karel goes home
Your job in this problem is to write a recursive function
int CountPaths(int street, int avenue)
that returns the number of paths Karel could take back to the origin from the specified starting position, subject to the condition that Karel doesn’t want to take any  unnecessary steps and can therefore only move west or south (left or down in the diagram).
 Download my solution for problem 1 here.
 Problem 2. Balancing parentheses
Write a function
bool IsBalanced(string exp);
that takes a string consisting only of parentheses, brackets, and curly braces and returns true or false according to whether that expression has properly balanced operators. (Your function should operate recursively.)
Download my solution for problem 2  here.

Problem 3. Cell phone mind-reading
Write a function
void ListCompletions(string digits, Lexicon & lex);
that prints all words from the lexicon that can be formed by extending the given digit sequence. For example, calling ListCompletions("72547", english) should generate the following sample run:
palisade
palisaded
palisades
palisading
palish
rakis
rakish
rakishly
rakishness
sakis

 Download my solution for problem 3  here.

Problem 4. Stock Cutting
You are charged with buying the plumbing pipes for a construction project. Your
foreman gives you a list of the varying lengths of pipe needed. Home Depot sells stock
pipe in one fixed length. You can divide each stock pipe in any way needed. Your job is
to figure out the minimum number of stock pipes required to satisfy the list of requests,
thereby saving money and minimizing waste.

Your job is to write a recursive function

int CutStock(Vector<int> & requests, int stockLength);

that takes two arguments—a vector of the lengths needed and the length of stock pipe
that Home Depot sells—and returns the minimum number of stock pipes needed to
service all requests in the vector. For example, if the vector contains [ 4, 3, 4, 1, 7, 8 ]
and the stock pipe length is 10, you can purchase three stock pipes and divide them as
follows:

Pipe 1: 4, 4, 1
Pipe 2: 3, 7
Pipe 3: 8

Doing so leaves you with two small remnants left over. There are other possible
arrangements that also fit into three stock pipes, but it cannot be done with fewer.

Download my solution for problem 4 here or  here.
Happy coding!!!

Tuesday, August 30, 2011

Simple Project in Assembly Language - Menu


This was supposed to be my project in assembly language. (The truth is, I have never tried to master assembly language programming and I have already forgotten how the code below works. LOL! But I'm going to share it anyway.)

I thought I did not have a copy of this but I found a copy on my previous blog.

They called this "Menu"

The code below is just part of the program. Download the whole program here or here. 
This should be assembled using the A86 Assembler by  Eric Isaacson.


Enjoy!

start:
    ;set video mode
                mov     AH, 00h     ; I want to set the video mode...
                mov     AL, 03h     ; ...to 80x25x16
                int     10h         ; Call video interrupt

    call clear_screen

    ;--------------------------display choices
    mov ah, 09
    lea dx, box1
    int 21h
    

    mov ah, 09
    lea dx, choice
    int 21h
    

    call crlf

    mov ah, 09
    lea dx, choice1
    int 21h

    call crlf
    
    mov ah, 09
    lea dx, choice2
    int 21h

    call crlf   

    mov ah, 09
    lea dx, choice3
    int 21h

    call crlf 
    
    mov ah, 09
    lea dx, choice4
    int 21h
    
    call crlf 
    
    mov ah, 09
    lea dx, choice5
    int 21h
    
    call crlf 
    
    mov ah, 09
    lea dx, choice6
    int 21h

    call crlf 
    
    mov ah, 09
    lea dx, choice7
    int 21h

    call crlf

    mov ah, 09
    lea dx, box2
    int 21h
    

    call crlf

    ;-----------------prompt user of letters a-f or z
    call crlf
    call crlf 
    
    mov ah, 09
    lea dx, prompt
    int 21h

    ;---------------get input character
    mov ah, 01
    int 21h

    ;----compare input character with... and execute chosen subprogram
    cmp al, '1'
    je one
    cmp al, '2'
    je two
    cmp al, '3'
    je three
    cmp al, '4'
    je four    
    cmp al, '5'
    je five    
    cmp al, '6'
    je six
    cmp al, '0'
    je endendend
    
    ;-------------------no match
    mov ah, 09
    lea dx, no_match
    int 21h

    call crlf
    call crlf
    jmp next

     jmp start
one:
    call crlf 
    call crlf 
    call display_biodata_with_border   
    jmp next
two:
    call crlf 
    call crlf 
    call reverse_string
    jmp next
three:
    call crlf 
    call crlf
    call password
    jmp next
four:
    call crlf 
    call crlf
    call horizontal
    call crlf 
    call crlf    
    call crlf 
    call crlf
    call crlf 
    call crlf
    call crlf 
    call crlf

    jmp next
five:
    call crlf 
    call crlf
    call quadrant
    jmp next    
six:
    call crlf 
    call crlf
    call addition
    jmp next
endendend:
    jmp ending

;-------------------press any key to continue
next:
    mov ah, 09
    lea dx, Press_anyKey
    int 21h
    
    mov ah, 01
    int 21h
      
      cmp al, '0'
      je endendend

    
    call crlf 
    call crlf
    call crlf 

    ;set video mode
                mov     AH, 00h     ; I want to set the video mode...
                mov     AL, 03h     ; ...to 80x25x16
                int     10h         ; Call video interrupt

    call clear_screen
    
    jmp start

ending:
    mov ah, 09
    lea dx, closing
    int 21h

    ret