Tuesday, June 10, 2014

Control Observer

import java.util.*;

/**
 * Description   : ControlCommand, interface for processing commands
 * @author dbauman
 * @since   Jun 11, 2004
 *      Jun 11, 2004    (DBauman) Original Release
 */

public interface ControlCommand {
    public boolean processCommand(ControlProcessing controlProcessing);
}


import java.util.*;

/**
 * Description   : ControlCommandAbstract, holds the parameters, implements ControlCommand
 * @author dbauman
 * @since   Jun 11, 2004
 *      Jun 11, 2004    (DBauman) Original Release
 */

public abstract class ControlCommandAbstract implements ControlCommand {

    protected boolean debug = true;
    
    private ControlParameters controlParameters;
    public ControlParameters getControlParameters() {return controlParameters;}
    public ControlCommandAbstract(ControlParameters controlParameters) {
        this.controlParameters = controlParameters;
    }

}



import java.util.*;

/**
 * Description   : ControlCommandExit, exit command
 * @author dbauman
 * @since   Jun 11, 2004
 *   Jun 11, 2004    (DBauman) Original Release
 */

public class ControlCommandExit extends ControlCommandAbstract {
    public ControlCommandExit(ControlParameters controlParameters) {
        super(controlParameters);
    }
    public boolean processCommand(ControlProcessing controlProcessing) {
        ControlParameters controlParameters = getControlParameters();
        if (debug) System.out.println("Exit");
        System.exit(0);
        return true;
    }
}




import java.util.*;

/**
 * Description   : ControlCommandGetItem, get item command
 * @author dbauman
 * @since   Jun 11, 2004
 *      Jun 11, 2004    (DBauman) Original Release
 */

public class ControlCommandGetItem extends ControlCommandAbstract {
    public ControlCommandGetItem(ControlParameters controlParameters) {
        super(controlParameters);
    }
    public boolean processCommand(ControlProcessing controlProcessing) {
        ControlParameters controlParameters = getControlParameters();
        if (!controlParameters.hasNext()) return false;
        String map = (controlParameters.nextToken()).trim();
        if (!controlParameters.hasNext()) return false;
        String section = (controlParameters.nextToken()).trim();
        if (!controlParameters.hasNext()) return false;
        String item = (controlParameters.nextToken()).trim();
        if (debug) System.out.println("getitem: "+map+", "+section+", "+item);
        String val = "itemValue";
        // DO THE WORK HERE!!!
        // val = helper.getAppMapItem(map, section, item);

        // we can cast because we know that we are of this 'interface' type
        ((ControlProcessingUI1)controlProcessing).setAppMapItem(val);
        return true;
    }
}




import java.util.*;

/**
 * Description   : ControlCommandOpenMap, open map command
 * @author dbauman
 * @since   Jun 11, 2004
 *      Jun 11, 2004    (DBauman) Original Release
 */

public class ControlCommandOpenMap extends ControlCommandAbstract {
    public ControlCommandOpenMap(ControlParameters controlParameters) {
        super(controlParameters);
    }
    public boolean processCommand(ControlProcessing controlProcessing) {
        ControlParameters controlParameters = getControlParameters();
        if (!controlParameters.hasNext()) return false;
        String map = (controlParameters.nextToken()).trim();
        if (debug) System.out.println("Openmap: "+map);
        String statusCode = "OK";
        // DO THE WORK HERE!!!
        // statusCode = helper.openMap(map);
        try { // simulate that the commands takes real time
            Thread.sleep(3000);
        } catch (InterruptedException ie) {}
        //
        // we can cast because we know that we are of this 'interface' type
        ((ControlProcessingUI1)controlProcessing).setStatusCode(statusCode);
        return true;
    }
}




import java.util.*;

/**
 * Description   : ControlObservable, extends Observable, implements Runnable.
 * This is the 'other thread' which sends data to the Control portion.
 * Implement Runnable so that our 'run' method can be the result of
 * starting another Thread so that the controler/Observer can receive the notification
 * messages without blocking.
 * This class does all of the thread stuff, including the 'synchronizing'
 * @author dbauman
 * @since   DEC 17, 2003
 *      DEC 17, 2003    (DBauman) Original Release
 *      DEC 17, 2003    (DBauman) we also
 *   implement ControlProcessing so that we can tell the GUI when we are done processing.
 */

public class ControlObservable extends Observable implements Runnable {

  private ControlProcessing controlProcessing;

  /** constructor, starts our thread **/
  ControlObservable (ControlProcessing controlProcessing) {
    this.controlProcessing = controlProcessing;
    // start the processing thread
    new Thread(this).start();
  }

  /** a queue of commands to notify the observer with.
   ** The observer is on another thread, so we use this to
   ** pass the commands from one thread to another.
   **/
  private ArrayList cmds = new ArrayList();

  public boolean isEmpty () {
    return cmds.isEmpty(); // no need to be sychronized
  }

  public void addCommand (Object cmd) {
    synchronized(cmds) {
      cmds.add(cmd);
    }
  }


  /** Purpose: run method of another thread. Used
   ** solely by the notifyOurObserver method via the 'cmds'.  It is best to keep
   ** the observer (controller) in a separate thread from the GUI (view) because
   ** if the user presses a button twice during a test then nothing will happen.
   * Side Effects: 'cmds', a command is grabbed from this queue
   * State Read:   'cmds'
   * Assumptions:  We sleep for 100 ms between commands inside an infinite loop.
   **/
  public void run () {
    for(;;) {
      Object next = null;
      if (!cmds.isEmpty()) { // do this twice for efficiency
        synchronized(cmds) {
          if (!cmds.isEmpty()) { // have to do here inside the 'synchronized' at the very least
            next = cmds.get(0);
          }
        }
      }
      if (next != null) {
        setChanged();
        notifyObservers(next);
        clearChanged();
      }
      boolean empty = false;
      synchronized(cmds) {
        if (!cmds.isEmpty()) {
          cmds.remove(0); // finally remove the element
        }
        empty = cmds.isEmpty();
      }
      // processing complete, based on 'empty' flag
      // make sure not to do this inside the 'sychronized' block because it could be slow
      controlProcessing.processingComplete(empty);

      try {
        Thread.sleep(100);
      } catch (InterruptedException ie) {}
    }
  }
}



import java.io.*;
import java.util.*;
import java.lang.reflect.*;

/**
 * Description   : ControlObserver, used to control something, and acts as an observer
 * @author dbauman
 * @since   DEC 15, 2003
 *   DEC 15, 2003    (DBauman) Original Release
 * a controller : it uses Class.forName to load the 'instanceName' class which is the Observable
 * to our Observer.  Our 'update' method gets the commands from
 * that GUI and executes them.
 */

public class ControlObserver extends ControlObserverUpdate {
  /** the instance name of the GUI **/
  public static String instanceName = "ControlObservableUI";


  /** Purpose: main method
   * @param                     args, String[],
   * 
args[0]: can be: *
instanceName **/ public static void main (String[] args) { ControlObserver control = new ControlObserver(); if (args.length>0) { control.instanceName = args[0]; } System.out.println("instanceName (for GUI class): "+instanceName); control.debug = true; control.instanceGui(instanceName); control.start(); } }

import java.io.*;
import java.util.*;
import java.lang.reflect.*;

/**
 * Description   : ControlObserver, used to control something, and acts as an observer, abstract method to be extended
 * @author dbauman
 * @since   DEC 15, 2003
 *      DEC 15, 2003    (DBauman) Original Release
 *      Jun 11, 2004    (DBauman) was moved to this class
 * abstract reusable part of our controller : it uses Class.forName to load the 'instanceName' class which is the Observable
 * to our Observer.  Our 'update' method gets the commands from
 * that GUI and executes them.
 *
 */

public abstract class ControlObserverUpdate implements Observer {
  protected boolean debug=false;
  protected ControlProcessing instance = null;

  public void start() {
      instance.start();
  }
  /** Tries to instance a Gui
   * @param                     instanceName, String
   * @return instance
   **/
  public ControlProcessing instanceGui (String instanceName) {
    String methodName = "ControlObserver.instanceGui: ";
    try { // next try using Class.forName...
      if (debug) System.out.println(methodName+"trying :"+instanceName);
      Class guiClass = Class.forName(instanceName);
      if (debug) System.out.println(methodName+"guiClass: "+guiClass.getName());
      instance = (ControlProcessing) guiClass.newInstance();
      instance.addObserver(this);
      return instance;
    } catch (NoClassDefFoundError nc) {
      System.err.println(methodName+"no class definition found: "+instanceName);
    } catch (ClassCastException cc) {
      System.err.println(methodName+"can't Cast class: "+instanceName);
    } catch (InstantiationException ie) {
      System.err.println(methodName+"can't instantiate class: "+instanceName);
    } catch (ClassNotFoundException ex) {
      System.err.println(methodName+"can't find class: "+instanceName);
    } catch (IllegalAccessException iae) {
      System.err.println(methodName+iae.toString());
    }
    return null;
  }

  /** 
Purpose: this class is called when a GUI sends us data * @param obs, Observable * @param arg, Object **/ public void update(Observable obs, Object arg) { ControlParameters st = (ControlParameters) arg; ControlCommand command = st.getCommand(); if (debug) System.out.println("NEXT: "+command); boolean result = command.processCommand(instance); if (debug) System.out.println("RESULT: "+result); } }


import java.util.*;

/**
 * Description   : ControlParameters, contains objects passed to the control
 * @author dbauman
 * @since   DEC 17, 2003
 *
 *     DEC 17, 2003    (DBauman) Original Release
 */

public class ControlParameters {
  private ControlCommand command;
  public ControlCommand getCommand() {iterator=params.iterator(); return command;}
  public void setCommand(ControlCommand command) {this.command=command;}
  private Collection params = new LinkedList();
  private Iterator iterator;
  public void addParam(Object param) {params.add(param);}
  public boolean hasNext () {return iterator.hasNext();}
  public Object next() {return iterator.next();}
  public String nextToken() {return (String)next();}
}






import java.util.*;

/**
 * Description   : ControlProcessing interface, can indicate when processing is complete
 * @author dbauman
 * @since   DEC 17, 2003
 *      DEC 17, 2003    (DBauman) Original Release
 */

public interface ControlProcessing {

  public void processingComplete (boolean pc);
  /** pass along to 'controlObservable'
   ** with a line like this: 
   ** controlObservable.addObserver(observer); 
**/ public void addObserver(Observer observer); public void start(); }



public interface ControlProcessingUI1 extends ControlProcessing {
  /** set the text of the 'statusCode' text field **/
  public void setStatusCode(String status);
  /** set the text of the 'appMapItem' text field **/
  public void setAppMapItem(String val);
}






import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

/**
 * Description   : ControlObservableUI, used to control an engine by sending step commands.
 * This is the GUI, we contain an Observable (instance of ControlObservable).
 * When our buttons are pressed, we send commands to the Observer (Controller)
 * Implement ActionListener so that our actionPerformed method can
 * react to the buttons.
 * Implement Runnable so that our 'run' method can be the result of
 * starting another Thread so that the controler/Observer can receive the notification
 * messages without blocking our GUI thread.
 * @author dbauman
 * @since   DEC 15, 2003
 *      DEC 15, 2003    (DBauman) Original Release
 *      DEC 17, 2003    (DBauman) changed to contain an ControlObservable.
 */

public class ControlObservableUI implements ActionListener, ControlProcessingUI1 {

  /** set the text of the 'statusCode' text field **/
  public void setStatusCode(String status) {this.statusCode.setText(status);}
  /** set the text of the 'appMapItem' text field **/
  public void setAppMapItem(String val) {this.appMapItem.setText(val);}

  /** startup the observable thread **/
  private ControlObservable controlObservable = new ControlObservable(this);

  /** all of the GUI elements **/
  private JFrame frame;
  private JPanel top;
  private JLabel lab7;
  private JTextField map;
  private JTextField section;
  private JTextField item;
  private JTextField appMapItem;
  private JTextField statusCode;
  public static final String CENTER = "Center";
  private String BUSY = "Please wait until the last command is finished.";
  private static final String BLANKSPACE = "                    ";
  private String lab7text = "Processing Command";
  private String lab7tail= "..."+BLANKSPACE;
  /**Construct the Panel*/
  public ControlObservableUI() {
    top = new JPanel();
    Dimension dim = new Dimension(588, 160);
    top.setSize(dim);
    top.setPreferredSize(dim);
    JPanel panC = new JPanel();
    panC.setBorder(BorderFactory.createTitledBorder("Application Map"));
    JPanel pan8 = new JPanel();
    JPanel pan9 = new JPanel();
    JPanel pan10 = new JPanel();
    JPanel pan11 = new JPanel();
    JPanel pan12 = new JPanel();
    JPanel pan13 = new JPanel();
    lab7 = new JLabel(BLANKSPACE);
    JLabel lab5 = new JLabel("Application Map"+": ");
    JLabel lab10 = new JLabel("Status Code"+": ");
    JLabel lab11 = new JLabel("Section"+": ");
    JLabel lab12 = new JLabel("Item"+": ");
    JLabel lab13 = new JLabel("Item Value"+": ");
    map = new JTextField();
    section = new JTextField();
    item = new JTextField();
    appMapItem = new JTextField();
    statusCode = new JTextField();
    map.setColumns(28);
    section.setColumns(28);
    item.setColumns(28);
    appMapItem.setColumns(28);
    statusCode.setColumns(28);
    JButton b2 = new JButton("OpenMap");
    JButton b3 = new JButton("Clear");
    JButton b4 = new JButton("Exit");
    JButton b6 = new JButton("Get Item");
    JButton b6b = new JButton("Get Item Now");
    b2.setActionCommand("OpenMap");
    b2.addActionListener(this);
    b3.setActionCommand("Clear");
    b3.addActionListener(this);
    b4.setActionCommand("Exit");
    b4.addActionListener(this);
    b6.setActionCommand("GetItem");
    b6.addActionListener(this);
    b6b.setActionCommand("GetItemNow");
    b6b.addActionListener(this);
    panC.setLayout(new BoxLayout(panC, BoxLayout.Y_AXIS));
    pan8.setLayout(new BoxLayout(pan8, BoxLayout.X_AXIS));
    pan9.setLayout(new BoxLayout(pan9, BoxLayout.X_AXIS));
    pan10.setLayout(new BoxLayout(pan10, BoxLayout.X_AXIS));
    pan11.setLayout(new BoxLayout(pan11, BoxLayout.X_AXIS));
    pan12.setLayout(new BoxLayout(pan12, BoxLayout.X_AXIS));
    pan13.setLayout(new BoxLayout(pan13, BoxLayout.X_AXIS));
    pan8.add(lab5, CENTER);
    pan8.add(map, CENTER);
    pan9.add(lab11, CENTER);
    pan9.add(section, CENTER);
    pan10.add(lab12, CENTER);
    pan10.add(item, CENTER);
    pan11.add(lab13, CENTER);
    pan11.add(appMapItem, CENTER);
    pan12.add(lab10, CENTER);
    pan12.add(statusCode, CENTER);
    pan13.add(lab7, CENTER);
    pan13.add(b2, CENTER);
    pan13.add(b3, CENTER);
    pan13.add(b4, CENTER);
    pan13.add(b6, CENTER);
    pan13.add(b6b, CENTER);
    top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS));
    top.add(panC);
    panC.add(pan8);
    panC.add(pan9);
    panC.add(pan10);
    panC.add(pan11);
    panC.add(pan12);
    panC.add(pan13);
  }

  /** starts up the frame and adds the 'top' component to it;
   ** also starts up the observable thread (ControlObservable)
   **/
  public void start () {
    System.out.println("start");
    frame = new JFrame("ControlObservableUI");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
          //notifyOurObserver("Exit");
          System.exit(1); // for the impatient user, otherwise would have to wait for cmd
        }
      });
    frame.getContentPane().add(top, CENTER);
    frame.pack();
    frame.setVisible(true);
  }

  /** pass along to 'controlObservable'**/
  public void addObserver(Observer observer) {
    System.out.println("adding: "+observer);
    controlObservable.addObserver(observer);
    System.out.println("done adding: "+observer);
  }

  /** show an information popup dialog using JOptionPane
   ** @param msg, String
   **/
  public void popupMessage (String msg) {
    JOptionPane.showMessageDialog(frame, msg,
                                  msg, JOptionPane.INFORMATION_MESSAGE);
  }

  /** processing complete will be called by ControlObservable class run thread **/
  public void processingComplete (boolean pc) {
    if (lab7 != null) {
      if (pc) {
        lab7.setText(BLANKSPACE);
      } else {
        lab7.setText(lab7text + lab7tail);
      }
    }
  }

  /** notify the observers by placing 'cmd' on the 'cmds' queue
   ** @param cmd, String
   **/
  private void notifyOurObserver (Object cmd) {
    lab7.setText(lab7text + lab7tail);
    controlObservable.addCommand(cmd);
  }
  /** notify the observers of the event.getActionCommand()
   ** with the params
   **/
  public void actionPerformed(ActionEvent event) {
    ControlParameters buf = new ControlParameters();
    if (event.getActionCommand().equalsIgnoreCase("OpenMap")) {
      if (!controlObservable.isEmpty()) {popupMessage(BUSY); return;}
      buf.setCommand(new ControlCommandOpenMap(buf));
      buf.addParam(map.getText());
    } else if (event.getActionCommand().equalsIgnoreCase("GetItem")) {
      if (!controlObservable.isEmpty()) {popupMessage(BUSY); return;}
      buf.setCommand(new ControlCommandGetItem(buf));
      buf.addParam(map.getText());
      buf.addParam(section.getText());
      buf.addParam(item.getText());
    } else if (event.getActionCommand().equalsIgnoreCase("GetItemNow")) {
        //if (!controlObservable.isEmpty()) {popupMessage(BUSY); return;}
      buf.setCommand(new ControlCommandGetItem(buf));
      buf.addParam(map.getText());
      buf.addParam(section.getText());
      buf.addParam(item.getText());
    } else if (event.getActionCommand().equalsIgnoreCase("Clear")) {
      map.setText("");
      section.setText("");
      item.setText("");
      statusCode.setText("");
      appMapItem.setText("");
      return; // because we don't need to 'notify'
    } else if (event.getActionCommand().equalsIgnoreCase("Exit")) {
      if (!controlObservable.isEmpty()) {popupMessage(BUSY); return;}
      buf.setCommand(new ControlCommandExit(buf));
    } 
    notifyOurObserver(buf);
  }

}

Friday, June 6, 2014

Updated for 2014: Pi to any precision ported to Dart





It used to take 7 to 10 seconds to do 1000 digits of Pi on my machine with the original version of Dart, which is was based on javascript.

The new version of dart (c. 2014) now calcuates 3500 digits of Pi in 1.88 seconds. My Java version is only slightly faster, 3500 digits of PI in 1.39 seconds.

Douglas Bauman
/** Pi
 * I found an old C program which 
 * prints out lots of digits of pi.
 * I ported it to java (and now to dart)
 *  © 2011 - © 2014 Douglas A. Bauman
 * Here it is in case you are interested.
 * -Doug
 */

class Pi {
 
    static final int MAXPRC = 20000;
    StringBuffer bufDigits;
    StringBuffer buf;
    StringBuffer bufTime;
    List<int> p; // = new List<int>(MAXPRC); // byte[]
    List<int> t; // = new List<int>(MAXPRC); // byte[]
    int q;

    Pi(){
    }

    setQ(int q) {
        this.q = q;
        bufDigits = new StringBuffer();
        bufDigits.write("digits: "+q.toString());
        buf = new StringBuffer();
        bufTime = new StringBuffer();
    }

    arctan(int s) {
        int n;
        t[0] = 1;
        div6(s);   /* t[] = 1/s */
        add5();
        n = 1;
        do {
            mul7(n);
            div6(s * s);
            div6(n += 2);
            if (((n-1) / 2) % 2 == 0) {
                add5();
            } else {
                sub8();
            }
        } while (!tiszero());
    }
 
    add5() {
        int j;
        for (j = q; j >= 0; j--) {
            if (t[j] + p[j] > 9) {
                p[j] += t[j] - 10;
                if (j>=0) p[j-1] += 1;
            } else {
                p[j] += t[j];
            }
        }
    }
 
    sub8() {
        int j;
        for (j = q; j >= 0; j--) {
            if (p[j] < t[j]) {
                p[j] -= t[j] - 10;
                if (j>=0) p[j-1] -= 1;
            } else {
                p[j] -= t[j];
            }
        }
    }
 
    mul7(int multiplier) {
        int b;
        int i;
        num carry=0;
        int digit = 0;
        for (i = q; i >= 0; i--) {
            b = (t[i] * multiplier + carry);
            digit = b % 10;
            carry = (b / 10).floor();
            t[i] = digit; //(byte)
        }
    }
    
    /* t[] /= l */
    div6(int divisor) {
        int i, b;
        num quotient, remainder = 0;
        for (i = 0; i <= q; i++) {
            b = (10 * remainder + t[i]);
            quotient = (b / divisor).floor();
            remainder = b % divisor;
            t[i] = quotient; // (byte)
        }
    }
    
    div4() {
        int i=0, d = 0;
        num c=0;
        for (; i <= q; i++) {
            c = ((10 * d + p[i]) / 4).floor();
            d = (10 * d + p[i]) % 4;
            p[i] = c; // (byte)
        }
    }
    
    mul4() {
        int i;
        num d=0;
        num c=0;
        for (i = q; i >= 0; i--) {
            d = (p[i] * 4 + c) % 10;
            c = (p[i] * 4 + c) / 10;
            p[i] = d.floor(); // (byte)
        }
    }
    
    bool tiszero() {
        int k;
        for (k = 0; k <= q; k++)
            if (t[k] != 0)
                return(false);
        return(true);
    }

    compute() {
        int i;
        print(getAppletInfo());
        print("..compute..");
        if (q > MAXPRC) {
            buf.write("Precision too large: "+q.toString()+", >MAX: "+MAXPRC.toString());
            return;
        }
 
        /* compute pi */
        p = new List<int>(MAXPRC+1);
        t = new List<int>(MAXPRC+1);
        for(int ii=0; ii<=q; ii++) {p[ii]=0; t[ii]=0;}

        DateTime startime = new DateTime.now();
        print("..arctan(2)..");
        arctan(2);
        print("..arctan(3)..");
        arctan(3);
        print("..mul..");
        mul4();

        DateTime endtime = new DateTime.now();
        Duration diff = endtime.difference(startime);
 
        /* print pi */
        bufTime.write(""+diff.toString()+
          " seconds to compute "+q.toString()+" digits of pi");
        print(bufDigits.toString());

        print("pi = ");
        i = 0;
        int km = 79;
        int f = 1;
        do {
          for (int k=0; i <= q && k < km; i++, k++) {
            buf.write(""+(p[i]==null?"?":p[i].toString()));
            if (i==0) buf.write(".");
          }
          print(buf.toString());
          buf = new StringBuffer();
          km+= f;
          f=0;
        } while (i <= q);

        print(buf.toString());
        print(bufTime.toString());
    }
    
    String getAppletInfo() {
        return "Pi by Douglas A. Bauman";
    }
}
main() {
    int q = 3500;
    print("calculating Pi for " + q.toString() + " digits...");
    Pi pi = new Pi();
    pi.setQ(q);
    pi.compute();

}

output:
calculating Pi for 3500 digits...
Pi by Douglas A. Bauman
..compute..
..arctan(2)..
..arctan(3)..
..mul..
digits: 3500
pi = 
3.141592653589793238462643383279502884197169399375105820974944592307816406286208
99862803482534211706798214808651328230664709384460955058223172535940812848111745
02841027019385211055596446229489549303819644288109756659334461284756482337867831
65271201909145648566923460348610454326648213393607260249141273724587006606315588
17488152092096282925409171536436789259036001133053054882046652138414695194151160
94330572703657595919530921861173819326117931051185480744623799627495673518857527
24891227938183011949129833673362440656643086021394946395224737190702179860943702
77053921717629317675238467481846766940513200056812714526356082778577134275778960
91736371787214684409012249534301465495853710507922796892589235420199561121290219
60864034418159813629774771309960518707211349999998372978049951059731732816096318
59502445945534690830264252230825334468503526193118817101000313783875288658753320
83814206171776691473035982534904287554687311595628638823537875937519577818577805
32171226806613001927876611195909216420198938095257201065485863278865936153381827
96823030195203530185296899577362259941389124972177528347913151557485724245415069
59508295331168617278558890750983817546374649393192550604009277016711390098488240
12858361603563707660104710181942955596198946767837449448255379774726847104047534
64620804668425906949129331367702898915210475216205696602405803815019351125338243
00355876402474964732639141992726042699227967823547816360093417216412199245863150
30286182974555706749838505494588586926995690927210797509302955321165344987202755
96023648066549911988183479775356636980742654252786255181841757467289097777279380
00816470600161452491921732172147723501414419735685481613611573525521334757418494
68438523323907394143334547762416862518983569485562099219222184272550254256887671
79049460165346680498862723279178608578438382796797668145410095388378636095068006
42251252051173929848960841284886269456042419652850222106611863067442786220391949
45047123713786960956364371917287467764657573962413890865832645995813390478027590
09946576407895126946839835259570982582262052248940772671947826848260147699090264
01363944374553050682034962524517493996514314298091906592509372216964615157098583
87410597885959772975498930161753928468138268683868942774155991855925245953959431
04997252468084598727364469584865383673622262609912460805124388439045124413654976
27807977156914359977001296160894416948685558484063534220722258284886481584560285
06016842739452267467678895252138522549954666727823986456596116354886230577456498
03559363456817432411251507606947945109659609402522887971089314566913686722874894
05601015033086179286809208747609178249385890097149096759852613655497818931297848
21682998948722658804857564014270477555132379641451523746234364542858444795265867
82105114135473573952311342716610213596953623144295248493718711014576540359027993
44037420073105785390621983874478084784896833214457138687519435064302184531910484
81005370614680674919278191197939952061419663428754440643745123718192179998391015
91956181467514269123974894090718649423196156794520809514655022523160388193014209
37621378559566389377870830390697920773467221825625996615014215030680384477345492
02605414665925201497442850732518666002132434088190710486331734649651453905796268
56100550810665879699816357473638405257145910289706414011097120628043903975951567
71577004203378699360072305587631763594218731251471205329281918261861258673215791
98414848829164470609575270695722091756711672291098169091528017350671274858322287
18352093539657251210835791513698820914442100675103346711031336

0:00:01.846000 seconds to compute 3500 digits of pi