# 数学题

http://www.math.ucsb.edu/~cooper/puz1.html

`    /**    * MATH PUZZLE 01    *    * An ant starts at one end of a rubber band and walks along it at a speed    * of 1 inch per second. The rubber band is 10 inches long, and is being    * stretched uniformly at a rate of 20 inches per second. Does the ant ever    * reach the other end of the rubber band?. Give reasons.    */   public void testMathPuzzle01() {       long t = 0;       final long MINUTE = 60, HOUR = MINUTE * 60, DAY = HOUR * 24, YEAR = DAY * 365;       double rubber = 10;       double walked = 0;       while (walked < rubber) {           // After 1 second           t++;           rubber = rubber + 20;           walked = walked * rubber / (rubber - 20) + 1;           if (t % YEAR == 0) {               System.out.println("" + t / YEAR + " years has been flying by");           }       }       System.out.println("Time used:" + t / YEAR + " years, " + t % YEAR               / DAY + " days, " + t % DAY / HOUR + " hours," + t % HOUR               / MINUTE + " minutes," + t % MINUTE + " seconds");   }`

walked = walked * rubber / (rubber - 20) + 1;

walked = (walked + 1) * rubber / (rubber - 20) ;

`  /**    * MATH PUZZLE 09    *    * In a TV show, a prize is hidden behind one of 3 closed doors. The    * contestant tries to guess where the prize is. After the contestant    * chooses a door, the host of the show (who knows where the prize is) opens    * one of the 2 remaining doors, to reveal that the prize is not behind that    * door. The host then gives the contestant the opportunity to change her    * guess. Should she?    */   public void testMathPuzzle09() {       final int SIZE = 100000;       boolean[] doors = new boolean[3];       Random random = new Random();       int insist = 0;       int reselect = 0;       for (int i = 0; i < SIZE; i++) {           // Init doors           doors[0] = doors[1] = doors[2] = false;           int index = random.nextInt(3);           doors[index] = true;           int guess = random.nextInt(3);           // does not change her guess           if (doors[guess] == true) {               insist++;           }           // change her guess           if (doors[guess] == false) {               reselect++;           }       }       System.out.println("Not change will get:" + insist);       System.out.println("Change will get:" + reselect);   } `