JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 程式分享區 » 數獨、猜數字  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) [Re:worookie]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2004-03-01 05:01 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
worookie wrote:
如果你一開始就提出這樣的證據來, 那可能就可以省掉大家許多的無謂的討論.
我沒深入去看你的程式, 所以我沒法很容易的去修改你的程式.
不過, 我想這是你的很好的機會去把你的程式修改好後, 把你的新的證據提供出來給大家看.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
public class TestThe2Deep {
  
    String answerSet[] = new String[10*9*8*7];
    boolean validSet[] = new boolean[10*9*8*7];
    String specialGuessNumber;
  
    //you could generate the answerSet in any order you want, as long as answerSet cover all possible guess numbers.
    // deepGreenGuess and deepCafeGuess will using this order to do guessing.
    void generateAnswerSet() {
        int i = 0;
        for (int a = 0; a < 10; a++) {
            for (int b = 0; b < 10; b++) {
                if (b == a) { continue; }
                for (int c = 0; c < 10; c++) {
                    if (c == a || c == b) { continue; }
                    for (int d = 0; d < 10; d++) {
                        if (d == a || d == b || d == c) { continue; }
                        answerSet[i++] = "" + a + b + c + d;
                    }
                }
            }
        }
    }
  
    void initValidSet() {
        for (int i = 0; i < validSet.length; i++) {
            validSet[ i ] = true;
        }
    }
  
    int getA(String s1, String s2) {
        int a = 0;
        for (int i = 0; i < 4; i++) {
            if (s1.charAt( i ) == s2.charAt( i )) { a++; }
        }
        return a;
    }
  
    int getB(String s1, String s2) {
        int b = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (i==j) { continue; }
                if (s1.charAt( i ) == s2.charAt(j)) { b++; }
            }
        }
        return b;
    }
  
    void reduce(String s, int a, int b) {
        for (int i = 0; i < validSet.length; i++) {
            if (!validSet[ i ]) { continue; }
            if ((getA(s, answerSet[ i ]) != a) || (getB(s, answerSet[ i ]) != b)) {
                validSet[ i ] = false;
            }
        }
    }
  
    // Guess the number <code> solution </code>, and return number times of guessing.
    int deepGreenGuess(String solution) {
        int count = 0;
        for (int i = 0; i < validSet.length; i++) {
            if (!validSet[ i ]) { continue; }
            count++;
            int a = getA(solution, answerSet[ i ]);
            if (a == 4) { break; }
            int b = getB(solution, answerSet[ i ]);
            reduce(answerSet[ i ], a, b);
        }
        return count;
    }
  
        // Guess the number <code> solution </code>, and return number times of guessing.
    int deepCafeGuess(String solution) {
        int count = 1;
  
        int a1 = getA(solution, answerSet[ 0 ]);
        if (a1 == 4) { return count; }
        int b1 = getB(solution, answerSet[ 0 ]);
        reduce(answerSet[ 0 ], a1, b1);
  
        // rule #1 :
        // This is the main difference between deepCafeGuess and deepGreenGuess.
        // Without this if block the deepCafeGuess() is exactly the same as deepGreenGuess().
        // deepGreen will never guess the specialGuessNumber because
        // specialGuessNumber represent the other 4 digits no used yet.
        // which after first guessing, if #a+#b == 3, all this kind combination will filter out.
        if (a1+b1 == 3) {
            count++;
            int a2 = getA(solution, specialGuessNumber);
            if (a2 == 4) { return count; }
            int b2 = getB(solution, specialGuessNumber);
            reduce(specialGuessNumber , a2, b2);
        }
          
        for (int i = 1; i < validSet.length; i++) { // i start form 1 instead of 0, because we already guess the answerSet[ 0 ]
            if (!validSet[ i ]) { continue; }
            count++;
            int a = getA(solution, answerSet[ i ]);
            if (a == 4) { break; }
            int b = getB(solution, answerSet[ i ]);
            reduce(answerSet[ i ], a, b);
        }
        return count;
    }
  
    // You can choice any 4 digit not in the <code> s </code> in any order
    // Here, we pick the "first" 4 digits not in <code> s </code>.
    String getSpecialGuessNumber(String s) {
        String specialNumber = "";
        for (int i = (int)'0'; i < (int)'9'; i++) {
            if (s.indexOf( i ) >= 0) { continue; }
            specialNumber += (char)i;
            if (specialNumber.length() == 4) { break; }
        }
        return specialNumber;
    }
  
    public static void main(String[] args) {        
        TestThe2Deep t = new TestThe2Deep();
        t.generateAnswerSet();
        t.specialGuessNumber = t.getSpecialGuessNumber(t.answerSet[ 0 ]);
  
        int total_A_B_3 = 0;
        int total_deepGreen = 0;
        int total_deepCafe = 0;
  
        for (int i = 0; i < t.answerSet.length; i++) {
             int a = t.getA(t.answerSet[ i ], t.answerSet[ 0 ]);
             int b = t.getB(t.answerSet[ i ], t.answerSet[ 0 ]);
  
            // we are interest only the #A+#B == 3
            // for the #A+#B != 3, DeepGreen == DeepCafe
            if (a + b != 3) { continue; }
  
             total_A_B_3++;
  
             t.initValidSet();
             int deepGreenGuessNumber = t.deepGreenGuess(t.answerSet[ i ]);
             total_deepGreen += deepGreenGuessNumber;
  
             t.initValidSet();
             int deepCafeGuessNumber = t.deepCafeGuess(t.answerSet[ i ]);
             total_deepCafe += deepCafeGuessNumber;
  
             System.out.println(t.answerSet[ i ] + " ==> " +
                                "cafe:" + deepCafeGuessNumber +
                                "\t green:" + deepGreenGuessNumber);
        }
  
        System.out.println(" total for first guess #A+#B == 3 numbers ==> " + total_A_B_3);
        System.out.println(" deep green need total " + total_deepGreen + " times to guess all.");
        System.out.println(" deep cafe  need total " + total_deepCafe  + " times to guess all.");
    }
  
}


T55555 edited on 2004-03-01 22:20
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
27488 [精華] [猜數字系列]深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 8882 2004-02-29 09:49
23986 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 257 2004-02-29 11:58
23939 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 405 2004-02-29 12:14
23924 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 406 2004-02-29 12:23
23947 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 367 2004-02-29 12:31
23932 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 623 2004-02-29 14:33
23849 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 292 2004-02-29 12:48
23848 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) jini 19 2004-02-29 12:53
23852 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 1153 2004-02-29 12:57
23785 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 1143 2004-02-29 13:36
23820 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) Yoshi 374 2004-02-29 14:05
23494 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) JiaYun 233 2004-03-01 21:19
23422 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) Duncan 745 2004-03-01 23:09
23595 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 1384 2004-03-02 00:42
23192 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 874 2004-03-02 01:18
23422 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) JiaYun 692 2004-03-02 01:33
23374 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 155 2004-03-02 01:43
23287 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 834 2004-03-02 02:09
23300 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 1966 2004-03-02 02:50
23252 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 2225 2004-03-02 03:03
23125 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 781 2004-03-02 03:14
24607 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 773 2004-03-02 03:19
23270 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 314 2004-03-02 01:55
23305 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) JiaYun 112 2004-03-02 01:58
23365 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) koji 130 2004-03-02 02:02
23836 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) Yoshi 227 2004-02-29 13:33
23732 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 870 2004-02-29 22:43
23751 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) Yoshi 348 2004-02-29 23:39
23715 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 1267 2004-03-01 01:26
23718 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) TAHO 347 2004-03-01 01:59
23615 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) Yoshi 477 2004-03-01 02:12
23569 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 568 2004-03-01 02:13
23552 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) TAHO 858 2004-03-01 02:46
23799 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 998 2004-03-01 04:07
23733 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 1042 2004-03-01 04:23
23643 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 0 2004-03-01 04:28
23633 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 402 2004-03-01 05:14
23593 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 447 2004-03-01 05:41
23665 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 292 2004-03-01 05:08
23599 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 399 2004-03-01 05:50
23659 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 180 2004-03-01 05:57
23587 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 294 2004-03-01 09:15
23497 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 1446 2004-03-01 06:27
23469 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 1295 2004-03-01 07:25
23535 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 1234 2004-03-01 09:12
23520 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 1631 2004-03-01 10:02
23500 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 146 2004-03-01 16:36
23687 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 595 2004-03-01 03:39
23821 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 718 2004-03-01 03:34
23568 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 252 2004-03-01 04:20
23568 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 6047 2004-03-01 05:01
23464 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) TAHO 297 2004-03-01 12:34
23433 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 637 2004-03-01 16:40
23467 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 137 2004-03-01 16:45
23366 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 236 2004-03-01 17:31
23389 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 756 2004-03-01 17:04
23390 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 971 2004-03-01 18:35
23504 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) ramb 753 2004-03-01 18:01
23257 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) T55555 1046 2004-03-02 01:11
23344 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) TAHO 716 2004-03-01 18:23
23434 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) worookie 847 2004-03-01 18:44
23451 Re:深咖啡 0.1 挑戰 深綠 (DeepCafe 0.1 vs DeepGreen) TAHO 12 2004-03-01 18:48
» JWorld@TW »  Java 程式分享區 » 數獨、猜數字

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8