- 注册
- 2002-10-12
- 消息
- 47,114
- 荣誉分数
- 2,376
- 声望点数
- 393
我有个问题,嘿嘿,就是这个
Step 1: Generate a file of 10,000 fibonacci numbers, each number on a line
The start should look like:
0
1
1
2
3
5
8
13
21
etc
Step 2: You need to calculate the signed int crc32 values of each line.
The start should look like:
-186917087
-2082672713
-2082672713
450215437
1842515611
etc
Step 3: Then multiply any negative line by -1.
Step 4: Find the largest value and remember it
Step 5: Then add all the resulting values (including the largest one), e.g. result 1 + result 2 + etc...
Step 6: Then multiply that with the largest value from step 4
我写的code得到的结果居然不是正确的
不知道逻辑那里出错误了
哪位有空帮忙看看,多谢了
Step 1: Generate a file of 10,000 fibonacci numbers, each number on a line
The start should look like:
0
1
1
2
3
5
8
13
21
etc
Step 2: You need to calculate the signed int crc32 values of each line.
The start should look like:
-186917087
-2082672713
-2082672713
450215437
1842515611
etc
Step 3: Then multiply any negative line by -1.
Step 4: Find the largest value and remember it
Step 5: Then add all the resulting values (including the largest one), e.g. result 1 + result 2 + etc...
Step 6: Then multiply that with the largest value from step 4
我写的code得到的结果居然不是正确的
不知道逻辑那里出错误了
哪位有空帮忙看看,多谢了
代码:
<?
$vala = 0; //第一个fibonacci numbers
$valb = 1; //第二个fibonacci numbers
$max = 0; //最大值
$total = 0;//$vala + $valb; //sum of all
$val = array(); //保存所有fibonacci numbers
$crc = array(); //保存所有crc32 values
array_push($val, $vala); //push 0 into array
array_push($val, $valb); //push 1 into array
//Step 1 : fibonacci numbers
for ($i = 0; $i<5000;$i++){
$vala = $vala + $valb; //calculate fibonacci numbers
$valb = $vala + $valb; //calculate fibonacci numbers
array_push($val, $vala); //push $vala into array
array_push($val, $valb); //push $valb into array
$total = $vala + $valb + $total; //calculate total
}
//Step 2 : CRC Value
foreach ($val as $rawline) {
$CRC_Val = crc32($rawline); //calculate CRC32 Value
array_push($crc, $CRC_Val); //push $CRC_Val into array
$total = $CRC_Val + $total; //calculate total
}
foreach ($crc as $rawline) {
//Step 3: Then multiply any negative line by -1.
if ( $rawline < 0 ){ //如果小于0
$rawline = $rawline * -1; //multiply by -1
}
//Step 4: Find the largest value and remember it
if ( $rawline > $max ){ //如果大于最大值
$max = $rawline; //reintialize it to rawline
}
$total = $rawline + $total; //calculate total
}
//Step 5: Then add all the resulting values (including the largest one)
$total = $total + $max;
//Step 6: Then multiply that with the largest value from step 4
$total = $total * $max;
print $total;
?>