Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Monday, June 28, 2010

Dear Wimbledon

If you watched the Isner-Mahut match, you'll know that the scoreboard malfunctioned late in the fifth set. That doesn't make sense, so I'll offer some pseudocode for the new upgrade that might come up.

set = [0,0] //Set won by each player




games_won = [0,0] //Games won for the current set




current_set = 1 //which set we're tracking


updateNumber() //assuming there's a function for updating the number with
//syntax as (player number, set) and adds one to the game


while (set[0] != 3 || set[1] != 3):
while abs(games_won[0] - games_won[1]) < 1 :
temp = int(input("who won the game?")) //assuming the referee inputs stuff corectly
updateNumber(temp, current_set)
set[temp] += 1
current_set += 1


print "Player " temp+1 " is the winner!"

You're welcome Wimbledon.

(... hmm there might be a bug in there somewhere....)

-runiteking1

Got comments? Post them below!

Monday, June 22, 2009

My USACO Solutions: Your Ride is Here

I decided to do the USACO training program over the summer. Meanwhile, the darn program has all their solutions/analysis in C++, which I don't do... so I'm posting my solutions here for 1. Just for the heck of it and 2. So other people can tell me what I can do better

import java.util.*;
import java.io.*;

public class ride 
{
 public static void main(String [] args) throws IOException {
  
     BufferedReader f = new BufferedReader(new FileReader("ride.in"));
     PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ride.out")));
    
     String comet = f.readLine();
     String group = f.readLine();
  
  //I didn't know if java has the ord() or char() function like python does
  //and I'm too lazy to find out. Besides, this is easier to understand
     String[] list_alpha = {"A","B","C","D","E","F","G","H","I","J","K","L",
   "M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
     ArrayList list = new ArrayList(Arrays.asList(list_alpha));
     
     int comet_num=1;
     int group_num=1;
     
  //At the time of submission, I split the loop to two for loops... >.>
  //didn't realize that they were same length
     for (int x = 0 ; x < comet.length() ; x++)
     {
      comet_num *= list.indexOf((comet.substring(x, x+1)))+1;
   group_num *= list.indexOf((group.substring(x, x+1)))+1;
     }
     
     if ((comet_num % 47) == (group_num % 47)){
      out.println("GO");
     }
     
     else out.println("STAY");
     
     out.close();
     System.exit(0);
 }
}
-runiteking1 Got comments? Post them below!