
Archive for May, 2009
max will jump over you
PC > Mac?






![]()



stealing…is scary
Encourage your child
What does it mean?
My Ideal Marriage…
Joe Wang, MA!
GoldBach, is it a prime?
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;
public class goldbach {
public static double pp;
//Scanner in=new Scanner(System.in);
//DCLUO
public static boolean goodDiv(double a,double b){
double e=a/b;
if((int)e==e){
return true;
}
return false;
}
public static void main(String[] args) throws FileNotFoundException {
Scanner scan=null;
int a=1;
// TODO Auto-generated method stub
double ts=System.currentTimeMillis();
while(a90000){ scan = new Scanner(new FileInputStream(“primes1.txt”));}
while(a/b>2){
while(goodDiv(c,b)){
c=c/b;
System.out.print(“*”+(int)b);
}
//
if(a>900000){b=(double)scan.nextInt();}else{b++;}
}if(a>900000){scan.close();}
if (c!=1){
System.out.print(“*”+(int)c);
if(c==a){System.out.print(“\t\t PRIME”);
pp++;}
}
double ees=System.currentTimeMillis();
System.out.println(“\t\t Runtime:”+(tts-ees)+” ms”);
a++;}
}
System.out.println(“percentage of prime in range 1~”+(a-1)+”=”+100*(pp/a)+”%”);
double end=System.currentTimeMillis();
System.out.println(“Runtime:”+(end-ts)/1000+” s”);
}
}
Catastrophe
sudoku.java
package sudoku;
//dcluo
import java.util.*;
public class sudoku {
static key[] board=new key[81];
static int[] test={
0,0,0,0,0,6,0,4,0,
0,0,0,8,0,5,0,2,7,
0,0,0,0,7,9,8,5,0,
5,6,8,1,4,3,7,9,2,
0,1,0,5,0,0,3,0,4,
0,0,9,0,6,0,1,0,5,
4,0,0,0,0,0,0,1,0,
2,5,0,0,0,0,0,3,6,
9,0,1,0,0,0,5,7,0,
};
static key[][] figure=new key[9][9];
static int count=0,tcount=44;
/**
* @param args
*/
public static void main(String[] args) {
ini();
printFg();
Scanner user=new Scanner(System.in);
System.out.println("mode:");
if(user.next().equals("test")){
for(int i=0;i<81;i++){
board[i].set(test[i]);
}
count=tcount;
}else{
for(int i=0;i9||in9||in<1)){
test("check");
if(check(in,board[i].getHn(),board[i].getVn()))
{
board[i].set(in);
board[i].setS(true);
break;
}else{
System.out.println("False input");
in=user.nextInt();
}
}
}
printbd();
}
}
for(int i=0;i<81;i++){if(board[i].getValue()==0){board[i].setS(false);}else{board[i].setS(true);}}
System.out.println("Sudoku:");
printFg();
solve();
System.out.println("Result:");
printbd();
}
public static boolean presolve(){
boolean did=false;
for(int i=0;i<81;i++){
key cur=board[i];
if(!board[i].getS()){
for(int p=1;p<10;p++){
if(check(p,cur.getHn(),cur.getVn()))
{
if(!cur.psbl.contains(p)){
cur.psbl.add(p);
test("for "+i+" added possible anwser:"+p+" "+cur.psbl.toString());
did=true;
}
}else{
if(cur.psbl.contains(p))
{
did=true;
test("for "+i+" removed possible anwser:"+p);
cur.psbl.remove(cur.psbl.indexOf(p));
}
}
}
}
}
return did;
}
public static boolean fill(){
for(int i=0;i0){
count--;
}
}
public static boolean check(int v,int hn,int vn){
return checkH(v,vn)&&checkV(v,hn)&&checkB(v,hn,vn)==true;
}
public static boolean checkH(int v,int ln){
for(int i=0;i<9;i++){
if(figure[ln][i].getValue()==v){
return false;
}
}
return true;
}
public static boolean checkV(int v,int vn){
for(int i=0;i<9;i++){
if(figure[i][vn].getValue()==v){return false;}
}
return true;
}
public static int[][] getbox(int hv,int vn){
int[][] set=new int[2][3];
if(hv<3){
for(int i=0;i<3;i++){
set[0][i]=i+1;
}
}else if(hv<6){
for(int i=0;i<3;i++){
set[0][i]=i+4;
}
}else{
for(int i=0;i<3;i++){
set[0][i]=i+7;
}
} if(vn<3){
for(int i=0;i<3;i++){
set[1][i]=i+1;
}
}else if(vn<6){
for(int i=0;i<3;i++){
set[1][i]=i+4;
}
}else{
for(int i=0;i<3;i++){
set[1][i]=i+7;
}
}
return set;
}
public static boolean checkB(int v,int hv,int vn){
int hc,vc;
int set[][]=getbox(hv,vn);
test(set[0][0]+"~"+set[1][2]);
for(int i=0;i<3;i++){
hc=set[1][i];
for(int j=0;j<3;j++){
vc=set[0][i];
if(v==figure[vc-1][hc-1].getValue()){
test(v+" false!"+vc+":"+hc);
return false;}
}
}
test(v+" true!"+vn+":"+hv);
return true;
}
public static void printbd(){
String out="";
for(int i=0;i<81;i++){
out=out+"\t"+board[i].getValue();
if((i+1)%9==0){out=out+"\n";}
}
System.out.print(out);
}
public static void printFg(){
for (int r=0;r<9;r++){
for(int n=0;n<9;n++){
System.out.print("\t"+figure[r][n].getValue());
}
System.out.println();
}
}
public static void ini(){
int r=0,c=0;
for(int i=0;i7){r++;}
}
}
public static void test(Object c){System.out.println(c);}
}
key.java
package sudoku;
import java.util.*;
public class key {
boolean solid=false;
int value=0;
int vn=0;
int hn=0;
int[] list;
LinkedList psbl=new LinkedList();
public key(int i){
value=i;
}
public boolean getS(){return solid;}
public void setS(boolean set){solid=set;}
public int getValue(){return value;}
public void setHn(int r){hn=r;}
public void setVn(int l){vn=l;}
public int getHn(){return hn;}
public int getVn(){return vn;}
public void set(int i){if(i>0&&i<10){value=i;}else{value=0;}}
public void addpsbl(int add){if(!psbl.contains((Integer)add))psbl.add(add);}
public int[] getPsbl(){
int[] lst=new int[psbl.size()-1];
if(list.length==lst.length){return list;}
Integer[] integers=(Integer[]) psbl.toArray();
for (int i=0;i<lst.length;i++){
lst[i]=integers[i];
}
list=lst;
return list;
}
}
Data strucutre imagine.
With the leaps of IT developments, data space is reacquired. More and more people or program seeks a way to compress old achieved files. here comes the vision of mine. Similar to hash code data structure, what if a file is represented with colors. As Rubik’s cube, the combination of file is dramatically improved. It is even better with Sudokus…However, it is harder or impossible (md5) to unhash the indexes. Whatif, a Sudoku map is what we need to store infos? that is 6,670,903,752,021,072,936,960 combinations. That is what i see..
Recent Comments