Hanoi void TowersOfHanoi(int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter from the stack specified by the // second parameter to the stack specified by the third // parameter. The stack specified by the fourth parameter // is avaialable for use as a spare. if (disks == 1) { // There is only one disk to be moved. Just move it. console.putln("Move a disk from stack number " + from + " to stack number " + to); } else { // Move all but one disk to the spare stack, then move the bottom disk, then put all the // other disks on top of it. TowersOfHanoi(disks-1, from, spare, to); console.putln("Move a disk from stack number " + from + " to stack number " + to);
63
Embed
Hanoi void TowersOfHanoi(int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Hanoivoid TowersOfHanoi(int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter from the stack specified by the // second parameter to the stack specified by the third // parameter. The stack specified by the fourth parameter // is avaialable for use as a spare. if (disks == 1) { // There is only one disk to be moved. Just move it. console.putln("Move a disk from stack number " + from + " to stack number " + to); } else { // Move all but one disk to the spare stack, then move the bottom disk, then put all the // other disks on top of it. TowersOfHanoi(disks-1, from, spare, to); console.putln("Move a disk from stack number " + from + " to stack number " + to); TowersOfHanoi(disks-1, spare, to, from); } }
Labirinto
Inseguitorepublic class Utils { /** readFile */ public static String readFile(String file) { String str = new String(""); char buf[] = new char[8192]; try { FileReader fin = new FileReader(file); while(fin.read(buf) != -1) str += new String(buf); } catch(Exception e) { str = "Eccezione rilevata: " + e + "<br>"; } return str; }
/** replace */ public static String replace(String str, String source, String dest) { int index = 0, lunghSource = source.length();
while ( (index = str.indexOf(source,index)) != -1) { str = str.substring(0,index) + dest + str.substring(index+lunghSource); index += dest.length(); } return str; }
/** * getYear: from a date (source format indicated by flag) */ public static int getYear(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(0,4)); else return 0; } catch(Exception e) {} return 0; }
/** * getMonth: from a date (source format indicated by flag) */ public static int getMonth(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(5,7)); else return 0; } catch (Exception e) {} return 0; }
/** * getDay: from a date (source format indicated by flag) */ public static int getDay(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(8,10)); else return 0; } catch(Exception e) {} return 0; }
/** * getHour: from a date * (source format indicated by flag) */ public static int getHour(String date, int flag){ try { if (flag == 0) return Integer.parseInt(date.substring(11,13)); else return 0; } catch(Exception e) {} return 0; }
/** * getMinutes: from a date (source format indicated by flag) */ public static int getMinutes(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(14,16)); else return 0; } catch (Exception e) {} return 0; }
/** * formatDate */ public static String formatDate(String date, int flag) { String strHour; String strMin; int h = Utils.getHour(date,0); if (h < 10) strHour = "0"+h; else strHour = "" + h; int m = Utils.getMinutes(date,0); if (m < 10) strMin = "0"+m; else strMin = ""+m; if (flag == 0) return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0)+
" "+strHour+":"+strMin; if (flag == 1) return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0);
/** * Interface for timer functions * * @author Ignazio Locatelli - Media Illusion - (C) 2000 */
package it.MediaIllusion.Anim;
public interface TimerInterface { public void tick();}
* Timer class: calls the tick method every n milliseconds. * * <PRE> * Timer timer = new Timer(this,1000); // 1 second interval * timer.start(); * </PRE> * * @author Ignazio Locatelli */
package it.MediaIllusion.Anim;
public class Timer implements Runnable {
// main thread protected Thread myThread = null;
// milliseconds to wait protected long interval;
// interface used TimerInterface callback;
/** * default constructor */ public Timer() { interval = 1000; } /** * constructor * @param long millisecond number of millisecond for the interval * @param TimerInterface callback reference to the interface */ public Timer(long milliseconds, TimerInterface callback) { interval = milliseconds; this.callback = callback; } /** * return milliseconds for an interval */ public long getInterval() { return interval; } /** * set interval * @param long milliseconds number of milliseconds */ public void setInterval(long milliseconds) { interval = milliseconds; }
/** * starts the timer */ public void start() { myThread = new Thread(this); myThread.start(); }
/** * stops the timer */ public void stop() { myThread.stop(); myThread = null; }
/** * run */ public void run() { while(true) { long sTime = System.currentTimeMillis(); if (callback != null) callback.tick(); long eTime = System.currentTimeMillis(); long sleep = interval - (eTime-sTime); if (sleep <= 0) continue; try { Thread.sleep(sleep); } catch (Exception e) { System.out.println("Exception during sleep operation\n"); } } }}
/** * Pos: class abstracting a 2D position on a grid * @author Ignazio Locatelli - Media Illusion (C) 2000 */
public class Pos { public int x; public int y;
/** * Position */ public Pos() { x = y = 0; }
/** * Position */ public Pos(int x, int y) { this.x = x; this.y = y; }}
public class InseguitoreConst {public static final int NUM_VITE=4;public static final int MAP_ROWS = 39;public static final int MAP_COLOUMNS = 39;public static final int MAP_CELL_DIMENSION = 8;public static final int PASSO = 4;public static final int DISTANZA_CONTATTO = 36;public static final int SPEED=18;public static final int ACCELERAZIONE=4;public static final int ATTESA=1000;public static final int OFFSET_X = 54;public static final int OFFSET_Y = 34;public static final int OFFSET_PERS_X = 50;public static final int OFFSET_PERS_Y = 30;public static final int START_X1 = 416;public static final int START_X2 = 465;public static final int START_Y1 = 323;public static final int START_Y2 = 377;
int r = ((rgb >> 16) & 0xff)/4; // estra la componente rossa int g = ((rgb >> 8) & 0xff)/4; // verde int b = (rgb & 0xff)/4; // blu int k = (int)(.56*g+.33*r+.11*b); return (0xff000000 | k << 16 | k << 8 | k); //return rgb;
}}
* @author Ing. Alessandro Campi */public class Rettangolo {
int pezziVisitati=0;int totalePezzi=0; //vertici //in alto a sinistra public int x1, y1; //in basso a destra public int x2, y2;public int x1RealeNormale, y1RealeNormale; public int x1RealeScuro, y1RealeScuro;public int w, h;public int saltoNormaleX, saltoNormaleY;public int saltoNormaleDirettoX,saltoNormaleDirettoY;public int saltoScuroX, saltoScuroY;