Private Sub Command1_Click() '4058B0
看到這個function裡面的
loc_0040592D: Form1.Unknown_405A60(arg_8, eax, Form1.QueryInterface, eax+03h, "")
用ollydbg追進去
這段很明顯是在判斷數字正確性, 錯誤的話會跳到00405b02
所以就下幾個數字進去測試
發現, 全部數字加起來必須為16h, 且確定的位數為 4__09, 10次內搞定: )...
read more
總有新鮮事~
觀察 sourcecode.txt,由下面兩段code可以發現...
//register
fputs($hfile, ";::".$HTTP_POST_VARS['accessid']."::".$md5_passwd."::;\n");
//login
$datastring = $HTTP_POST_VARS['accessid']."::".$md5_pin;
if(strpos($con_file, $datastring)){
do check...
}
能夠偽裝成別人登入,
不過好像沒有用.....
再觀察別的地方!
// endsess
if((preg_match("/^[a-zA-Z0-9=]+$/i", $HTTP_GET_VARS['sessid'])==true)){
$session_file = "xxxxx/".$HTTP_GET_VARS['sessid'];
if(unlink($session_file)==false){
do something...
}
發現sessid在這邊不像register時候有檢查長度!
於是...DONE!
Section "InputDevice"
Identifier "Configured Mouse"
Driver "vmmouse"
Option "Protocol" "ImPS/2"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "ZAxisMapping" "4 5"
Option "Emulate3Buttons" "yes"
EndSection
...遊戲人數:3-4人
適合年齡:10歲以上
遊戲時間:約45分
遊戲設計:The Lamont Brothers
語言版本:英文
”絕對不要嚐試去預測移動中羊群的動向…” 今天是羊群的放牧日,牠們將在附近的原野上漫步,牠們會遇到傳說中的酷羊情聖,而要小心,剪毛工人就在附近等著抓住他所看到的所有羊隻…
在這個遊戲裡,您將扮演一群母羊,得在不同的時機與關卡,儘可能的控制與唯一的公羊、情聖、及剪毛人的距離,依據每個玩家輪流行使的動作,將會出現無可預料的爆笑情況,包準您哭笑不得!
製作精緻的羊咩咩模型、豐富的遊戲性,以及逗趣的遊戲流程,適合不同年齡層、不同深度的玩家!
遊戲人數:3-10人
適合年齡:8歲以上
遊戲時間:約30分
遊戲設計:Frederic Moyersoen
語言版本:圖片
遊戲目標:
三個目的地,玩家抽取角色牌決定好人或壞人(就是破壞者)後開始心機大對決!
好人目標是出隧道牌挖到真正的寶藏(另兩個是石頭)即獲勝,
壞人則須干擾及搞破壞,所有人手牌皆出完後若仍未挖到寶藏,則壞人獲勝。
遊戲特色:
◎玩家在寶藏挖到後或結束時才可以表明身份。
◎由出牌過程中猜測誰是好人誰是壞人是最大樂趣,相當心機。
◎有封鎖牌,可以對別的玩家使用,以禁止其使用通道牌,亦有解救牌。
◎有炸彈牌,可以炸毀死路或活路,也有地圖牌,可以先檢查寶藏位置。
◎角色牌共十一張,4壞7好,讓最多10個人抽,因此無法確定壞人確實人數。
◎好人挖到寶藏後,可以分享金礦牌,其金額由運氣決定。
◎壞人獲勝後,可以獲得固定高金額的報酬。
◎遊戲進行以金礦牌張數決定,10人遊戲大約進行3回合,即結束。
◎遊戲結束時,計算手中金礦金額以決定誰是大贏家。
這是個可10人遊戲的Party Game,規則簡單好上手,
但過程變化多端,也可以趁機耍耍心機喔!
因為前提為 34*c*lgn - n*(0.3*c-1) <= 0
且 34*c*lgn >= 0
=> - n*(0.3*c-1) <= 0
=> n*(0.3*c-1) >= 0
=> 0.3*c-1 >= 0
=> c >= 3.3~
...
PHP 自從 4.1.0 開始,支援一種比較安全的變數傳遞方式。原本我們在寫 PHP 程式時,從表單以 POST 方式傳入 PHP 程式時,PHP 可以直接拿來使用。例如,有一個表單是下面這個樣子:
<form action=test.php method=post>
<input type=text name=username>
<input type=button value=送出 name=b1>
</form>
當上述的 HTML 按了送出之後,在 test.php 這個程式就會有一個變數名為 $username,其值是我們所填入的名稱。
但是使用者也可以直接在網址列輸入 http://url/test.php?username=myname 來設定 $username 這個變數的值為 myname。
這會有什麼問題呢?讓我們以 PHP 4.1.0 release note 所提出的例子來說明。假設我們有一個程式如下:
<?php
if (authenticate_user()) {
$authenticated = true;
}
...
?>
使用者可以經由網址列輸入一個變數 $authenticated=true,這樣一來,不管是否通過 authenticate_user() 的檢查,$authenticated 永遠都是 true。
所以在 4.1.0 之後,有一個新的方式可以讓我們使用,就是將傳進來的變數全部都存在陣列中。以第一個例子而言,我們以 POST 的方式從表單傳來變數 $username,新的取得變數方式是:$_POST["username"],也就是說所有以 POST 傳遞過來的變數全部存在 $_POST 這個陣列中。詳細說明請參考 http://www.php.net/release_4_1_0.php 。
在 4.2.0 之前,新舊二種方式都可以使用,但是在 4.2.0 之後,Default 只能使用新的方式來傳遞變數。所以如果你安裝的了新 PHP 而發現無法使用舊的 PHP 程式,別驚訝。
如果您還是要以舊的方式來傳遞變數,請修改 php.ini (通常位於 /usr/local/lib/),將原本的 register_globals = Off 改成下列這個樣子,並移除開頭的註解符號 ";":
; register_globals = Off
register_globals = On
新的方式下,用來存放變數的陣列有下列七種:
* $_GET:存放以 GET 傳來的變數
* $_POST:存放以 POST 傳來的變數
* $_COOKIE :包含了存在 HTTP cookie 的變數
* $_SERVER:存放 server 變數 (如 REMOTE_ADDR)
* $_ENV:存放環境變數
* $_REQUEST:存放了 GET、POST、及Cookie 變數,也就是從使用者端傳來的變數。換句話說,這個變數的內容並不可靠。
* $_SESSION:包含了在 session 已註冊的變數。
* $_FILES:使用者上傳檔案(input type="file")
$_FILES['userfile']['name'] -- 檔案在客戶端電腦上的檔案名稱
$_FILES['userfile']['type'] -- 檔案的 MIME 類型,例如 "image/gif"
$_FILES['userfile']['size'] -- 上傳檔案的檔案大小,單為為 bytes
$_FILES['userfile']['tmp_name'] -- 上傳檔案儲存在伺服器端的暫存檔案名
$_FILES['userfile']['error'] -- 在 PHP 4.2.0 或更新的片本才有的這個陣列元素,上傳檔案的錯誤號碼
測試方法:
<?php
if(count($_POST)>0)
foreach($_POST as $k=>$v)
echo $k.'='.$v.'<br>';
?>
Note: 以下欄位資料皆為 little-endian! Little-Endian 的意思是:若某個欄位值為 0x1234,當你將BMP檔案用 UltraEdit 之類的純文字編輯器打開時,則你看到的值會是 0x3412,這是 Intel 制定的儲存方式,把值小的位元組(0x34)存在前面;詳情可參考 Big Endian 和 Little Endian 架構的說明
Shift | Name | Size (bytes) | Content | |
Bitmap File Header | 0000h | Identifier (ID) | 2 | 'BM'【註1】 |
0002h | File Size | 4 | 整個點陣圖檔案的大小(單位:byte) | |
0006h | Reserved | 4 | 保留欄位 | |
000Ah | Bitmap Data Offset | 4 | 點陣圖資料開始之前的偏移量(單位:byte) | |
Bitmap Info Header | 000Eh | Bitmap Header Size | 4 | Bitmap Info Header 的長度【註2】 |
0012h | Width | 4 | 點陣圖的寬度,以像素(pixel)為單位 | |
0016h | Height | 4 | 點陣圖的高度,以像素(pixel)為單位【註3】 | |
001Ah | Planes | 2 | 點陣圖的位元圖層數【註4】 | |
001Ch | Bits Per Pixel | 2 | 每個像素的位元數 1:單色點陣圖(使用 2 色調色盤) 4:4 位元點陣圖(使用 16 色調色盤) 8:8 位元點陣圖(使用 256 色調色盤) 16:16 位元高彩點陣圖(不一定使用調色盤) 24:24 位元全彩點陣圖(不使用調色盤) 32:32 位元全彩點陣圖(不一定使用調色盤) 【註5】 | |
001Eh | Compression | 4 | 壓縮方式【註6】: 0:未壓縮 1:RLE 8-bit/pixel 2:RLE 4-bit/pixel 3:Bitfields | |
0022h | Bitmap Data Size | 4 | 點陣圖資料的大小(單位:byte)【註7】。 | |
0026h | H-Resolution | 4 | 水平解析度(單位:像素/公尺)【註8】 | |
002Ah | V-Resolution | 4 | 垂直解析度(單位:像素/公尺) | |
002Eh | Used Colors | 4 | 點陣圖使用的調色盤顏色數【註9】 | |
0032h | Important Colors | 4 | 重要的顏色數【註10】 | |
Palette | 0036h | Palette | N*4 | 調色盤資料。 每個索引值指定一種顏色:0x00RRGGBB 其中最高位元組保留為零 |
Bitmap Array | - | Bitmap Data | - | 點陣圖資料【註11】 |
【註1】此欄原本有多種識別碼,用來識別點陣圖的類型:
'BM' - Windows 3.1x, 95, NT, ...
'BA' - OS/2 Bitmap Array
'CI' - OS/2 Color Icon
'CP' - OS/2 Color Pointer
'IC' - OS/2 Icon
'PT' - OS/2 Pointer
不過既然 OS/2 並不普及,目前皆在 Windows 上作業,因此 ID 全都是 'BM'。
【註2】此欄原本有多種數值,依作業系統種類而定:
28h - Windows 3.1x, 95, NT, ...
0Ch - OS/2 1.x
F0h - OS/2 2.x
以目前 Windows 常用的點陣圖來說,此欄位數值通常是 28h。
但因為微軟已經制定出了新的點陣圖格式,其中的 Bitmap Info Header 結構變化較大,長度加長,所以最好不要直接使用常數 28h,而是應該從實際檔案中讀取這個數值,才能確保程式相容性。
【註3】高度可能為負值,負值表示掃瞄方向由上而下。
但若高度是負值時,此點陣圖將不能被壓縮!(也就是說 Compression 欄位總是為 0)
【註5】16 及 32 位元點陣圖是否使用調色盤必須由 Compression 欄位的數值決定,
請參考 Bitfields 的解說。
【註6】點陣圖壓縮方式有以下四種:BI_RGB,BI_RLE8,BI_RLE4,以及BI_BITFIELDS。
壓縮資料 | 解壓縮之後的資料 |
03 01 | 01 01 01 |
05 02 | 02 02 02 02 02 |
00 03 00 01 02 00 | 00 01 02(最後的 00 是為了 word-aligned 才補上的) |
02 01 | 01 01 |
00 02 05 01 | 從目前位置右移 5 像素之後,向下移一列 |
02 03 | 03 03 |
00 00 | 此列結束 |
09 02 | 02 02 02 02 02 02 02 02 02 |
00 01 | 此點陣圖結束 |
上述資料的圖形如下:
壓縮資料 | 解壓縮之後的資料 |
03 11 | 1 1 1 |
05 02 | 0 2 0 2 0 |
00 05 01 23 10 00 | 0 1 2 3 1(最後的 0 00 是為了 word-aligned 才補上的) |
02 22 | 2 2 |
00 02 05 01 | 從目前位置右移 5 像素之後,向下移一列 |
02 13 | 1 3 |
00 00 | 此列結束 |
09 10 | 1 0 1 0 1 0 1 0 1 |
00 01 | 此點陣圖結束 |
上述資料的圖形如下:
【註7】若沒有壓縮(Compression 欄位為 0),則此欄數值可設為 0。
(我發現許多繪圖軟體根本不看此欄數值,隨便填寫也無所謂,圖檔仍可正常開啟)
【註8】若要換算為 dpi,則將此欄數值要除以39.37(吋/公尺)
例如,此欄數值若為 2834 (pixels per meter),
則 2834 ÷ 39.37 = 72 (pixels per inch) = 72 dpi
【註9】此欄表示圖檔實際使用的顏色數目,若數值為 0,表示使用所有調色盤顏色。
如果此欄數值並非「可用顏色的最大值」或者「零」,則需注意調色盤尺寸的計算。
例如,在 4 bpp bitmap 中,調色盤預設尺寸應是 16*4 bytes,
但若 Used Color 欄位數值並非 16 或 0,則調色盤尺寸應是 Used_Color_Number * 4 (bytes)。
【註10】當此欄的值等於「顏色數」或者為 0 時,表示所有顏色都一樣重要。
【註11】緊跟在調色盤之後的就是點陣圖資料陣列。
每一掃描列的長度取決於圖檔的寬度及顏色深度(Color Depth),
但是每一掃描列的長度必需是 4 byte 的倍數(DWORD-aligned)!
正常的點陣圖掃描列是由底向上儲存的:
陣列中的第一個 byte 表示全圖左下角的像素,而最後一個 byte 則表示全圖右上角的像素。
但如果是正向掃描(Height 欄位為負值),則掃描方向則是由上而下。
...
# Author : mashimaro
# Last Modify : 2008/01/27
$MAP = [
'0000000000000000E0',
'011111111111111111',
'000000000000F01000',
'00010000000010101H',
'000100000000001011',
'0I0100010000101000',
'000100010000001001',
'00010001000101001A',
'000000010001s0010e',
'000100010000111000',
'000100000000010000',
'00010100C000100000',
'000001000001000000',
'000001110010000000',
'000100000100010001',
'0111000010001D1G1B',
'00J101100101000100',
'000100000000000000'
];
$COST = [1, 2, 3, 7, 7, 8, 9, 9, 19, 97];
def calculate_path_len(arrDouble, x, y, val)
if($MAP[x][y].chr != '1' && arrDouble[x][y] > val)
arrDouble[x][y] = val;
#up
arrDouble = calculate_path_len(arrDouble, x - 1, y, val + 1) if(x > 0);
#down
arrDouble = calculate_path_len(arrDouble, x + 1, y, val + 1) if(x < 17);
#left
arrDouble = calculate_path_len(arrDouble, x, y - 1, val + 1) if(y > 0);
#right
arrDouble = calculate_path_len(arrDouble, x, y + 1, val + 1) if(y < 17);
end
#if($MAP[x][y])
#puts $MAP;
arrDouble;
end
pathArray = Array.new(11){Array.new(12)};
i = 0;
for s in ['s', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
j = 0;
$MAP.each { |str|
if(str.index(s))
#puts str + ' ' + str.index(s).to_s;
arrDouble = Array.new(18){Array.new(18, 99)};
arrDouble = calculate_path_len(arrDouble, j, str.index(s), 0);
#output arrDouble
if(1 == 0)
x = 0;
while(x < 18)
y = 0;
while(y < 18)
print arrDouble[x][y].to_s + ' ';
y = y + 1;
end
puts ;
x = x + 1;
end
end
#calculate pathArray
m = 0;
for tmp_s in ['s', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'e']
n = 0;
$MAP.each { |tmp_str|
if(tmp_str.index(tmp_s))
pathArray[i][m] = arrDouble[n][tmp_str.index(tmp_s)];
break;
end
n = n + 1;
}
m = m + 1;
end
break;
end
j = j + 1;
}
i = i + 1;
puts ;
puts ;
end
#output pathArray
if(1 == 1)
x = 0;
while(x < 11)
y = 0;
while(y < 12)
print pathArray[x][y].to_s + ' ';
y = y + 1;
end
puts ;
x = x + 1;
end
end
pick_cost = 1+2+5+7+20+15+9+17+35+89;
min_cost = 9999999;
indexArray = [1,2,3,4,5,6,7,8,9,10];
for i1 in indexArray
indexArray.delete(i1);
tmp_cost1 = pick_cost + pathArray[0][i1];
cost1 = 1 + $COST[i1 - 1];
for i2 in indexArray
indexArray.delete(i2);
tmp_cost2 = tmp_cost1 + pathArray[i1][i2] * cost1;
cost2 = cost1 + $COST[i2 - 1];
for i3 in indexArray
indexArray.delete(i3);
tmp_cost3 = tmp_cost2 + pathArray[i2][i3] * cost2;
cost3 = cost2 + $COST[i3 - 1];
for i4 in indexArray
indexArray.delete(i4);
tmp_cost4 = tmp_cost3 + pathArray[i3][i4] * cost3;
cost4 = cost3 + $COST[i4 - 1];
for i5 in indexArray
indexArray.delete(i5);
tmp_cost5 = tmp_cost4 + pathArray[i4][i5] * cost4;
cost5 = cost4 + $COST[i5 - 1];
for i6 in indexArray
indexArray.delete(i6);
tmp_cost6 = tmp_cost5 + pathArray[i5][i6] * cost5;
cost6 = cost5 + $COST[i6 - 1];
for i7 in indexArray
break if(min_cost <= tmp_cost6);
indexArray.delete(i7);
tmp_cost7 = tmp_cost6 + pathArray[i6][i7] * cost6;
cost7 = cost6 + $COST[i7 - 1];
for i8 in indexArray
break if(min_cost <= tmp_cost7);
indexArray.delete(i8);
tmp_cost8 = tmp_cost7 + pathArray[i7][i8] * cost7;
cost8 = cost7 + $COST[i8 - 1];
for i9 in indexArray
#puts 'start->'+i1.to_s+'->'+i2.to_s+'->'+i3.to_s+'->'+i4.to_s+'->'+i5.to_s+'->'+i6.to_s+'->'+i7.to_s+'->'+i8.to_s+'->'+i9.to_s+'->'+indexArray[0].to_s+'->end';
break if(min_cost <= tmp_cost8);
indexArray.delete(i9);
tmp_cost9 = tmp_cost8 + pathArray[i8][i9] * cost8;
cost9 = cost8 + $COST[i9 - 1];
tmp_cost10 = tmp_cost9 + pathArray[i9][indexArray[0]] * cost9;
cost10 = cost9 + $COST[indexArray[0] - 1];
tmp_cost = tmp_cost10 + pathArray[indexArray[0]][11] * cost10;
if(min_cost > tmp_cost)
min_cost = tmp_cost;
puts 'start->'+i1.to_s+'->'+i2.to_s+'->'+i3.to_s+'->'+i4.to_s+'->'+i5.to_s+'->'+i6.to_s+'->'+i7.to_s+'->'+i8.to_s+'->'+i9.to_s+'->'+indexArray[0].to_s+'->end';
puts min_cost;
end
indexArray.push(i9);
indexArray.sort!;
end
indexArray.push(i8);
indexArray.sort!;
end
indexArray.push(i7);
indexArray.sort!;
end
indexArray.push(i6);
indexArray.sort!;
end
indexArray.push(i5);
indexArray.sort!;
end
indexArray.push(i4);
indexArray.sort!;
end
indexArray.push(i3);
indexArray.sort!;
end
indexArray.push(i2);
indexArray.sort!;
end
indexArray.push(i1);
indexArray.sort!;
end
puts min_cost;
...
require 'wx'
require 'RMagick'
include Magick
include Wx
class MyFrame < Wx::Frame
def initialize(title)
super(nil, -1, title, Point.new(-1,1), Size.new(500,500))
evt_paint { on_paint }
img_file = File.join( File.dirname(__FILE__), 'tmp_new.bmp')
# first load the image into an Image object
image = Wx::Image.new(img_file)
# then create a Bitmap suitable for drawing
@bitmap = Wx::Bitmap.new(image)
end
def on_paint
paint do | dc |
dc.clear
dc.draw_bitmap(@bitmap, 0, 0, false)
end
end
end
class ImagesApp < Wx::App
def on_init
frame = MyFrame.new('Title')
frame.show
end
end
a = ImagesApp.new;
a.main_loop();
# Author : mashimaro
# Last Modify : 2008/01/02
def lcs(str1,str2)
if(str1.length == 0 || str2.length == 0)
''
else
if(str1[-1..-1] == str2[-1..-1])
lcs(str1[0..-2],str2[0..-2]) + str1[-1..-1]
else
a=lcs(str1[0..-2],str2)
b=lcs(str1,str2[0..-2])
if(a.length>=b.length)
a
else
b
end
end
end
end
str2='ATCACGAATTGGGCAATAATGCTACTTGAGACGTTTGAGCCCTCCGTCGGGCGCCTGTGGATGCCGGATTGGCATCCCGCAACAGAACGCTCTTAGTCCCCGCCTTCGGAGAATATGCCAAGTCGTAAGAGGCGGACGTGCATCACGCACGCGCCGTTAAGCAACAGATACCAGATGTCGTTTTGGTTAGTGGATTTAGCAGTATGCCTAACAGGACGCAAAACGGAGGGCTATCCGGCGAGGGTCAGCGGGACCCTATACGACCCTCGGAATGTCTTTGTTTACGCACTAAATGAAGTC'
str1='ATCGATACTTGGTGATACGTGCCTACGGCACTTCACGCTAGTCACGACTCCCTCTATGCCCCCACCGTATATATCCAGCCAGTCGTGATTAGAGTAATCAGTGGGCTGTACTGTGATGCATACCACTCCCTCACCACGCACCGAGGGCTTTGACGAGGATTTGATTCGCTATGAGAGTTGCGCCCTTTTGCCAAGATTACCACGCTTACTCACGGCCGGCCGACGATGAAATGCACGCGCGGGGGCTCAGCGAGCTGCAAACAGATGTACTATTAAGGCATGATTAAAGATGTAATATAA'
str1=gets
str1.sub!("\n",'')
str2=gets
str2.sub!("\n",'')
puts lcs(str1, str2)
...
# Author : mashimaro
# Last Modify : 2008/01/02
str2='ATCACGAATTGGGCAATAATGCTACTTGAGACGTTTGAGCCCTCCGTCGGGCGCCTGTGGATGCCGGATTGGCATCCCGCAACAGAACGCTCTTAGTCCCCGCCTTCGGAGAATATGCCAAGTCGTAAGAGGCGGACGTGCATCACGCACGCGCCGTTAAGCAACAGATACCAGATGTCGTTTTGGTTAGTGGATTTAGCAGTATGCCTAACAGGACGCAAAACGGAGGGCTATCCGGCGAGGGTCAGCGGGACCCTATACGACCCTCGGAATGTCTTTGTTTACGCACTAAATGAAGTC'
str1='ATCGATACTTGGTGATACGTGCCTACGGCACTTCACGCTAGTCACGACTCCCTCTATGCCCCCACCGTATATATCCAGCCAGTCGTGATTAGAGTAATCAGTGGGCTGTACTGTGATGCATACCACTCCCTCACCACGCACCGAGGGCTTTGACGAGGATTTGATTCGCTATGAGAGTTGCGCCCTTTTGCCAAGATTACCACGCTTACTCACGGCCGGCCGACGATGAAATGCACGCGCGGGGGCTCAGCGAGCTGCAAACAGATGTACTATTAAGGCATGATTAAAGATGTAATATAA'
#str1='AAC'
#str2='ACAA'
#str1='CATGGCATG'
#str2='ATCATTCAT'
str1=gets
str1.sub!("\n",'')
str2=gets
str2.sub!("\n",'')
#puts str1,str2;
arr = Array.new(str2.length){Array.new(str1.length, 0)};
#arr = Array.new(2,Array.new(3, 1));#不能用Orz
x = 0;
str2.split(//).each { |s2|
y = 0;
#puts "\n"+s2;
str1.split(//).each { |s1|
#print s1;
if(s1 == s2)
if(x > 0 && y > 0)
arr[x][y] = arr[x - 1][y - 1] + 1;
else
arr[x][y] = 1;
end
(x + 1).upto(str2.length-1) { |tmp_x|
break if(arr[x][y] <= arr[tmp_x][y]);
arr[tmp_x][y] = arr[x][y];
}
(y + 1).upto(str1.length-1) { |tmp_y|
break if(arr[x][y] <= arr[x][tmp_y]);
arr[x][tmp_y] = arr[x][y];
}
(y + 1).upto(str1.length-1) { |tmp_y|
break if(x + 1 >= str2.length || arr[x][y] <= arr[x + 1][tmp_y]);
(x + 1).upto(str2.length-1) { |tmp_x|
break if(arr[x][y] <= arr[tmp_x][tmp_y]);
arr[tmp_x][tmp_y] = arr[x][y];
}
}
end
y = y + 1;
}
x = x + 1;
}
print ' ';
str1.split(//).each { |c|
print ' ' + c;
}
puts '';
0.upto(str2.length-1) { |a|
print str2[a..a];
0.upto(str1.length-1) { |b|
print ' ' * (3 - arr[a][b].to_s.length) + arr[a][b].to_s;
}
puts '';
}
x = str2.length - 1;
y = str1.length - 1;
path = '';
puts 'arr[x][y] = ' + arr[x][y].to_s;
while(1)
while(y > 0 && arr[x][y-1] == arr[x][y])
y = y - 1;
end
while(x > 0 && arr[x-1][y] == arr[x][y])
x = x - 1;
end
path = str1[y..y] + path;
break if(arr[x][y] == 1);
x = x - 1;
y = y - 1;
end
puts path;
# Author : mashimaro...
# Last Modify : 2008/01/02
require 'net/http'
require 'net/https'
host = 'www.bright-shadows.net'
path = '/challenges/programming/calculate2/tryout.php'
cookie = 'PHPSESSID=************************************'
http = Net::HTTP.new(host, 80)
#http.use_ssl = true
headers = {
'Cookie' => cookie,
# 'Referer' => 'http://profil.wp.pl/login.html',
# 'Content-Type' => 'application/x-www-form-urlencoded'
}
resp, data = http.get(path, headers);
data.sub!('The equation is "', '');
data.sub!('"', '');
data.sub!('=[', '=+[');
puts data;
bases = [];
data.scan(/\][0-9]+/).each { |tmp_base|
bases.push(tmp_base[1..-1].to_i);
}
signs = ['+'];
data.scan(/[+-]\[/).each { |tmp_sign|
signs.push(tmp_sign[0..0]);
}
nums = [];
data.scan(/\[[0-9a-zA-Z]+\]/).each { |tmp_num|
nums.push(tmp_num[1..-2]);
}
#puts bases;
#puts signs;
#puts nums;
chrs = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
i = 1;
sum = 0;
while(i < bases.length)
num = 0;
nums[i].split(//).each { |c|
num = num * bases[i] + (chrs.index(c));
}
num = -num if(signs[i] == '-');
puts signs[i]+'['+nums[i]+']_'+bases[i].to_s+"\t"+num.to_s;
sum = sum + num;
i = i + 1;
end
tmp = sum;
(tmp = -tmp) if(tmp < 0);
result = '';
while(tmp > 0)
x = tmp % bases[0];
result = chrs[x..x] + result;
tmp = tmp / bases[0];
end
(result = '-' + result) if(sum < 0);
ret_path = '/challenges/programming/calculate2/solution.php?solution=' + result;
resp, data = http.get(ret_path, headers);
puts data;
...
# Author : mashimaro
# Last Modify : 2008/01/02
require 'digest/md5'
require 'net/http'
require 'net/https'
host = 'www.bright-shadows.net'
path = '/challenges/programming/peanojordan/tryout.php'
cookie = 'PHPSESSID=**********************************'
http = Net::HTTP.new(host, 80)
#http.use_ssl = true
headers = {
'Cookie' => cookie,
# 'Referer' => 'http://profil.wp.pl/login.html',
# 'Content-Type' => 'application/x-www-form-urlencoded'
}
while(true)
resp, data = http.get(path, headers);
data.sub!('<pre>', '');
data.sub!('</pre>', '');
lines = data.split('<br>');
exp = lines[0].sub('p(x) = ', '').gsub('/','.to_f/').gsub('^','**');
a, b = lines[2].scan(/[\-0-9]+/);
int_1 = a.to_i;
int_2 = b.to_i;
puts '';
puts lines[0];
puts '';
puts lines[2];
puts '';
puts exp;
#puts int_1, int_2;
puts '';
break if(exp[-1..-1].to_i < 6);
end
sum = 0;
int_1 = int_1 + 0.005;
while(int_1 < int_2)
sum = sum + eval(exp.gsub('x','('+int_1.to_s+')'));
puts sum;
int_1 = int_1 + 0.01;
end
puts (sum * 0.01).round;
digest = Digest::MD5.hexdigest((sum * 0.01).round.to_s);
ret_path = '/challenges/programming/peanojordan/solution.php?solution=' + digest;
resp, data = http.get(ret_path, headers);
puts data;
metaprogramming 或著叫做中介編程
簡單的說呢 就是寫一個程式讓他自己會去寫程式。
什麼意思呢? 請看下面的例子:
–
print "你要招換什麼生物?"
creature_class = gets
case gets
when "貓耳娘"
creature = 貓耳娘.new
when "長髮蘿莉"
creature = 長髮蘿莉.new
end
–
上面的程式碼可以達到我們的要求:使用者輸入什麼東西,就建立什麼物件的實體。
但是有沒有更乾淨的寫法呢?
–
print "你要招換什麼生物?"
creature_class = gets
eval( "creature = " + creature_class + ".new" )
–
看出來了嗎? eval這個函式接受了一個字串,並且叫ruby把這個字串當做一段程式碼來編譯。
也達到了metaprogramming的意義 動態的產生程式。
+-Square------+-Rows----------------+-Cols----------------+-Diagonals----+
| a b c d e | Row 1 = a+b+c+d+e | Col 1 = a+f+k+p+u | Diagonal 1 |
| f g h i j | Row 2 = f+g+h+i+j | Col 2 = b+g+l+q+v | = a+g+m+s+y |
| k l m n o | Row 3 = k+l+m+n+o | Col 3 = c+h+m+r+w | |
| p q r s t | Row 4 = p+q+r+s+t | Col 4 = d+i+n+s+x | Diagonal 2 |
| u v w x y | Row 5 = u+v+w+x+y | Col 5 = e+j+o+t+y | = u+q+m+i+e |
+-------------+---------------------+---------------------+--------------+
...
# Author : mashimaro
# Last Modify : 2008/01/01
require 'net/http'
require 'net/https'
host = 'www.bright-shadows.net'
path = '/challenges/programming/looping/tryout.php'
cookie = 'PHPSESSID=**********************************'
http = Net::HTTP.new(host, 80)
#http.use_ssl = true
headers = {
'Cookie' => cookie,
# 'Referer' => 'http://profil.wp.pl/login.html',
# 'Content-Type' => 'application/x-www-form-urlencoded'
}
resp, data = http.get(path, headers);
data.sub!('<pre>', '');
data.sub!('</pre>', '');
arr = [];
data.split('<br />').each { |line|
if(line[0..2]=='Sum')
arr.push(line[-2..-1]);
puts line[-2..-1];
end
}
puts '';
# puts arr[0];
# puts arr[1];
# puts arr[2];
# puts arr[3];
# puts arr[4];
# puts arr[5];
# puts arr[6];
# puts arr[7];
# puts arr[8];
# puts arr[9];
# puts arr[10];
# puts arr[11];
[1,2,3,4,5,6,7,8,9].each { |a|
[1,2,3,4,5,6,7,8,9].each { |b|
[1,2,3,4,5,6,7,8,9].each { |c|
[1,2,3,4,5,6,7,8,9].each { |d|
e = arr[0].to_i - a - b - c - d;
break if(e < 1);
next if(e > 9);
[1,2,3,4,5,6,7,8,9].each { |j|
[1,2,3,4,5,6,7,8,9].each { |o|
[1,2,3,4,5,6,7,8,9].each { |t|
y = arr[9].to_i - e - j - o - t;
break if(y < 1);
next if(y > 9);
[1,2,3,4,5,6,7,8,9].each { |x|
[1,2,3,4,5,6,7,8,9].each { |w|
[1,2,3,4,5,6,7,8,9].each { |v|
u = arr[4].to_i - v - w - x - y;
break if(u < 1);
next if(u > 9);
[1,2,3,4,5,6,7,8,9].each { |p|
[1,2,3,4,5,6,7,8,9].each { |k|
f = arr[5].to_i - a - k - p - u;
break if(f < 1);
next if(f > 9);
[1,2,3,4,5,6,7,8,9].each { |g|
[1,2,3,4,5,6,7,8,9].each { |h|
i = arr[1].to_i - f - g - h - j;
break if(i < 1);
next if(i > 9);
[1,2,3,4,5,6,7,8,9].each { |m|
q = arr[11].to_i - e - i - m - u;
break if(q < 1);
next if(q > 9);
r = arr[7].to_i - c - h - m - w;
break if(r < 1);
next if(r > 9);
s = arr[10].to_i - a - g - m - y;
break if(s < 1);
next if(s > 9);
next if(s != arr[3].to_i - p - q - r - t);
l = arr[6].to_i - b - g - q - v;
next if(l < 1 || l > 9);
n = arr[8].to_i - d - i - s - x;
next if(n < 1 || n > 9);
next if(n != arr[2].to_i - k - l - m - o);
arr2=[];
puts [].push(a,b,c,d,e).join(' ');
puts [].push(f,g,h,i,j).join(' ');
puts [].push(k,l,m,n,o).join(' ');
puts [].push(p,q,r,s,t).join(' ');
puts [].push(u,v,w,x,y).join(' ');
puts '';
ret_path = [].push('http://www.bright-shadows.net/challenges/programming/looping/solution.php?solution=',a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y).join('');
puts ret_path;
resp, data = http.get(ret_path, headers);
puts data;
exit(0);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}