# Exercise One

Write the function bind.

——————————

bind f' (gx,gs) = (fx, gs++fs)                  where                    (fx,fs) = f' gx

The meaning of bind here:

1. apply f' to the last result data gx, generating the new data fx; and

2. concat the last debug string, gs, to the string generating by f', fs.

— Me@2015.07.19 10:25 PM

# Problem 14.1a

A First Course in String Theory

14.1 Counting bosonic states

~~~ $n$ is the number of $a$‘s. $k$ is the number of different $a$‘s.

For $a^{i_1} a^{i_2}$, $n=2$.

(Indices $i_1$ and $i_2$ are not powers. Instead, they are just upper indices for representing different $a$‘s.)

When all $a$‘s commute, $a^1 a^2$ and $a^2 a^1$, for example, represent the same state. So we have to avoid double-counting, except for the same $a$‘s states, such as $a^3 a^3$.

By direct counting, without using the formula, the number of products of the form $a^{i_1} a^{i_2}$ can be built is $\frac{k(k-1)}{2} + k$ $= \frac{(k + 1)k}{2}$

Let $N(n, k) = {n + k - 1 \choose k - 1}$, the number of ways to put $n$ indistinguishable balls into $k$ boxes.

By using the formula, the number of products of the form $a^{i_1} a^{i_2}$ can be built is $N(2,k)$ $= \frac{(2+k-1)!}{2!(k-1)!}$ $= \frac{(k+1)k}{2}$

— Me@2015-07-26 08:43:22 AM

# River

You are not a stone flowing on the river.

Instead, a small region of the river is labelled as “you”.

You are a wave of the water.

— Me@2012.04.11

# Share

Publish! 7.2

We like to share because we like our information, ideas, and insights to have a future.

— Me@2011.08.07

# 避免犯錯 1.2

.

You probably will make those mistakes anyway.

You cannot choose whether to make those mistakes or not.

All you can choose is whether to make those mistakes before or during the exams.

— Me@2015.07.16

.

— Me@2018-02-14 09:51:15 PM

.

.

Generalize the bunny invasion example in the list monad chapter for an arbitrary number of generations.

— Wikibooks

——————————

import Control.Monad

 generation = replicate 3gen n = foldr (<=<) return (replicate n generation) --- 

["bunny"] >>= gen n

m >>= g ≡ join (fmap g m)xs >>= f = concat (map f xs) -- for the List Monad

---

f >=> g= (\x -> f x) >>= g= concat (map g (\x -> f x))
---
xs >>= f >=> gxs >>= (f >=> g)xs >>= ((\x -> f x) >>= g)(xs >>= f) >>= g

 

xs >>= (return >=> g >=> h)((xs >>= return) >>= g) >>= h
---
xs >>= return= concat (map f xs)= concat (map return xs)= concat (map return ["bunny"])= concat ([return "bunny"])= concat ([["bunny"]])= ["bunny"]
---
-- foldr f acc []     = acc-- foldr f acc (x:xs) = f x (foldr f acc xs)

 -- foldr (<=<) return (replicate n generation) 

foldr (<=<) return [h,g]= (<=<) h (foldr (<=<) return [g])= (<=<) h ((<=<) g (foldr return []))= (<=<) h ((<=<) g return)= h <=< g <=< return
---
compose :: [b -> [b]] -> b -> [b]compose = foldr (<=<) return

 

foldr (<=<) return (replicate n generation)= compose (replicate n generation)

— Me@2015-07-08 11:29:40 PM

# Problem 14.1 | Problem 12.11

A First Course in String Theory

14.1 Counting bosonic states

12.11 Counting symmetric products

~~~ $a^{I_1} a^{I_2} ... a^{I_n}$ $i = 1, 2, ..., n$ $I_i = 1, 2, ..., k$ $n$ is the number of $a$‘s. $k$ is the number of different $a$‘s.

For $k=6$ and $n=9$, one of the possible configurations is $a^1 a^2 a^2 a^4 a^4 a^4 a^5 a^6 a^6$

The problem is equivalent to that of assigning $n$ balls to $k$ boxes.

Box 1 collects the $a$‘s with index 1.

Box 2 collects the $a$‘s with index 2.

— Me@2015-07-13 03:34:32 PM

# Things You Should Never Do

It’s important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time. First of all, you probably don’t even have the same programming team that worked on version one, so you don’t actually have “more experience”. You’re just going to make most of the old mistakes again, and introduce some new problems that weren’t in the original version.

— Things You Should Never Do, Part I

— Joel Spolsky

2015.07.12 Sunday ACHK

# Passion Test

The Top Idea in Your Mind, 6 | 事業愛情觀 6

.

Am I willing to spend INFINITE time on it?

— Me@2015-07-05 04:26:24 PM

.

Do you want it to be one of your lifelong projects?

— Me@2015-07-12 11:00:11 AM

.

.

# 注定外傳 1.2

（問：但是，有沒有一個可能是，其實，將來所有事情的所有方面，都是注定的。所謂的「將來」，其實和「過去」一樣，都完全是固定的。

（問：為什麼你要講「類似」？

（問：不是呀。在量子力學中，即使有兩組百分百一樣的物理系統，即使它們獲得完全相同的輸入，都可能有不同的輸出。）

— Me@2015.05.26

# Euler problem 30

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

1634 = 1^4 + 6^4 + 3^4 + 4^48208 = 8^4 + 2^4 + 0^4 + 8^49474 = 9^4 + 4^4 + 7^4 + 4^4

As 1 = 1^4 is not a sum it is not included.

The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

——————————

sum_5th_powers n = sum $map ((^5) . digitToInt) (show n)  -- sum_5th_powers 999999 == 354294-- sum_5th_powers 9999999 == 413343  For a number having more than 6 digits, the fifth powers of its digits cannot be the number itself. So we should consider only numbers with less than 7 digits. -- sum_5th_powers ______ <= 354294 For the numbers not greater than 354294, the number whose sum_5th_powers can represent the largest number is … When 2 –> 1, in exchange for 4 –> 9, we earn — we get 354199; When 4 –> 3, in exchange for 1 –> 9, we earn — we get 353999; When 5 –> 4, in exchange for 3 –> 9, we earn — we get 349999; When 3 –> 2, in exchange for 4 –> 9, we earn — we get 299999. So the maximum number sum_5th_powers can represent is … -- sum_5th_powers 299999 == 295277  -- 295277-- 199999 -- sum_5th_powers 199999 == 295246  p30 = [n | n <- [10..m], n == sum_5th_powers n] where m = 295246 —————————— — Me@2015-07-06 08:42:07 PM 2015.07.07 Tuesday (c) All rights reserved by ACHK # Quick Calculation 14.8 A First Course in String Theory What sector(s) can be combined with a left-moving NS- to form a consistent closed string sector? ~~~ — This answer is my guess. — What is the meaning of “left-moving NS”? p.322 “Conventionally, the first input in $(\cdot, \cdot)$ is the left-moving sector and the second input is the right-moving sector.” What is the meaning of “+” in “NS+”? p.321 “… we truncate the NS sector to the set of states with $(-1)^F = +1$. The resulting states comprise the so-called NS+ sector.” “The NS+ sector contains the massless states and throw away the tachyonic states.” What is the meaning of “consistent” closed string sector? p.322 “… guarantees that the left and right sectors give identical contributions to the mass-squared:” $\alpha' M_L^2 = \alpha' M_R^2$ If NS+ is the left sector, the corresponding candidate right sectors are NS+, R+, R-. $M$ in NS-sector, Equation (14.37): $M_{NS}^2 = \frac{1}{\alpha'} \left( - \frac{1}{2} + N^\perp \right)$ $M$ in R-sector, Equation (14.53): $M_{Ramond}^2 = \frac{1}{\alpha'} \sum_{n \ge 1} \left( \alpha_{-n}^I \alpha_n^I + n d_{-n}^I d_n^1 \right) = \frac{1}{\alpha'} N^\perp$ Equation (14.78): $\frac{1}{2} \alpha' M^2 = \alpha' M_L^2 + \alpha' M_R^2$ NS+ equations of (14.38): $\alpha'M^2=0,~~N^\perp = \frac{1}{2}:~~~~b_{-1/2}^I |NS \rangle \otimes |p^+, \vec p_T \rangle$, $\alpha'M^2=1,~~N^\perp = \frac{3}{2}:~~~~\{ ... \} |NS \rangle \otimes |p^+, \vec p_T \rangle$, $...$ NS- equations of (14.38): $\alpha'M^2=-\frac{1}{2},~~N^\perp = 0:~~~~\{ ... \} |NS \rangle \otimes |p^+, \vec p_T \rangle$, $\alpha'M^2=\frac{1}{2},~~N^\perp = 1:~~~~\{ ... \} |NS \rangle \otimes |p^+, \vec p_T \rangle$, $...$ Mass levels of R+ and R- (Equations 14.54): $\alpha'M^2=0,~~N^\perp = 0:~~~~|R_a \rangle~~||~~|R_{\bar a} \rangle$ $\alpha'M^2=1,~~N^\perp = 1:~~~~...$ $...$ There are no mass levels in NS+, R+, or R- that can match those in NS-. So NS- can be paired only with NS-: (NS-, NS-) — This answer is my guess. — — Me@2015-07-05 11:09:32 PM 2015.07.05 Sunday (c) All rights reserved by ACHK # Single-world interpretation, 6.2.3 You are still in a superposition after the so-called “collapse”. The unchosen choice is still in the definition of “you”. — Me@2012-04-08 1:21:55 PM 2015.07.03 Friday (c) All rights reserved by ACHK # Intelligence and Wisdom A few days ago I finally figured out something I’ve wondered about for 25 years: the relationship between wisdom and intelligence. Anyone can see they’re not the same by the number of people who are smart, but not very wise. And yet intelligence and wisdom do seem related. How? What is wisdom? I’d say it’s knowing what to do in a lot of situations. I’m not trying to make a deep point here about the true nature of wisdom, just to figure out how we use the word. A wise person is someone who usually knows the right thing to do. If wisdom and intelligence are the average and peaks of the same curve, then they converge as the number of points on the curve decreases. If there’s just one point, they’re identical: the average and maximum are the same. But as the number of points increases, wisdom and intelligence diverge. And historically the number of points on the curve seems to have been increasing: our ability is tested in an ever wider range of situations. The wise are all much alike in their wisdom, but very smart people tend to be smart in distinctive ways. — Is It Worth Being Wise? — Paul Graham 2015.07.03 Friday ACHK # 技巧管理 這段改編自 2010 年 8 月 11 日的對話。 . 有時，你可能收集了，太多重要的讀書技巧，有吃不消的感覺。你可以這樣處理： 第一，你要意識到，讀書技巧夠用就可以。你並沒有必要，學懂或者執行，「所有」的讀書技巧。 第二，你試試每次，只針對一個問題，只執行一個讀書技巧，把它用到最盡為止。例如，我所講的「魔法筆記」技巧，並不只適用於數學科。你在其他科中，亦應大量使用。 到該個技巧自動運作時，你讀書上的下一個問題，自然會浮現出來。那時，你才考慮嘗試，下一個讀書技巧，針對該個新問題。 — Me@2015.06.29 . . 2015.07.02 Thursday (c) All rights reserved by ACHK # Euler problem 27.2 Haskell ——————————  problem_27 = -(2*a-1)*(a^2-a+41) where n = 1000 m = head$ filter (\x -> x^2 - x + 41 > n) [1..]          a = m - 1

This is the “official” Haskell solution to Euler problem 27.

This solution is incomprehensible. The following hints are as far as I can get.

Prerequisite considerations:

b must be a prime number, since x^2 + a*x + b must be a prime number when n=0.

 a = m - 1  is a choice of the prime number b (in x^2 + a*x + b) just(?) smaller than 1000.

a == 32

(\x -> x^2 – x + 41) 31 == 971

Why not the prime number 997?

— Me@2015.06.14 08:53 AM

It is because 997 is not a prime number generated by the formula x^2 - x + 41.

— Me@2015-06-30 11:07:53 AM

map (\x -> x^2 - x + 41) [0..40]

is for generating 41 primes with the greatest Euler’s lucky number 41.

— Me@2015.06.14 08:34 AM