## YAML 的問題 (挪威問題)

Hacker News 首頁上看到的，YAML 寫多的人都遇過類似的問題：「The Norway Problem - why StrictYAML refuses to do implicit typing and so should you」，對應的討論「The Norway Problem (hitchdev.com)」也可以看一下。

```countries:
- GB
- IE
- FR
- DE
- NO```
```>>> from pyyaml import load
>>> load(the_configuration)
{'countries': ['GB', 'IE', 'FR', 'DE', False]}```

```python: 3.5.3
postgres: 9.3```

```first name: Christopher
surname: Null```

## 找數列的平均值

2016 年的文章，不過算是經典的題目，所以最近又冒出來了。要怎麼找數列的平均值：「Calculating the mean of a list of numbers」。

You have a list of floating point numbers. No nasty tricks - these aren’t NaN or Infinity, just normal “simple” floating point numbers.

Now: Calculate the mean (average). Can you do it?

• 第一個要處理的就是設計演算法時各種會 overflow 的情況。
• 降低誤差。
• 合理的計算量。

It also demonstrates a problem: Floating point mathematics is very hard, and this makes it somewhat unsuitable for testing with Hypothesis.

```#include <math.h>
#include <stdio.h>

int main(void)
{
int i;
float a;

for (i = 0; i < 32; i++) {
a = pow(2, i);
printf("2^%d     = %f\n", i, a);

a += 1;
printf("2^%d + 1 = %f\n", i, a);
}
}```

```2^23     = 8388608.000000
2^23 + 1 = 8388609.000000
2^24     = 16777216.000000
2^24 + 1 = 16777216.000000```

## 資料庫裡的浮點數：MySQL 5.1 到 MySQL 5.5 的差異...

Mozilla 最近在升級 MySQL 採「先建後拆」的步驟，發現用 pt-table-checksum 檢查時不一致：「MySQL 5.1 vs. MySQL 5.5: Floats, Doubles, and Scientific Notation」。

```mysql> select float_field from db.tbl where id=218964;
+-------------+
| float_field |
+-------------+
| 9.58084e-05 |
+-------------+
1 row in set (0.04 sec)```

```MariaDB [(none)]> select float_field from db.tbl where id=218964;
+--------------+
| float_field |
+--------------+
| 0.0000958084 |
+--------------+
1 row in set (0.24 sec)```