tag:blogger.com,1999:blog-88499149362288979132024-03-12T23:57:50.394-07:00Brady's StudyingAnonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.comBlogger26125tag:blogger.com,1999:blog-8849914936228897913.post-72863734273660506472014-04-26T23:01:00.001-07:002014-04-26T23:01:26.996-07:00[Python][CheckiO] Open LabyrinthBasically this task can be solved applying DFS algorithm.<br />
<br />
If there's anything confusing, please refer to "Disposable teleports"<br />
<br />
Link: <a href="http://bradyisstudying.blogspot.tw/2014/04/checkiopython-disposable-teleports.html">http://bradyisstudying.blogspot.tw/2014/04/checkiopython-disposable-teleports.html</a><br />
<br />
--<br />
<br />
Some tricks are used for this task.<br />
<br />
(1) map refinement to avoid 2x2 quad dead-lock<br />
<br />
(2) path recording to avoid circular dead-lock<br />
<br />
There is a strong relation between (1) and (2) and I believe (2) is a more general solution.<br />
<br />
I will review my code sooner or later to make it more clear and intuitive<br />
<br />
--<br />
<br />
Following is the "raw" source code which is counter-intuitive, confusing, and containing lots of redundant code right now.LOL<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def is_north_valid(cur_pos, maze_map):
if cur_pos[0] - 1 < 0:
return False
if maze_map[ cur_pos[0] - 1][cur_pos[1]] == 0:
return True
return False</code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def is_south_valid(cur_pos, maze_map):
if cur_pos[0] + 1 >= len(maze_map):
return False
if maze_map[ cur_pos[0] + 1][cur_pos[1]] == 0:
return True
return False</code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def is_east_valid(cur_pos, maze_map):
if cur_pos[1] + 1 >= len(maze_map):
return False
if maze_map[ cur_pos[0]][cur_pos[1]+1] == 0:
return True
return False </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def is_west_valid(cur_pos, maze_map):
if cur_pos[1] - 1 < 0:
return False
if maze_map[ cur_pos[0]][cur_pos[1]-1] == 0:
return True
return False </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def get_num_to_go(cur_pos, maze_map):
count = 0
if is_south_valid(cur_pos, maze_map):
count += 1
if is_north_valid(cur_pos, maze_map):
count += 1
if is_west_valid(cur_pos, maze_map):
count += 1
if is_east_valid(cur_pos, maze_map):
count += 1
return count </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def suggest_go(cur_pos, maze_map, prev_dir, direct):
num_to_go = get_num_to_go(cur_pos, maze_map)
if num_to_go > 1 and prev_dir == direct:
return False
else:
return True </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def never_go(cur_pos, record_map, direct):
record = record_map[ cur_pos[0] ][ cur_pos[1] ]
#print(record)
#print(direct)
if direct not in record:
return True
else:
return False </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def which_dir(cur_pos, l_path, maze_map, record_map, pop):
#print ('qq: '+str(record_map[9][5]))
if pop == False:
prev_dir = ''
if len(l_path) > 0:
prev_dir = l_path[ len(l_path) - 1 ]
if is_south_valid(cur_pos, maze_map) == True and prev_dir != 'N' and never_go(cur_pos, record_map, 'S') == True:
l_path.append('S')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('S')
pop = False
cur_pos[0] += 1
return 'south'
elif is_east_valid(cur_pos, maze_map) == True and prev_dir != 'W' and never_go(cur_pos, record_map, 'E') == True:
l_path.append('E')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('E')
pop = False
cur_pos[1] += 1
return 'east'
elif is_west_valid(cur_pos, maze_map) == True and prev_dir != 'E' and never_go(cur_pos, record_map, 'W') == True:
l_path.append('W')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('W')
cur_pos[1] -= 1
pop = False
return 'west'
elif is_north_valid(cur_pos, maze_map) == True and prev_dir != 'S' and never_go(cur_pos, record_map, 'N') == True:
l_path.append('N')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('N')
cur_pos[0] -= 1
pop = False
return 'north'
else:
#return 'dead'
print('d')
pop = True
return which_dir(cur_pos, l_path, maze_map, record_map, pop)
else: # pop case
prev_dir = l_path.pop()
prev_2_dir = l_path[ len(l_path) - 1 ]
if prev_dir == 'S':
cur_pos[0] -= 1
if is_east_valid(cur_pos, maze_map) == True and prev_2_dir != 'W':
l_path.append('E')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('E')
cur_pos[1] += 1
pop = False
return 'east'
elif is_west_valid(cur_pos, maze_map) == True and prev_2_dir != 'E':
l_path.append('W')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('W')
cur_pos[1] -= 1
pop = False
return 'west'
elif is_north_valid(cur_pos, maze_map) == True and prev_2_dir != 'S':
l_path.append('N')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('N')
cur_pos[0] -= 1
pop = False
return 'north'
else:
#return 'dead'
pop = True
return which_dir(cur_pos, l_path, maze_map, record_map, pop)
elif prev_dir == 'E':
cur_pos[1] -= 1
if is_west_valid(cur_pos, maze_map) == True and prev_2_dir != 'E':
l_path.append('W')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('W')
cur_pos[1] -= 1
pop = False
return 'west'
elif is_north_valid(cur_pos, maze_map) == True and prev_2_dir != 'S':
l_path.append('N')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('N')
cur_pos[0] -= 1
pop = False
return 'north'
else:
#return 'dead'
pop = True
return which_dir(cur_pos, l_path, maze_map, record_map, pop)
elif prev_dir == 'W':
cur_pos[1] += 1
if is_north_valid(cur_pos, maze_map) == True and prev_2_dir != 'S':
l_path.append('N')
record_map[ cur_pos[0] ][ cur_pos[1] ].append('N')
cur_pos[0] -= 1
pop = False
return 'north'
else:
#return 'dead'
pop = True
return which_dir(cur_pos, l_path, maze_map, record_map, pop)
elif prev_dir == 'N':
cur_pos[0] += 1
#return 'dead'
pop = True
return which_dir(cur_pos, l_path, maze_map, record_map, pop) </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def only_one_exit(row, col, maze_map):
count = 0
exit_code = 0
if maze_map[row][col-1] == 0:
exit_code = 1
count += 1
if maze_map[row+1][col-1] == 0:
exit_code = 2
count += 1
if maze_map[row-1][col] == 0:
exit_code = 3
count += 1
if maze_map[row-1][col+1] == 0:
exit_code = 4
count += 1
if maze_map[row+2][col] == 0:
exit_code = 5
count += 1
if maze_map[row+2][col+1] == 0:
exit_code = 6
count += 1
if maze_map[row][col+2] == 0:
exit_code = 7
count += 1
if maze_map[row+1][col+2] == 0:
exit_code = 8
count += 1
if count == 1:
return [True, exit_code]
else:
return [False, exit_code] </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def refine_map(maze_map):
#case 1 : quad all zero
# 1 1 1 1
# 1 0 0 1
# 1 0 0 1
# 1 1 1 1
for row in range(2, len(maze_map) - 2): #dont need to touch (1,1) and (10, 10)
for col in range(2, len(maze_map) - 2):
if maze_map[row][col] == 0 and maze_map[row][col+1] == 0 and maze_map[row+1][col] == 0 and maze_map[row+1][col+1] == 0:
#print ('found quad: '+ str(row) +' '+ str(col))
l_map_scanner = only_one_exit(row, col, maze_map)
if l_map_scanner[0] == True:
#print ('found quad with one exit: '+ str(row) +' '+ str(col))
if l_map_scanner[1] == 1 or l_map_scanner[1] == 7:
maze_map[row + 1][col] = 1
maze_map[row + 1][col + 1] = 1
if l_map_scanner[1] == 2 or l_map_scanner[1] == 8:
maze_map[row][col] = 1
maze_map[row][col + 1] = 1
if l_map_scanner[1] == 3 or l_map_scanner[1] == 5:
maze_map[row][col + 1] = 1
maze_map[row + 1][col + 1] = 1
if l_map_scanner[1] == 4 or l_map_scanner[1] == 6:
maze_map[row ][col] = 1
maze_map[row + 1][col] = 1
return maze_map </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def get_record_map(dim):
l_record_map = [ ]
ll_record_map = [ ]
for row in range(0, dim):
for col in range(0, dim):
l_record_map.append([ ])
ll_record_map.append(l_record_map)
l_record_map = [ ]
return ll_record_map </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def checkio(maze_map):
l_path = [ ]
cur_pos = [1, 1]
maze_map = refine_map(maze_map)
record_map = get_record_map(len(maze_map))
#print(maze_map)
#for i in range(0, 50):
while cur_pos != [10, 10]:
dir = which_dir(cur_pos, l_path, maze_map, record_map, False)
#print(dir)
return ''.join(l_path)
</code></pre>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-82683650346221733842014-04-13T09:14:00.000-07:002014-04-13T09:17:01.238-07:00[Python][CheckiO]Feed Pigeons<div class="separator" style="clear: both; text-align: center;">
</div>
Simple task, but the problem description is a lil bit hard to understand.<br />
<br />
Therefore I made a representative figure as follows.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinmDQZ-C2WAsXmvfADYD6U6svTP1Ee5OU5dkWYaAtifmOURgZ5yWlQosuo84vBQWasSOxNu86c6WlIfUAYbW5-4umnYX8baQ6tMhwEHt6BbNdF-3bagd2TR7ywCTqcI7q3CW0IOkZTe9xa/s1600/%E6%9C%AA%E5%91%BD%E5%90%8D.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinmDQZ-C2WAsXmvfADYD6U6svTP1Ee5OU5dkWYaAtifmOURgZ5yWlQosuo84vBQWasSOxNu86c6WlIfUAYbW5-4umnYX8baQ6tMhwEHt6BbNdF-3bagd2TR7ywCTqcI7q3CW0IOkZTe9xa/s1600/%E6%9C%AA%E5%91%BD%E5%90%8D.png" height="56" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
In the 1st minute, only one pigeon can be fed.<br />
<br />
In the 2nd minute, besides the original pigeon(came in the 1st minute), another two pigeons come.<br />
<br />
In the 3rd minute, another three comes beside to the original three (came in the 1st and 2nd minute)<br />
<br />
--<br />
<br />
According to the aforementioned description, we know the number of new pigeons is exactly the same as the delta of time (in minute)<br />
<br />
After understanding the rules above, it is easy to calculate how many pigeons can be fed<br />
<br />
--<br />
<br />
Following is the source code:<br />
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> def add_new_pigeons(minute):
return minute </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def calculate_total_pigeons(minute):
total = 0
for m in range(1, minute+1):
total += m
return total </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def checkio(food):
minute = 1
while (food > 0):
new_group = add_new_pigeons(minute)
total_pigeons = calculate_total_pigeons(minute)
food -= total_pigeons
if food < 0:
new_pigeons = new_group - abs(food)
if new_pigeons < 0: # none of the new pigenons gets fed
new_pigeons = 0
return calculate_total_pigeons(minute - 1) + new_pigeons
elif food == 0:
return total_pigeons
minute += 1
</code></pre>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-60570697035953524832014-04-12T11:03:00.001-07:002014-04-12T22:34:18.330-07:00[Python][CheckiO] Radiation searchIn order to solve this task, I use recursive flood fill algorithm to search the neighbor with same value.<br />
<br />
Be attention to the usage of recursion, especially the push and pop operation of context (use return function in a suitable time).<br />
<br />
Some tricks are used in this task.<br />
<br />
(1) expand the matrix in order to avoid list boundary access violation<br />
<br />
(2) use another matrix (traversed_mask) to avoid re-filling the region<br />
<br />
--<br />
<br />
Source code is listed as follows.<br />
<br />
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #flood fill algorithm </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def get_dim(matrix):
return len(matrix[0]) </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def expand_matrix(dim, matrix):
ll_expanded_matrix = [ ]
l_expanded_row = []
for i in range(0, dim):
l_expanded_row.append(-1)
ll_expanded_matrix.append(l_expanded_row)
l_expanded_row = [-1] #point to another new list
for row in range(0, dim-2): #because dim is for expanded matrix
for col in range(0, dim-2):
l_expanded_row.append(matrix[row][col])
l_expanded_row.append(-1) #tail -1
ll_expanded_matrix.append(l_expanded_row)
l_expanded_row = [-1] #point to another new list
for i in range(0, dim):
l_expanded_row.append(-1)
ll_expanded_matrix.append(l_expanded_row)
return ll_expanded_matrix </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def gen_traversed_mask(dim):
l_mask = [ ]
ll_mask = [ ]
for row in range(0, dim):
for col in range(0, dim):
l_mask.append(0)
ll_mask.append(l_mask)
l_mask = [ ]
return ll_mask </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def is_same_union(x, y, matrix):
if matrix[y][x] == matrix[y-1][x] or matrix[y][x] == matrix[y+1][x] or matrix[y][x] == matrix[y][x+1] or matrix[y][x] == matrix[y][x-1]:
return True
else:
return False </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def flood(x, y, target, dim, traversed_mask, matrix, count):
if x > 0 and x < dim - 1 and y > 0 and y < dim - 1 and traversed_mask[y][x] == 0:
if matrix[y][x] == target and is_same_union(x, y, matrix) == True:
count += 1
else:
return count
traversed_mask[y][x] = 1
count = flood(x-1, y , target, dim, traversed_mask, matrix, count)
count = flood(x+1, y , target, dim, traversed_mask, matrix, count)
count = flood(x , y-1, target, dim, traversed_mask, matrix, count)
count = flood(x , y+1, target, dim, traversed_mask, matrix, count)
return count </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def checkio(matrix):
count = 0
ll_result = [ ]
dim = get_dim(matrix)+2 # add two for expanded matrix
expanded_matrix = expand_matrix(dim, matrix)
traversed_mask = gen_traversed_mask(dim)
for row in range(1, dim-1):
for col in range(1, dim-1):
count = flood(col, row, expanded_matrix[row][col], dim, traversed_mask, expanded_matrix, count)
ll_result.append([count, expanded_matrix[row][col]])
traversed_mask = gen_traversed_mask(dim)
count = 0
ll_result = sorted( ll_result, key=lambda l_result: l_result[0], reverse=True)
return ll_result[0]
</code></pre>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-87144284461336060382014-04-08T09:52:00.002-07:002014-04-12T10:55:13.122-07:00[Python][CheckiO] How much gold<div>
In order to solve this problem, we need to calculate the following proportion</div>
<div>
<br /></div>
<div>
(a1) gold-tin</div>
<div>
<br /></div>
<div>
(a2) gold-copper</div>
<div>
<br /></div>
<div>
(a3) gold-iron</div>
<div>
<br /></div>
<div>
Once we got (a1), (a2), and (a3), we can calculate the proportion of gold applying the following equation:</div>
<div>
<br /></div>
<div>
<i>gold = ( (a1)+(a2)+(a3) - 1 ) / 2</i></div>
<div>
<br /></div>
<div>
Therefore we can divide this question into three sub-questions (a1) (a2) (a3).</div>
<div>
<br /></div>
<div>
Firstly, we can categorize the given proportion into two classes.</div>
<div>
<br /></div>
<div>
<div>
(b1) proportion consists of "gold"</div>
<div>
Ex. gold-tin proportion</div>
<div>
<br /></div>
<div>
(b2) proportion doesn't consist of "gold"</div>
<div>
Ex. copper-iron proportion</div>
</div>
<div>
<br /></div>
<div>
If the given proportion belongs to (b1), we just return it</div>
<div>
<br /></div>
<div>
However, when it belongs to (b2), we return (1 - <i>given_proportion</i>)</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
And following is the source code</div>
<div>
<br /></div>
<div>
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> from fractions import Fraction </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
METALS = ('gold', 'tin', 'iron', 'copper') </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def get_proportion(ele1, ele2, ele3, ele4, alloys):
#print(ele1+','+ele2+','+ele3+','+ele4)
if ele1+'-'+ele2 in alloys:
return alloys[ele1+'-'+ele2]
elif ele2+'-'+ele1 in alloys:
return alloys[ele2+'-'+ele1]
elif ele3+'-'+ele4 in alloys:
return 1 - alloys[ele3+'-'+ele4]
elif ele4+'-'+ele3 in alloys:
return 1 - alloys[ele4+'-'+ele3]
else:
assert(0) </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def checkio(alloys):
#step 1. find proportion of gold-tin, gold-iron, and gold-copper
gold_tin = get_proportion('gold', 'tin', 'iron', 'copper', alloys)
gold_iron = get_proportion('gold', 'iron', 'tin', 'copper', alloys)
gold_copper = get_proportion('gold', 'copper', 'tin', 'iron', alloys)
#step 2.
return Fraction(gold_tin + gold_iron + gold_copper - 1, 2)
</code></pre>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-43352819276828574502014-04-06T07:11:00.001-07:002014-04-06T07:16:36.125-07:00[Python][CheckiO] Solve Disposable teleportsFirstly I thought it was the Eular Circuit problem, so it took me couples of days to review the Eular Path and the Eular Circuit. During the implementation, I found it was not that hard and could be solved applying DFS algorithm.<br />
<br />
<br />
Here's the source code
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> def list_sub(l_a, l_b):
return [i for i in l_a if not i in l_b or l_b.remove(i)] </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def bi_direction_list_sub(l_a, l_b):
l_valid_path = [ ]
for i in l_a:
rev_i = (i % 10) * 10 + (i // 10)
if not i in l_b:
if not rev_i in l_b:
l_valid_path.append(i)
return l_valid_path </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def get_map_list(teleports_string):
l_map = [ int(i) for i in teleports_string.split(',')]
l_map_bi_direction = [i for i in l_map]
for p in l_map:
p_rev = (p % 10) * 10 + (p // 10)
l_map_bi_direction.append(p_rev)
sorted(l_map_bi_direction)
return l_map_bi_direction </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def get_path(l_tel, l_ret, last_path, last_pop):
l_working_path = bi_direction_list_sub(l_tel, l_ret)
sorted(l_working_path)
for p in l_working_path:
if str(p)[0] == str(last_path)[ len(str(last_path)) - 1 ]:
if every_node_be_traversed(l_ret) == False:
if p > last_pop:
return p
return 'dead' </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def every_node_be_traversed(l_ret):
l_traversed_node = [str(path)[0] for path in l_ret]
for i in range(1, 9):
if not str(i) in l_traversed_node:
return False
if str(l_ret[len(l_ret) - 1])[1] != '1':
return False
return True </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def remove_path_from_candidate(l_tmp_tel, path):
rev_path = (path % 10) * 10 + (path // 10 )
if path in l_tmp_tel:
l_tmp_tel.remove(path)
if rev_path in l_tmp_tel:
l_tmp_tel.remove(rev_path) </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def add_candidate(l_tmp_tel, path):
rev_path = (path % 10) * 10 + (path // 10 )
if not path in l_tmp_tel:
l_tmp_tel.append(path)
if not rev_path in l_tmp_tel:
l_tmp_tel.append(rev_path)</code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">
def checkio(teleports_string):
l_ret = [ ]
l_tel = get_map_list(teleports_string)
l_tmp_tel = [i for i in l_tel]
last_path = 1
last_pop = 1
while every_node_be_traversed(l_ret) == False:
path = get_path(l_tmp_tel, l_ret, last_path, last_pop)
if path == 'dead': #dead end
if len(l_ret) == 0:
last_path = 1
last_pop = 1
else:
last_pop = l_ret.pop()
add_candidate(l_tmp_tel, last_pop)
if str(last_pop)[0] == '1':
last_path = 1
last = 1
continue
else:
last_path = l_ret[ len(l_ret) - 1]
continue
last_pop = 1
last_path = path
l_ret.append(path)
remove_path_from_candidate(l_tmp_tel, path)
l_tmp_tel = sorted(l_tmp_tel)
l_str_ret = [str(i)[0] for i in l_ret]
ret = ''.join(l_str_ret)+'1'
return ret
</code></pre>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-16841038213998259032014-03-26T09:32:00.003-07:002014-03-26T09:32:51.850-07:00[Python][CheckIO] Solve Ghosts age莫名其妙一個簡單的題目寫了兩天於是紀念一下<br />
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> def is_fibonacci(num):
cur = 0
prev1 = 1
prev2 = 0
while cur < num:
cur = prev1 + prev2
prev2 = prev1
prev1 = cur
if num == cur:
return True
else:
return False </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> def checkio(opacity):
if opacity == 10000:
return 0
cur = 10000
last_fibonacci = 1
for yrs in range(1, 5000):
if is_fibonacci(yrs) == True:
if cur - yrs == opacity:
return yrs
else:
cur -= yrs
last_fibonacci = yrs
else:
if cur + 1 == opacity:
return yrs
else:
cur += 1
</code></pre>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-32329478690856623412014-03-22T22:19:00.000-07:002014-03-26T09:33:58.536-07:00[Python] Formatted Binary<pre class="lang-py prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 17.804800033569336px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">>>></span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">'{0:08b}'</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">format</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">6</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">00000110</span></code></pre>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.804800033569336px; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Just to explain the parts of the formatting string:</div>
<ul style="background-color: white; border: 0px; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 17.804800033569336px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;">
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: pre-wrap;">{}</code> places a variable into a string</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: pre-wrap;">0</code> takes the variable at argument position 0</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: pre-wrap;">:</code> adds formatting options for this variable (otherwise it would represent decimal <code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: pre-wrap;">6</code>)</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: pre-wrap;">08</code> formats the number to eight digits zero-padded on the left</li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: pre-wrap;">b</code> converts the number to its binary representation</li>
</ul>
<div>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 17.804800033569336px;">ref. http://stackoverflow.com/questions/10411085/converting-integer-to-binary-in-python </span></span></div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-77422274435812330132014-03-16T08:25:00.003-07:002014-03-16T08:26:30.840-07:00[Python] key function for sorting<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"><b>Example</b></code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> def checkio(numbers_array):
list_num = list(numbers_array)
list_num = sorted(list_num, key=abs)
return list_num
</code></pre>
<br />
<br />
[Note]<br />
<br />
1. <span style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;">The value of the </span><tt style="background-color: white;">key</tt><span style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;"> parameter should be a function </span><span class="anchor" id="line-56" style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;"></span><span style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;">that takes a <b>single</b> argument and returns a key to use for sorting purposes</span><br />
<span style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;"><br /></span>
<span style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;">2. </span><span style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;">A common pattern is to sort complex objects using some of the object's </span><span class="anchor" id="line-61" style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;"></span><span style="background-color: white; font-family: Arial, Verdana, Geneva, 'Bitstream Vera Sans', Helvetica, sans-serif; font-size: 14px; line-height: 21.259199142456055px;">indices as a key</span><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"><b>Example</b> </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">>>> student_tuples = [
('john', 'A', 15),
('jane', 'B', 12),
('dave', 'B', 10),
]
>>> sorted(student_tuples, key=lambda student: student[2]) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
</code></pre>
<br />
[Ref]<br />
<br />
https://wiki.python.org/moin/HowTo/Sorting/#Key_FunctionsAnonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-76188875035284249362014-03-08T08:53:00.002-08:002014-03-08T08:53:19.850-08:00[Python] Roman Numerals ConverterSpeedy solution:<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">1: def checkio(input):
2: ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
3: nums = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
4:
5: result = ""
6:
7: for i in range(len(ints)):
8: count = int(input / ints[i])
9: result += nums[i] * count
10: input -= ints[i] * count
11:
12: return result
</code></pre>
<br />
<br />
ref . http://www.rapidtables.com/math/symbols/roman_numerals.htm<br />
<br />
--<br />
<br />
人家寫12行我寫108行,真 他媽的Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-46509130521985207032013-03-09T07:13:00.001-08:002013-03-09T07:15:42.367-08:00Android layoutReview Android Layout<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom= "true">
<Button
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="exit"
android:id="@+id/btExit"
android:layout_alignParentBottom= "true"/>
<Button
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="add"
android:id="@+id/btAdd"
/>
<Button
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="test"
android:id="@+id/btTest"
/>
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above= "@+id/LinearLayout02">
<Button
android:id="@+id/btframeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="framelayout"/>
</FrameLayout>
</RelativeLayout>
</code></pre>
<br />
<br />
效果如下:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZtJt-xYvjdzl7M6UgRNHbTpqZPk470gW4gIomzF0z9JG6L5V-DEzHADZus96F0uKLVVF-X-SAyAc5aEDgrhAn3xzvoiEUBRNu-NpRic33mdX22X5T5VwK_AyMkpgyMLTpac2CACglDJ0U/s1600/lll.png" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZtJt-xYvjdzl7M6UgRNHbTpqZPk470gW4gIomzF0z9JG6L5V-DEzHADZus96F0uKLVVF-X-SAyAc5aEDgrhAn3xzvoiEUBRNu-NpRic33mdX22X5T5VwK_AyMkpgyMLTpac2CACglDJ0U/s320/lll.png" /></a><br />
<br />
Ref.<br />
<a href="http://corn0521.blogspot.tw/2011/04/android-relativelayout.html">http://corn0521.blogspot.tw/2011/04/android-relativelayout.html</a>Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-7348064295667298632013-02-01T06:51:00.003-08:002013-02-02T02:29:00.986-08:00Concrete Class vs. Abstract Class<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><b>Abstract Class</b></span><br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><b><br /></b></span>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><u>An abstract class is a class for which one or more methods are declared but not defined</u>, meaning that the compiler knows these methods are part of the class, but not what code to execute for that method.</span><br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><br /></span><span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;">Eg.</span></span><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> class shape
{
public:
virtual void draw() = 0;
};
</code></pre>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><br /></span>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">You cannot instantiate this class because it is abstract, after all, the compiler wouldn't know what code to execute if you called member draw.</span><br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><br /></span>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><br /></span>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><b>Concrete Class</b></span><br />
<br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><u>A class that has any abstract methods is abstract, any class that doesn't is concrete</u>.</span><br />
<br />
Eg.<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> class circle : public shape {
public:
circle(int x, int y, int radius) {
/* set up the circle */
}
void draw() {
/* do stuff to draw the circle */
}
};
class rectangle : public shape {
public:
rectangle(int min_x, int min_y, int max_x, int max_y) {
/* set up rectangle */
}
void draw() {
/* do stuff to draw the rectangle */
}
};
</code></pre>
<br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">Now you can instantiate the concrete objects circle and rectangle and use their draw methods:</span><br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><br /></span>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">Eg.</span><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> circle my_circle(40, 30, 10);
rectangle my_rectangle(20, 10, 50, 15);
my_circle.draw();
my_rectangle.draw();
</code></pre>
<br />
<br />
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><b>Question 1: </b></span></span><span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">Why would you want to do this?</span><br />
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><br /></span>
<span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;"><b>Ans:</b> To take advantage of the inheritance</span><br />
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><br /></span></span>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;">Eg.</span></span><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> std::vector<shape*> my_scene;
my_scene.push_back(new circle(40, 30, 10));
my_scene.push_back(new rectangle(20, 10, 50, 15));
</code></pre>
<br />
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><br /></span></span>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><b>Question 2: </b></span></span><span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">Why the draw function of shape is abstract, and not just an empty function?</span><br />
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><br /></span></span>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><b>Ans:</b> W</span></span><span style="background-color: white; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px;">e don't want objects of type shape, they wouldn't be real things anyway. So it doesn't make sense to define an implementation for the draw method. Making the shape class abstract prevents us from mistakenly instantiating the shape class, or mistakenly calling the empty draw function of the base class instead of the draw function of the derived classes.</span><br />
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;"><br /></span></span>
<span style="font-family: Arial, Liberation Sans, DejaVu Sans, sans-serif;"><span style="font-size: 14px; line-height: 18px;">--</span></span><br />
<br />
ref. <a href="http://stackoverflow.com/questions/2149207/what-is-the-difference-between-a-concrete-class-and-an-abstract-class">http://stackoverflow.com/questions/2149207/what-is-the-difference-between-a-concrete-class-and-an-abstract-class</a>Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-66923311743224941002013-02-01T06:03:00.004-08:002013-02-01T06:08:07.926-08:00Design patterns - overview<iframe allowfullscreen="" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/16293353" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/design-pattern-overview" target="_blank" title="design pattern overview">design pattern overview</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-26323662120930674332013-01-27T07:26:00.000-08:002013-01-27T07:26:27.204-08:00英文俚語一則<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> dafaq
【義】Shortened form of "The Fuck". Also used instead of "What The Fuck".
【例】Dafaq is this?
</code></pre>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTzfn8YGb5aId9zCtPMtYJWuZETZ87o02iLZLYr4BeycFuo2KdP3vcnsVN50fw_b8nO4-ggeG2m9yen9KMZUeIf1CbmEeQqmjv-_CPsrlQ95O_jQBFr6iDPkejLZFLk0y9UWjY6YXpyRVm/s1600/DAFAQ+_4a6276d67a4a4a5e78eca3021b599073.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTzfn8YGb5aId9zCtPMtYJWuZETZ87o02iLZLYr4BeycFuo2KdP3vcnsVN50fw_b8nO4-ggeG2m9yen9KMZUeIf1CbmEeQqmjv-_CPsrlQ95O_jQBFr6iDPkejLZFLk0y9UWjY6YXpyRVm/s1600/DAFAQ+_4a6276d67a4a4a5e78eca3021b599073.jpg" /></a></div>
<br />Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-5877125308037982662013-01-23T08:31:00.002-08:002013-01-23T08:31:21.355-08:00英文俚語三則<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> whipped
【義】Being completely controlled by your girlfriend or boyfriend
【例】He is whipped
</code></pre>
<br />
Whipped 通常用在男生身上,意思類似妻(女友)管嚴。<br />
<br />
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> tramp
【義】Any woman who will open her legs for anyone, except for me.
【例】She is such a tramp
</code></pre>
<br />
中文意思有點像把不到的花蝴蝶(貶意)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP_zBG4kdP2Sz7L5L5SuehV11R2Bp17vWKVH-xObwABiOyc1V3n2UGw2KASq0MrLbzWY0s-8MtNUMrioIJ6egdpOCgTm_2-2PcEjBKz_lccJYes3bVbrUKCxzsYjgGajp8beWXjHvx7rFJ/s1600/tramp.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP_zBG4kdP2Sz7L5L5SuehV11R2Bp17vWKVH-xObwABiOyc1V3n2UGw2KASq0MrLbzWY0s-8MtNUMrioIJ6egdpOCgTm_2-2PcEjBKz_lccJYes3bVbrUKCxzsYjgGajp8beWXjHvx7rFJ/s400/tramp.png" width="380" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> fucked in the head
【義】Idiotic, stupid, not too clever.
【例】He is fucked in the head
</code></pre>
<br />
就是stupid的意思,簡單稱為腦殘。 下面圖裡的學生就是fucked in the head的經典。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_kkS7ySNnpbsaFVW1E2eb4AbnbK_JoLAqBeqhLgJWQlACMzwDjOyAMjKLEBHtNTZOC3mcCYQPIttSTDKx7fg7FDdrLm_TkusUscgaf5Az2OpP3EIQuHSmHp_KZ-I8_deI05CH6hkCG88x/s1600/fucked+in+the+head.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_kkS7ySNnpbsaFVW1E2eb4AbnbK_JoLAqBeqhLgJWQlACMzwDjOyAMjKLEBHtNTZOC3mcCYQPIttSTDKx7fg7FDdrLm_TkusUscgaf5Az2OpP3EIQuHSmHp_KZ-I8_deI05CH6hkCG88x/s400/fucked+in+the+head.png" width="325" /></a></div>
<br />
<br />
<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-59745107993035892822013-01-20T05:49:00.000-08:002013-01-20T05:50:58.799-08:00Active Record關係在【Ruby on Rails Up and Running】一書中,有一整個章節在討論Active Record關係。<br />
<div>
<br /></div>
<div>
說穿了,所謂的Active Record關係(以下簡稱ARR)是用來描述不同model間的關係,或者可以想</div>
<div>
<br /></div>
<div>
成database中不同table間的關係,ARR可用Domain Specific Language(DSL)來描述。</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
以下方這張簡單的架構圖來說 (ps. 圖片來源參考至【Ruby on Rails Up and Running】chapter 3,</div>
<div>
<br /></div>
<div>
如有侵權,請不嗇告知)<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUrZCwPogcAy8MzrJqhN3ecHcI9xBc-48DnV1XUMDHfJOUkQwIFvnMG2P5tJhKj8g3AO_UHGtCPsUWdPGKLoayQHwmMmxHDj6rSAZi_3h1bDmdan_DXQxWJU9c2MhaQGmDDknn7pTc6pV3/s1600/photoshare_architecture.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUrZCwPogcAy8MzrJqhN3ecHcI9xBc-48DnV1XUMDHfJOUkQwIFvnMG2P5tJhKj8g3AO_UHGtCPsUWdPGKLoayQHwmMmxHDj6rSAZi_3h1bDmdan_DXQxWJU9c2MhaQGmDDknn7pTc6pV3/s400/photoshare_architecture.png" width="400" /></a></div>
<br />
<br />
這是一張線上瀏覽圖片的系統之架構,其中每個藍色方塊代表一個model,可以清楚的看到不<br />
<br />
同的model間存在一些關係,其中包括 Many to one, 以及Many to many。<br />
<br />
所代表的意義類似:<br />
<br />
1. 分類(category)和照片(photo)存在多對多關係, 一種分類中會有多張照片,一張照片亦可能<br />
<br />
屬於多個分類<br />
<br />
2. 投影片(slide)和照片(photo)存在多對一關係,多張投影片可能參照到同一張照片<br />
<br />
--<br />
<br />
清楚釐清不同model間的關係之後,我們就可以用DSL來描述這些關係。<br />
<br />
我們將DSL寫在相關的model中,舉例來說,要描述photo和slide間的關係,<br />
<br />
我們可能會把photo寫成下面的樣子:<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> class Photo < ActiveRecord::Base
has_many :slides
end
</code></pre>
<br />
另一方面,我們也會把slide寫成:<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> class Slide < ActiveRecord::Base
belongs_to :photo
end
</code></pre>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
由上面兩段code,我們清楚的看到兩個重點:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
1. photo has many slides</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
2. slide belongs to (a) photo</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
藉由這種和自然語言很相像的DSL,我們就可以為每種關係塑模。</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
除此之外,針對photo和category之間的多對多關係,</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
我們也可以更改photo的程式碼為:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> class Photo < ActiveRecord::Base
has_and_belongs_to_many :categories
has_many :slides
end
</code></pre>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
並且在category model中寫下:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOxm4d2xWL8V9Qq7wyN31HgRhr1dey0dTZ5hMVkFEBHMgRWu4QcBr_jHBmjcLAnCqLU0xnL_RQIASphD_m0D6kTzbXipoACiTUM9XPBnScq907idQPsDWNjszR9D4d6Fcidfn-Lm8xNn_m/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> class Category < ActiveRecord::Base
has_and_belongs_to_many :photos
end
</code></pre>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
一樣的,我們可以很白話的看出當中的關係:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
1. Photo has and belongs to many categories</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
2. Category (also) has and belongs to many photos</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
如此一來,我們便可對不同model間的關係塑模了。</div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-31759172448771383902013-01-20T02:15:00.003-08:002013-01-21T07:53:00.770-08:00How to start RoR project1. start a new project<br />
<br />
<b> rails new <i>project_name</i></b><br />
<br />
2. create scaffolds for your project, and notice your schema of the model<br />
<br />
<b> rails generate scaffold <i>scaffolding_name</i> <i>schema_name</i>:<i>schema_type</i></b><br />
<br />
<u>ps1</u>. if model_name is Photo, then table_name would be photos, controller_name would be PhotosController, and scaffolding_name would be photo. This is what we call "convention"!<br />
<br />
<u>ps2</u>. after we use scaffolds, we will get MVC, but the database is not generated yet until we use migrate command<br />
<br />
<u>ps3</u>. there is no <u>int</u> in schema_type, use <u>integer </u>instead<br />
<br />
3. create database<br />
<br />
<b> rails db:migrate</b>Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-87785904080323455202013-01-20T01:16:00.005-08:002013-01-20T01:17:37.927-08:00給RoR初學者的小建議Hi all,<br />
<br />
我的練習過程是先找文件,邊讀邊寫。<br />
<br />
有個小地方要提醒大家,<br />
<br />
RoR是一個迅速發展的語言,<br />
<br />
或者更精確地來說,它僅是一種framework,<br />
<br />
語言本質上還是Ruby。<br />
<br />
離題了,重點是由於迅速的發展,<br />
<br />
會出現很多版本上的差異。<br />
<br />
以我為例,我手邊有本O'reilly的【Ruby on Rails Up and Running】<br />
<br />
裡面就有很多地方和目前的版本不同<br />
<br />
包含scaffolding和其他API,若單純照書上所寫的來實作,<br />
<br />
會遭遇很多大大小小的問題,<br />
<br />
因此,我推薦另一本書給大家【Rails 3 in Action】<br />
<br />
或是根據官方文件來練習。<br />
<br />
將可免去走冤枉路的風險。<br />
<br />
<br />
Best,<br />
BradyAnonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-90911521909707786142012-12-22T08:23:00.002-08:002012-12-22T08:23:59.515-08:00Ruby on Rails Guide - part 1This is RoR Guide - part 1 written by me.<br />
<br />
Agenda:<br />
<br />
1. installation<br />
<br />
2. write the first application<br />
<br />
<iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15735837" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/ror-guidep1" target="_blank" title="RoR guide_p1">RoR guide_p1</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-88907464854048798672012-11-18T09:18:00.000-08:002012-12-01T10:26:24.899-08:00Learn To Program - Part1<b>[Slide]</b><br />
<br />
<iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15233229" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/ruby-introduction-part1" target="_blank" title="Ruby introduction part1">Ruby introduction part1</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> <br />
<br />
<br />
<b>[Quick Review]</b><br />
<br />
<b>Numbers</b><br />
Integer, a series of digits which can start with a plus or minus sign.<br />
<i>1 , 23 , and -10000 are examples</i><br />
<i>population = 12_000_000_000 is also an example</i>.<br />
<br />
Float, consists of numbers with a decimal place or scientific notation.<br />
<i>3.14 , -808.08 and 12.043e-04 are examples</i><br />
<i><br /></i>
<b>Strings</b><br />
Any sort of characters (letters, digits, punctuation) surrounded by quotes. Both single and double quotes are used to create strings.<br />
<i>"sealab" , '2021' , or "These cartoons are hilarious!" are examples.</i><br />
<i><br /></i>
<b>Symbols</b><br />
Like variables. contain letters, digits, or underscores. But start with a colon. Symbols are lightweight strings. Usually, symbols are used in situations where you need a string but you won’t be printing it to the screen.<br />
<i>:a , :b , or :ponce_de_leon are examples.</i><br />
<b><br /></b>
<b>Constants</b><br />
Constants are words like variables, but constants are capitalized.<br />
<i>Time , Array or Bunny_Lake_is_Missing are examples.</i><br />
<i><br /></i>
<br />
<b>Variables</b><br />
Any plain, lowercase word is a variable. Variables may consist of letters, digits and underscores.<br />
<i>x , y , banana2 or phone_a_quail are examples.</i><br />
<b><br /></b>
<b>Global variables</b><br />
Variables which begin with a dollar sign are global.<br />
<i>$x , $1 , $chunky and $CHunKY_bACOn are examples.</i><br />
<i><br /></i>
<br />
<b>Instance variables</b><br />
Variables which begin with an at symbol are instance variables. Instance variables are used to define characteristics of a single object. Think of the at symbol as meaning attribute.<br />
<div style="font-style: italic;">
@x , @y are examples.</div>
<div style="font-style: italic;">
<br /></div>
<b>Class variables</b><br />
Variables which begin with double at symbols are class variables. class variables give an attribute to many related objects in Ruby. Think of the double at prefix as meaning attribute all.<br />
<i>@@x , @@y are examples.</i><br />
<br />
<br />
<i><br /></i>
<i><br /></i>
<br />
<br />
<br />
<br />
<br />
<br />
<i><br /></i>
</div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-39505131711120901242012-11-17T05:20:00.000-08:002013-02-01T23:27:51.430-08:00Head First JavaScript - Chapter 8 <iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15221337" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/javascript-ch8" target="_blank" title="Javascript ch8">Javascript ch8</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-91229883832612521192012-11-17T01:42:00.002-08:002013-02-01T23:28:07.443-08:00Head First JavaScript - Chapter 7<iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15219787" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/javascipt-ch7" target="_blank" title="Javascript ch7">Javascript ch7</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-52654606702362397562012-11-16T04:45:00.000-08:002013-02-01T23:28:22.161-08:00Head First JavaScript - Chapter 6<iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15207773" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/javascript-ch6" target="_blank" title="Javascript ch6">Javascript ch6</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-51913031586850201602012-11-15T07:28:00.000-08:002013-02-01T23:27:24.207-08:00Head First JavaScript - Chapter 4 & 5<iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15192085" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/javascipt-ch4-ch5" target="_blank" title="Javascipt ch4 & ch5">Javascipt ch4 & ch5</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-61512567051236415482012-11-14T09:19:00.002-08:002013-02-01T23:28:53.772-08:00Head First JavaScript - Chapter 3<iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15176542" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/javascipt-ch3" target="_blank" title="Javascipt ch3">Javascipt ch3</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0tag:blogger.com,1999:blog-8849914936228897913.post-80295979608514027932012-11-12T05:53:00.003-08:002013-02-01T23:28:37.814-08:00Head First JavaScript - Chapter 2<iframe allowfullscreen="allowfullscreen" frameborder="0" height="356" marginheight="0" marginwidth="0" mozallowfullscreen="mozallowfullscreen" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/15137395" style="border-width: 1px 1px 0; border: 1px solid #CCC; margin-bottom: 5px;" webkitallowfullscreen="webkitallowfullscreen" width="427"> </iframe> <br />
<div style="margin-bottom: 5px;">
<strong> <a href="http://www.slideshare.net/bradycheng/javascipt-ch2" target="_blank" title="Javascipt ch2">Javascipt ch2</a> </strong> from <strong><a href="http://www.slideshare.net/bradycheng" target="_blank">Brady Cheng</a></strong> </div>
Anonymoushttp://www.blogger.com/profile/01144827703097593306noreply@blogger.com0