My Blog List

Thursday, March 19, 2015

interesting def


Interesting  ~

>>> i =5
>>>
>>> def f(arg=i):
print(arg)

>>> i =7
>>> f()

guess what number??

the result is 5


List Type

I think Python is very simple to learn
simple to understand
simple to code...

there are many advantage if I use this language.

Now I start to learn list

Make List:
squares = [1,2,3,4,5]

Add List:
squares.append(6)

Copy List:
sqaures[:]

Range List:
sqaures[0:2]

Clear List:
sqaures = []

Thursday, March 12, 2015

Problem 84

Before solving this problem
I thought lost of time. because. It request to me that I had to make monopoly rules and playing it to make statistic.

Anyway I made up~ never give up~!



What I learned from this problem is that statistics are very strong~!!!!!!




  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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package euler.numberFrom71;

import java.util.Arrays;
import java.util.Collections;
import java.util.Random;

public class number84 {
 
 static int visitCount [] = new int[40];
 static int currentPosition =0;
 
 static int money[] = new int [16];
 static int moneyPosition = 0;
 
 
 static String chance[] = new String [16];
 static int chancePosition = 0;
 
 static int []log = new int[40]; 
 
 static String [] map  = {
   "GO", "A1","CC1","A2","T1","R1","B1","CH1","B2","B3", //0 ~9
   "JAIL", "C1", "U1", "C2", "C3", "R2", "D1", "CC2","D2","D3", // 10-19
   "FP", "E1", "CH2", "E2", "E3", "R3", "F1",  "F2", "U2", "F3", // 20- 29
   "G2J",  "G1","G2",  "CC3",  "G3", "R4", "CH3", "H1", "T2",  "H2" //30-39
 };
 
 public static void main(String args[]) throws InterruptedException{
  settingMoneyAndChange();
  
  Random ran = new Random();
  
  for (int i = 0; i < 10000000; i++) {
   int count =0;
   boolean isCountinue = true;
   while (isCountinue) {
    DiceResult result = goDice();
    
    // 더블체크
    if(result .isDouble){
     isCountinue = true;
     if(count == 2){
      goToJail();
      break;
     }
     count++;
    }else{
     isCountinue = false;
    }
    
    int tempTotal = currentPosition+ result.total;
    if(tempTotal > map.length -1){
     currentPosition =tempTotal - map.length;
    }else{
     currentPosition = tempTotal;
    }  
    
    // 점령한다 // 더블이여도 감옥가면 그만
    if(!goToPosition(currentPosition)){
     break;
    }
   }
   
   
   //System.out.println(Arrays.toString(visitCount));
   
   Arrays.fill(log, 0);
   log[currentPosition] =9;
   //System.out.println(Arrays.toString(log));
  }
  
  
  int [] temp = visitCount.clone();
  Arrays.sort(temp);
  for (int i = temp.length-1; i > temp.length-4; i--) {
   
   for (int j = 0; j < visitCount.length; j++) {
    if(visitCount[j] == temp[i]){
     System.out.println(map[j]);
     break;
    }
   }
  }
  
  
  
 }
 
 /**
  * 점령한다
  * @param currentPosition2
  */
 private static boolean  goToPosition(int destP) {
  if(map[destP].contains("CC")){
   doPublic(destP);
  }else if(map[destP].contains("CH")){
   doChance(destP);
  }else if(map[destP].contains("G2J")){
   goToJail();
   
   return false;
  }else{
   visitCount[destP]++;
  }
  return true;
 }
 
 
 private static void doChance(int destP) {
  //System.out.println("chance " + chance[chancePosition]);
  if(chance[chancePosition] == null){
   visitCount[destP]++;
  }else if(chance[chancePosition] .equals("")){
   visitCount[destP]++;
  }else if(chance[chancePosition] .contains("N_")){
   findNextPosition(chance[chancePosition]);
   visitCount[currentPosition]++;
  }else if(chance[chancePosition] .equals("B3")){
   currentPosition = currentPosition-3;
   visitCount[currentPosition]++;
  }else{
   findPosition(chance[chancePosition]);
   visitCount[currentPosition]++;
  }
  
  if(chancePosition == chance.length-1){
   chancePosition =0; 
  }else{
   chancePosition++;
  }
 }

 private static void findNextPosition(String string) {
  String a = string.substring(2);
  for (int i = currentPosition; i < map.length; i++) {
   if(map[i].startsWith(a)){
    currentPosition =i;
    return ;
   }
  }
  
  for (int i = 0; i < currentPosition; i++) {
   if(map[i].startsWith(a)){
    currentPosition =i;
    return ;
   }
  }
 }

 private static void findPosition(String string) {
  for (int i = 0; i < map.length; i++) {
   if(string.equals(map[i])){
    currentPosition = i;
    break;
   }
  }
 }

 private static void doPublic(int destP) {
  //System.out.println("doPublic " + money[moneyPosition]);
  if(money[moneyPosition] != -1){
   currentPosition = money[moneyPosition];
   visitCount[currentPosition]++;
  }else{
   visitCount[destP]++;
  }
  
  if(moneyPosition == money.length-1){
   moneyPosition =0; 
  }else{
   moneyPosition++;
  }
  
 }

 /**
  * 초기화
  */
 private static void settingMoneyAndChange() {
  Arrays.fill(money, -1);
  money[0] = 0;
  money[1] = 10;
  
  Arrays.fill(chance, null);
  chance[0] = "GO";
  chance[1] = "JAIL";
  chance[2] = "C1";
  chance[3] = "E3";
  chance[4] = "H2";
  chance[5] = "R1";
  chance[6] = "N_R";
  chance[7] = "N_R";
  chance[8] = "N_U";
  chance[9] = "B3";
 }

 private static void goToJail() {
  //System.out.println("감옥");
  currentPosition = 10;
  visitCount[10]++;
 }

 public static DiceResult goDice(){

  Random ran = new Random();
  
  DiceResult result = new DiceResult();
  
  int a=0;
  int b=0;
  int total =0;
  a= ran.nextInt(4)+1;
  b= ran.nextInt(4)+1;
  
  //System.out.println("주사위 : " + a +" , "+ b);
  
  if(a == b){
   result.isDouble = true;
   //System.out.println("더블");
  }
  
  total = a+b;
  result.total = total;
  return result;
 }
}


class DiceResult{
 boolean isDouble = false;
 int total = 0;
}

Tuesday, March 10, 2015

Project euler 81~ 83 : BFS(Breadth-First-Search)

These questions were very easy to me~!

Because I studied graph algorithm very hard and posted on my blogger.

https://projecteuler.net/problem=83


# List #

1. BFS(Breadth-First-Search),
2. DFS(Depth-First-Search),
3. Prim algorithm,
4. Union Find algorithm,
5. Kruskal algorithm,
6. Topology algorithm,
7. dijkstra's algorithm



What I had to do was thinking about how to efficiently access good solution by past times.

I choosed BFS login with Queue and find all possible path.

condition
up case : if (sum[po.y - 1][po.x] > curSum + val[po.y - 1][po.x]) {
  sum[po.y - 1][po.x] = curSum + val[po.y - 1][po.x];
  queue.add(new Position(po.x, po.y - 1));
        }

right down, left ...




[P (y=0 , x=0)]
[131, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]

[P (y=0 , x=1), P (y=1 , x=0)]
[131, 804, max, max, max]
[332, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]

[P (y=1 , x=0), P (y=0 , x=2), P (y=1 , x=1)]
[131, 804, 1038, max, max]
[332, 900, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]

[P (y=0 , x=2), P (y=1 , x=1), P (y=1 , x=1), P (y=2 , x=0)]
[131, 804, 1038, max, max]
[332, 428, max, max, max]
[962, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]

[P (y=1 , x=1), P (y=1 , x=1), P (y=2 , x=0), P (y=0 , x=3), P (y=1 , x=2)]
[131, 804, 1038, 1141, max]
[332, 428, 1380, max, max]
[962, max, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]

[P (y=1 , x=1), P (y=2 , x=0), P (y=0 , x=3), P (y=1 , x=2), P (y=1 , x=2), P (y=2 , x=1)]
[131, 804, 1038, 1141, max]
[332, 428, 770, max, max]
[962, 1231, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]

[P (y=2 , x=0), P (y=0 , x=3), P (y=1 , x=2), P (y=1 , x=2), P (y=2 , x=1)]
[131, 804, 1038, 1141, max]
[332, 428, 770, max, max]
[962, 1231, max, max, max]
[max, max, max, max, max]
[max, max, max, max, max]

[P (y=0 , x=3), P (y=1 , x=2), P (y=1 , x=2), P (y=2 , x=1), P (y=3 , x=0)]
[131, 804, 1038, 1141, max]
[332, 428, 770, max, max]
[962, 1231, max, max, max]
[1499, max, max, max, max]
[max, max, max, max, max]

[P (y=1 , x=2), P (y=1 , x=2), P (y=2 , x=1), P (y=3 , x=0), P (y=0 , x=4), P (y=1 , x=3)]
[131, 804, 1038, 1141, 1159]
[332, 428, 770, 2106, max]
[962, 1231, max, max, max]
[1499, max, max, max, max]
[max, max, max, max, max]

[P (y=1 , x=2), P (y=2 , x=1), P (y=3 , x=0), P (y=0 , x=4), P (y=1 , x=3), P (y=0 , x=2), P (y=1 , x=3), P (y=2 , x=2)]
[131, 804, 1004, 1141, 1159]
[332, 428, 770, 1735, max]
[962, 1231, 1516, max, max]
[1499, max, max, max, max]
[max, max, max, max, max]

[P (y=2 , x=1), P (y=3 , x=0), P (y=0 , x=4), P (y=1 , x=3), P (y=0 , x=2), P (y=1 , x=3), P (y=2 , x=2)]
[131, 804, 1004, 1141, 1159]
[332, 428, 770, 1735, max]
[962, 1231, 1516, max, max]
[1499, max, max, max, max]
[max, max, max, max, max]

[P (y=3 , x=0), P (y=0 , x=4), P (y=1 , x=3), P (y=0 , x=2), P (y=1 , x=3), P (y=2 , x=2), P (y=3 , x=1)]
[131, 804, 1004, 1141, 1159]
[332, 428, 770, 1735, max]
[962, 1231, 1516, max, max]
[1499, 1930, max, max, max]
[max, max, max, max, max]

[P (y=0 , x=4), P (y=1 , x=3), P (y=0 , x=2), P (y=1 , x=3), P (y=2 , x=2), P (y=3 , x=1), P (y=4 , x=0)]
[131, 804, 1004, 1141, 1159]
[332, 428, 770, 1735, max]
[962, 1231, 1516, max, max]
[1499, 1930, max, max, max]
[2304, max, max, max, max]

[P (y=1 , x=3), P (y=0 , x=2), P (y=1 , x=3), P (y=2 , x=2), P (y=3 , x=1), P (y=4 , x=0), P (y=1 , x=4)]
[131, 804, 1004, 1141, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, max, max]
[1499, 1930, max, max, max]
[2304, max, max, max, max]

[P (y=0 , x=2), P (y=1 , x=3), P (y=2 , x=2), P (y=3 , x=1), P (y=4 , x=0), P (y=1 , x=4), P (y=2 , x=3)]
[131, 804, 1004, 1141, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 2157, max]
[1499, 1930, max, max, max]
[2304, max, max, max, max]

[P (y=1 , x=3), P (y=2 , x=2), P (y=3 , x=1), P (y=4 , x=0), P (y=1 , x=4), P (y=2 , x=3), P (y=0 , x=3)]
[131, 804, 1004, 1107, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 2157, max]
[1499, 1930, max, max, max]
[2304, max, max, max, max]

[P (y=2 , x=2), P (y=3 , x=1), P (y=4 , x=0), P (y=1 , x=4), P (y=2 , x=3), P (y=0 , x=3)]
[131, 804, 1004, 1107, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 2157, max]
[1499, 1930, max, max, max]
[2304, max, max, max, max]

[P (y=3 , x=1), P (y=4 , x=0), P (y=1 , x=4), P (y=2 , x=3), P (y=0 , x=3), P (y=2 , x=3), P (y=3 , x=2)]
[131, 804, 1004, 1107, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, max]
[1499, 1930, 2013, max, max]
[2304, max, max, max, max]

[P (y=4 , x=0), P (y=1 , x=4), P (y=2 , x=3), P (y=0 , x=3), P (y=2 , x=3), P (y=3 , x=2), P (y=4 , x=1)]
[131, 804, 1004, 1107, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, max]
[1499, 1930, 2013, max, max]
[2304, 2662, max, max, max]

[P (y=1 , x=4), P (y=2 , x=3), P (y=0 , x=3), P (y=2 , x=3), P (y=3 , x=2), P (y=4 , x=1)]
[131, 804, 1004, 1107, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, max]
[1499, 1930, 2013, max, max]
[2304, 2662, max, max, max]

[P (y=2 , x=3), P (y=0 , x=3), P (y=2 , x=3), P (y=3 , x=2), P (y=4 , x=1), P (y=2 , x=4)]
[131, 804, 1004, 1107, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, 1420]
[1499, 1930, 2013, max, max]
[2304, 2662, max, max, max]

[P (y=0 , x=3), P (y=2 , x=3), P (y=3 , x=2), P (y=4 , x=1), P (y=2 , x=4), P (y=3 , x=3)]
[131, 804, 1004, 1107, 1159]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, 1420]
[1499, 1930, 2013, 2059, max]
[2304, 2662, max, max, max]

[P (y=2 , x=3), P (y=3 , x=2), P (y=4 , x=1), P (y=2 , x=4), P (y=3 , x=3), P (y=0 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, 1420]
[1499, 1930, 2013, 2059, max]
[2304, 2662, max, max, max]

[P (y=3 , x=2), P (y=4 , x=1), P (y=2 , x=4), P (y=3 , x=3), P (y=0 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, 1420]
[1499, 1930, 2013, 2059, max]
[2304, 2662, max, max, max]

[P (y=4 , x=1), P (y=2 , x=4), P (y=3 , x=3), P (y=0 , x=4), P (y=4 , x=2)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, 1420]
[1499, 1930, 2013, 2059, max]
[2304, 2662, 2537, max, max]

[P (y=2 , x=4), P (y=3 , x=3), P (y=0 , x=4), P (y=4 , x=2)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1938, 1420]
[1499, 1930, 2013, 2059, max]
[2304, 2662, 2537, max, max]

[P (y=3 , x=3), P (y=0 , x=4), P (y=4 , x=2), P (y=2 , x=3), P (y=3 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1842, 1420]
[1499, 1930, 2013, 2059, 2376]
[2304, 2662, 2537, max, max]

[P (y=0 , x=4), P (y=4 , x=2), P (y=2 , x=3), P (y=3 , x=4), P (y=4 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1309]
[962, 1231, 1516, 1842, 1420]
[1499, 1930, 2013, 2059, 2376]
[2304, 2662, 2537, 2096, max]

[P (y=4 , x=2), P (y=2 , x=3), P (y=3 , x=4), P (y=4 , x=3), P (y=1 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1420]
[1499, 1930, 2013, 2059, 2376]
[2304, 2662, 2537, 2096, max]

[P (y=2 , x=3), P (y=3 , x=4), P (y=4 , x=3), P (y=1 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1420]
[1499, 1930, 2013, 2059, 2376]
[2304, 2662, 2537, 2096, max]

[P (y=3 , x=4), P (y=4 , x=3), P (y=1 , x=4), P (y=3 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1420]
[1499, 1930, 2013, 1963, 2376]
[2304, 2662, 2537, 2096, max]

[P (y=4 , x=3), P (y=1 , x=4), P (y=3 , x=3), P (y=4 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1420]
[1499, 1930, 2013, 1963, 2376]
[2304, 2662, 2537, 2096, 2707]

[P (y=1 , x=4), P (y=3 , x=3), P (y=4 , x=4), P (y=4 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1420]
[1499, 1930, 2013, 1963, 2376]
[2304, 2662, 2537, 2096, 2427]

[P (y=3 , x=3), P (y=4 , x=4), P (y=4 , x=4), P (y=2 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1386]
[1499, 1930, 2013, 1963, 2376]
[2304, 2662, 2537, 2096, 2427]

[P (y=4 , x=4), P (y=4 , x=4), P (y=2 , x=4), P (y=4 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1386]
[1499, 1930, 2013, 1963, 2376]
[2304, 2662, 2537, 2000, 2427]

[P (y=4 , x=4), P (y=2 , x=4), P (y=4 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1386]
[1499, 1930, 2013, 1963, 2376]
[2304, 2662, 2537, 2000, 2427]

[P (y=2 , x=4), P (y=4 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1842, 1386]
[1499, 1930, 2013, 1963, 2376]
[2304, 2662, 2537, 2000, 2427]

[P (y=4 , x=3), P (y=2 , x=3), P (y=3 , x=4)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1963, 2342]
[2304, 2662, 2537, 2000, 2427]

[P (y=2 , x=3), P (y=3 , x=4), P (y=4 , x=4), P (y=4 , x=2)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1963, 2342]
[2304, 2662, 2524, 2000, 2331]

[P (y=3 , x=4), P (y=4 , x=4), P (y=4 , x=2), P (y=3 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2524, 2000, 2331]

[P (y=4 , x=4), P (y=4 , x=2), P (y=3 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2524, 2000, 2331]

[P (y=4 , x=2), P (y=3 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2524, 2000, 2331]

[P (y=3 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2524, 2000, 2331]

[P (y=4 , x=3)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2524, 1966, 2331]

[P (y=4 , x=4), P (y=4 , x=2)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2490, 1966, 2297]

[P (y=4 , x=2)]
[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2490, 1966, 2297]

[131, 804, 1004, 1107, 1125]
[332, 428, 770, 1735, 1275]
[962, 1231, 1516, 1808, 1386]
[1499, 1930, 2013, 1929, 2342]
[2304, 2662, 2490, 1966, 2297]


and my source is

below



  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
157
158
159
package euler.numberFrom71;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class number83 {
 public static void main(String args[]) throws FileNotFoundException {
  long start = System.currentTimeMillis();
//  Scanner scan = new Scanner(
//    new File(
//      "D:/app/tool/eclipse-kepler-server/workspace/euler/src/euler/p081_matrix.txt"));
//
//  int total = 0;
//  String read = "";
//
//  ArrayList<Integer[]> list = new ArrayList<Integer[]>();
//
//  while (scan.hasNextLine()) {
//   String str = scan.nextLine();
//   String[] strNum = str.split(",");
//   Integer nums[] = new Integer[strNum.length];
//   for (int i = 0; i < strNum.length; i++) {
//    nums[i] = Integer.parseInt(strNum[i]);
//   }
//
//   list.add(nums);
//  }
//
//  Integer val[][] = new Integer[list.size()][list.get(0).length];
//
//  for (int i = 0; i < list.size(); i++) {
//   val[i] = list.get(i);
//  }
  
  int [][] val = new int[][] {
  {131,673,234,103,18},
  {201,96,342,965,150},
  {630,803,746,422,111},
  {537,699,497,121,956},
  {805,732,524,37,331}
};

  long[][] sum = new long[val.length][val[0].length];
  String[][] path = new String[val.length][val[0].length];

  long min = Long.MAX_VALUE;

  for (int k = 0; k < path.length; k++) {
   for (int j = 0; j < path.length; j++) {
    Arrays.fill(sum[k], Integer.MAX_VALUE);
   }
  }

  sum[0][0] = val[0][0];

  Queue<Position> queue = new LinkedList<Position>();
  Position position = new Position(0, 0);
  queue.add(position);

  while (!queue.isEmpty()) {
   System.out.println(queue);
   
   Position po = queue.poll();
   long curSum = sum[po.y][po.x];
   // up
   
   
   for (int j = 0; j < path.length; j++) {
     System.out.println(Arrays.toString(sum[j]));
   }
   
   System.out.println();
   
   if (canGo(po.x, po.y - 1)) {
    if (sum[po.y - 1][po.x] > curSum + val[po.y - 1][po.x]) {
     sum[po.y - 1][po.x] = curSum + val[po.y - 1][po.x];
     queue.add(new Position(po.x, po.y - 1));

    }
   }

   // right
   if (canGo(po.x + 1, po.y)) {
    if (sum[po.y][po.x + 1] > curSum + val[po.y][po.x + 1]) {
     sum[po.y][po.x + 1] = curSum + val[po.y][po.x + 1];
     queue.add(new Position(po.x + 1, po.y));
    }
   }

   // left
   if (canGo(po.x - 1, po.y)) {
    if (sum[po.y][po.x - 1] > curSum + val[po.y][po.x - 1]) {
     sum[po.y][po.x - 1] = curSum + val[po.y][po.x - 1];
     queue.add(new Position(po.x - 1, po.y));
    }
   }

   // down
   if (canGo(po.x, po.y + 1)) {
    if (sum[po.y + 1][po.x] > curSum + val[po.y + 1][po.x]) {
     sum[po.y + 1][po.x] = curSum + val[po.y + 1][po.x];
     queue.add(new Position(po.x, po.y + 1));
    }
   }
   
   
   
   
   
  }

  for (int j = 0; j < path.length; j++) {
    System.out.println(Arrays.toString(sum[j]));
  }

  for (int j = 0; j < path.length; j++) {
   min = Math.min(min, sum[j][4]);
  }

  System.out.println(sum[4][4]);

  System.out.println(System.currentTimeMillis() - start);

 }

 public static boolean canGo(int x, int y) {
  int limit = 5;
  if (0 <= x && x < limit && 0 <= y && y < limit) {
   return true;
  }
  return false;
 }

}

class Position {
 int x;
 int y;

 public Position(int x, int y) {
  this.x = x;
  this.y = y;
 }

 /* (non-Javadoc)
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
  return "P (y=" + y + " , x=" + x + ")";
 }
 
 
}

Problem 80

I solve this problem by using 57 problem, 64, 65
I think problem is getting harder than before and....
because of time and difficulty, It seem that I want to stop it.
but I wil do it continuously


Tuesday, March 3, 2015

I started Just Python

My first Language was Java
Second is javascript,
third is c
fourth is Python which I'm trying to learn ~!

Compare to java.
this is amazing and very simple

ex)
>>> 3 * 'abc' + 'de'
'abcabcabcde'

>>> word = 'Python'
>>> word[0:2]
'Py'

Very Very Interesting..

I will use it more and more