/** Copyright Henry Bottomley May 1999*/ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.lang.Math; public class Cdown extends Applet implements ActionListener {TextField box0, box1, box2, box3, box4, box5, targetbox, messagebox; int i=0; int j=0; int target=0; int[] possib = {1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,25,50,75,100}; int[] select = {0,0,0,0,0,0}; int[] tools = {0,0,0,0,0,0}; int[] fun = {0,0,0,0,0,0}; int[] higher = {0,0,0,0,0,0}; int[] lower = {0,0,0,0,0,0}; int[] k = {0,0,0,0,0,0}; int[] sorted={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; String[] formula={"","","","","","","","","","","","","","","","","","","","",""}; String[] symbol={"+", "-", "*", "/"}; int bestsofar=0; int level=0; int thiscalc=0; int done=0; int domore=0; String newform=""; String bestform=""; public void init() {Button generate = new Button("Generate"); generate.addActionListener(this); add (generate); box0 = new TextField(4); box1 = new TextField(4); box2 = new TextField(4); box3 = new TextField(4); box4 = new TextField(4); box5 = new TextField(4); add (box0); add (box1); add (box2); add (box3); add (box4); add (box5); targetbox = new TextField(8); add (targetbox); Button calculate = new Button("Calculate"); calculate.addActionListener(this); add (calculate); messagebox = new TextField(60); add (messagebox); } public void actionPerformed(ActionEvent event) {String arg=event.getActionCommand(); if (arg=="Generate") {for (i=0; i<6; i++) {select[i] = possib[i]; } for (i=6; i<19; i++) {if (Math.random()*(i+1) < 6) {select[(int)(Math.random()*6.0)] = possib[i]; } } box0.setText(""+select[0]); box1.setText(""+select[1]); box2.setText(""+select[2]); box3.setText(""+select[3]); box4.setText(""+select[4]); box5.setText(""+select[5]); targetbox.setText(""+(int)((Math.random()*900)+100)); messagebox.setText(""); } if (arg=="Calculate") {tools[0]=Integer.parseInt(box0.getText().trim()); tools[1]=Integer.parseInt(box1.getText().trim()); tools[2]=Integer.parseInt(box2.getText().trim()); tools[3]=Integer.parseInt(box3.getText().trim()); tools[4]=Integer.parseInt(box4.getText().trim()); tools[5]=Integer.parseInt(box5.getText().trim()); target=Integer.parseInt(targetbox.getText().trim()); for (i=0; i<6; i++) { k[i]=0; for (j=0; j<6; j++) {if ((tools[i]) < tools[j] || (tools[i]==tools[j] && i