Monday, September 21, 2009

Puzzle 15 using Breadth First Search Java

/******************************************* *
* Puzzle 15 using Breadth First Search
*************************************************/

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

public class puzzle15 {
// Use of Queue Implemented using LinkedList for Storing all the Nodes in
// BFS.
Queue q = new LinkedList();

// HashMap is used to ignore repeated nodes
Map map = new HashMap();

// String Buffer to print the series of number stored in queue. It will
// display the order in which
// the space is moved
StringBuffer strBuffer = new StringBuffer();

public static void main(String args[]) {
// Input the 15 Puzzle State as a String with 0 as the Blank Space
// The inputs are 1, 2, 3, 4, 5, 6 ,7, 8, 9, A, B, C D ,E ,F, 0
// Input can be hardcoded in the code or read from the text file.
// Currently I am storing the input file in
// E: drive. In file, provide inputs without space and comma. One input
// at a time

String strInput = "0123456789ABCDEF";

/******************* START Read Input from text file ******************************/
// File file = new File("E:\\Input.txt"); //Comment this line if reading
// from argument
//
// //To read input from console please uncomment below code and comment
// above line
// //File file = new File(args[0]);
// FileInputStream fis = null;
// BufferedInputStream bis = null;
// DataInputStream dis = null;
// String strLineData = "";
//
// try {
// fis = new FileInputStream(file);
//
// // Here BufferedInputStream is added for fast reading.
// bis = new BufferedInputStream(fis);
// dis = new DataInputStream(bis);
//
// // dis.available() returns 0 if the file does not have more lines.
// while (dis.available() != 0) {
// // this statement reads the line from the file and print it to
// // the console.
// strLineData = dis.readLine() + "";
//
// }
// strInput = strLineData;
//
// //dispose all the resources after using them.
// fis.close();
// bis.close();
// dis.close();
//
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
/******************* END Read Input from text file ******************************/

puzzle15 objPuzzle15 = new puzzle15(); // New Instance of the puzzle15
objPuzzle15.add(strInput, 0); // Add the Initial State
try {
// Breadth First Search Logic
while (objPuzzle15.q.peek() != null) {
// Move the blank space up and add new state to queue
objPuzzle15.upPuzzle(objPuzzle15.q.peek());
// Move the blank space down
objPuzzle15.downPuzzle(objPuzzle15.q.peek());
// Move left
objPuzzle15.leftPuzzle(objPuzzle15.q.peek());
// Move right and remove the current node
objPuzzle15.rightPuzzle(objPuzzle15.q.remove());
// from Queue
}
} catch (Exception ex) {
System.out.println("Exception: " + ex);
}

System.out
.println("Solution doesn't exist for the given Puzzle 15 problem");
}

// Add method to add the new modified string to the Map and Queue
void add(String str, int n) {
if (!map.containsKey(str)) {
map.put(str, n);
q.add(str);
// strBuffer.append(str + "\n");
}
}

/*
* Each methods below takes current state as string and if possible, task of
* moving thr blank space i.e., "0" is done. Then new modified string is add
* to the map and queue. Once Goal state is reached, the execution will be
* terminated.
*/
void upPuzzle(String str) {
String s = "";
try {
int a = str.indexOf("0");

if (a > 3) {
s = str.substring(0, a - 4) + "0" + str.substring(a - 3, a)
+ str.charAt(a - 4) + str.substring(a + 1);
add(s, map.get(str) + 1);
if (s.equals("123456789ABCDEF0")) {
System.out.println("Solution exists at Level " + map.get(s)
+ " of the tree");
// System.out.println("Solution seq " + strBuffer);
System.exit(0);
}
}
} catch (Exception ex) {
System.out.println("Exception: " + ex.getLocalizedMessage()
+ " at level " + map.get(s) + " of the tree");
}
}

void downPuzzle(String str) {
String s = "";
try {
int a = str.indexOf("0");
if (a < 12) {
s = str.substring(0, a) + str.substring(a + 4, a + 5)
+ str.substring(a + 1, a + 4) + "0"
+ str.substring(a + 4);
add(s, map.get(str) + 1);
if (s.equals("123456789ABCDEF0")) {
System.out.println("Solution exists at Level " + map.get(s)
+ " of the tree");
// System.out.println("Solution seq " + strBuffer);
System.exit(0);
}
}
} catch (Exception ex) {
System.out.println("Exception: " + ex.getLocalizedMessage()
+ " at level " + map.get(s) + " of the tree");
}
}

void leftPuzzle(String str) {
String s = "";
try {
int a = str.indexOf("0");
if (a != 0 && a != 4 && a != 8 && a != 12) {
s = str.substring(0, a - 1) + "0" + str.charAt(a - 1)
+ str.substring(a + 1);
add(s, map.get(str) + 1);
if (s.equals("123456789ABCDEF0")) {
System.out.println("Solution exists at Level " + map.get(s)
+ " of the tree");
// System.out.println("Solution seq " + strBuffer);
System.exit(0);
}
}
} catch (Exception ex) {
System.out.println("Exception: " + ex.getLocalizedMessage()
+ " at level " + map.get(s) + " of the tree");
}
}

void rightPuzzle(String str) {
String s = "";
try {
int a = str.indexOf("0");
if (a != 3 && a != 7 && a != 11 && a != 15) {
s = str.substring(0, a) + str.charAt(a + 1) + "0"
+ str.substring(a + 2);
add(s, map.get(str) + 1);
if (s.equals("123456789ABCDEF0")) {
System.out.println("Solution exists at Level " + map.get(s)
+ " of the tree");
// System.out.println("Solution seq " + strBuffer);
System.exit(0);
}
}
} catch (Exception ex) {
System.out.println("Exception: " + ex.getLocalizedMessage()
+ " at level " + map.get(s) + " of the tree");
}
}
}

Thursday, October 16, 2008

Label your USB stick



1) Extract LabelUSB.zip to the root folder of your USB stick.
2) Double click Autorun.inf and replace "YourName" with a name of your choice.
3) If you want to use another icon; replace icon.ico with another .ico file and give it the same name.
4) Enjoy

Sunday, October 12, 2008

Optimize Vista sound

This is for those who think vista's sounds are just too quiet। Some are not even used by default in vista, so this will help you know how to make extra sounds be used for certain things, and give you much louder sounds.

SIMPLE INSTRUCTIONS:

IMPORTANT: DO STEPS 1-3!!!

NOTE: This is assuming that Windows Vista is installed on drive C:

1. Open C:/Windows/Media folder
2. Select all the files (Ctrl + A) and copy all the contents of this folder
3. Make a New Folder somewhere safe, and PASTE all the copied files there...THIS IS FOR BACKUP!
4. Go back to C:/Windows/Media folder
5. Open THIS download's "Media" folder and copy all of its content
6. PASTE all the copied items into the C:/Windows/Media folder
7. You might want to check the bottom option "Do this for the next 42 conflicts"
8. Enjoy.


If you think the files are too loud for you...
Do this:
1. Press Windows logo + R
2. Open: SndVol.exe
3. On the "Windows Sounds" column, adjust the desired volume.

Tip:
Most of the modified files are not used in the Windows Vista default sound scheme.
For example, if you want to add a cool sound to when minimizing windows do the following:

1. Press Windows logo + R
2. Open: mmsys.cpl
3. On the "Sounds" tab, in the "Program" area, scroll down and click on "Minimize"
4. Click on the "Browse..." button
5. Navigate to C:/Windows/Media
6. Scroll down to select the "Windows Minimize" file
7. Apply
8। Do this for the options that aren't yet set, IF YOU WANT TO।

http://rapidshare.com/files/19345405/Louder_Vista_Sounds.exe

Friday, August 15, 2008

Use a Shortcut Key to Safely Remove Hardware

How to Use a Shortcut Key to Safely Remove Hardware

Many of you who use USB drives will benefit from this quick fix. Safely removing hardware can be a pain when you have to click the button every time. In this guide you will learn how to assign a keyboard shortcut to the Safely Remove Hardware Dialog.

Creating the Shortcut

1. Right-click anywhere on the desktop and choose New \ Shortcut:

How to Use a Shortcut Key to Safely Remove Hardware

2. Paste in the following into the location box:

RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll

How to Use a Shortcut Key to Safely Remove Hardware

3. Give the shortcut a name, and you’ll have a shortcut icon…

How to Use a Shortcut Key to Safely Remove Hardware

Wednesday, August 13, 2008

Infinite Gmail Accounts

When you choose a Gmail address, you actually get more than just "yourusername@gmail.com." Here are two different ways you can modify your Gmail address and still get your mail:

1] Append a plus ("+") sign and any combination of words or numbers after your email address. For example, if your name was hikingfan@gmail.com, you could send mail to hikingfan+friends@gmail.com or
hikingfan+mailinglists@gmail.com.

2] Insert one or several dots (".") anywhere in your email address. Gmail doesn't recognize periods as characters in addresses -- we just ignore them. For example, you could tell people your address was hikingfan@gmail.com, hiking.fan@gmail.com or hi.kin.g.fan@gmail.com. (We understand that there has been
some confusion about this in the past, but to settle it once and for all, you can indeed receive mail at all the variations with dots.)

Have fun!!!

Need a Serial Number....

Most of the people downloading trial and using it, only after the expiration of trial they try for crack, Serial No, Keygen, Patch....

But many don't known where to get Serial No, Some websites may be infect your system with Trojan horse, Viruses, Ad ware, Spy ware....

So for beginners this is a simply way to find hack with less effort and it saves time to, But make sure you have anti virus activated before trying to get some Serials, Patches to avoid data lossJust follow the steps as instructed below
1) Go to
http://www.google.com
2) type this syntax in search bar " 94FBR"
3) Replace Product name with desired software and leave a space then type 94FBR
4) Press enter, thats it ....Now you receive Many pages which contains Serial no, Crack, Patches....

Just make a try, this simple trick works for many people............ Have fun !!!!!!!!!!!!!

Friday, April 06, 2007

Best Way to deal with Virus.....

A number of viruses can do either together or single handedly.

My suggestion is you run the "Msconfig" command and do a selective startup. disable all the programs from starting up as the viruses sometimes hide behind them.
apply and restart. you will see it get slightly faster on startup.

Then depending on how the infection was done, you can run Windows repair so that you replace all the windows applications that don't start up.

Get a good antivirus, i wd go for F-secure or Sophos in this case, install and update it, then run a thorough scan, it wills show you the virus as well as
the infected file.

After you know the virus, you can deal with it. Its true some viruses may not antivirus solutions, but atleast F-secure and sophos, will tell you what a
virus does, where is resides, what it writes to the registry and the services it corrupts.

You will be able to manually remove these registry entries, delete the file say in safe mode and you will be up and running.

You can also run a registry cleaning utility to crown it all

FORMATTING SHOULD BE YOUR LAST, OPTION, unless you have been backing up, which I am sure u haven't and you can't do that now coz you will only backup viruses.

Cheers.

Friday, January 05, 2007

Most Effective Tweak for Windows XP

The best tweak for windows
1) Open the regedit tool (Start -> Run -> regedit.exe)
2) Use the navigation in the left and go to HKEY LOCAL MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management
3) Double click the DisablePagingExecutive attribute, and put 1 in the decimal value field. This will make the drivers and the XP kernel run in memory.
4) Double click the LargeSystemCache attribute, and put 1 in the decimal value field
This will improve performance of the kernel
5) Double click the IOPageLockLimit attribute. On some later versions of windows XP that doesn't exists, so if this is the case you're done. Otherwise you have to put to the hex value : 4000 for pcs with 128 mb ram, 10000 for 256 mb ram and if you have more put 40000. This value specifies how many bytes can be used for I/O operations in your system.

Windows Vista 1.4 MB

Whole Windows Vista!!! of size 1444Mb in just 1.4MB zip file.....


http://www.esnips.com/doc/2799928f-1924-4369-844e-84dce74f7693/Full_Longhorn.zip

Njoi...........