2022/10/15

定期寫部落格

其實真的是有點懶,也不知道要寫什麼?

但是呢,不寫點紀錄好像日子就白白的過了。

想寫點想法,又覺得很赤裸,為何要讓自己的想法給別人看到?

其實根本沒人想看?


放一下引起我想要寫一篇可能毫無內容的部落格的源頭:

https://tdd.best/blog/why-engineers-should-keep-blogging/

引用 91 的引用

When people ask me for advice on blogging, I always respond with yet another form of the same advice: pick a schedule you can live with, and stick to it. Until you do that, none of the other advice I could give you will matter. I don’t care if you suck at writing. I don’t care if nobody reads your blog. I don’t care if you have nothing interesting to say. If you can demonstrate a willingness to write, and a desire to keep continually improving your writing, you will eventually be successful.

先排時間,在做事情

這跟我的價值觀蠻相符的,如果是一件會重複做好幾次的事情,那先做比做好重要。而大部分的事情都不會一次就結束。尤其是你是第一次做這件事的時候。


好吧,今天就先這樣吧,還是有擠出一些想法,感恩。

2021/6/20

WPF ViewModel PropertyChanged

紀錄一個好用的套件:PropertyChanged.Fody

裝了之後呢,在你的 ViewModel 上面加上 [AddINotifyPropertyChangedInterface] 就可以自動產生 NotifyPropertyChanged 的事件囉!



2021/1/29

Union-Find 併查集

更新紀錄:

2022.03.01 更新網路資料 2 的連結

網路資料:

  1. Link 中文維基百科
  2. Link Robert Sedgewick 教授的 Algorithm 4th 配套投影片

觀念紀錄:

Union-Find 是一種 data structure 也可以是一種類型的問題。

問題的主要描述是:
  • Find(x, y): 回傳 x, y 是否屬於同一個 set
  • Union(x, y): 合併 x, y 所屬的 set
之所以會說是一種 data structure 是因為,實務上高效率解決這類問題的作法是一種特定的資料結構。


Python 程式碼:
class UnionFind:
    def __init__(self, n):
        self.id = [i for i in range(n)]
        self.sz = [1 for _ in range(n)]
        
    def root(self, i):
        while i != self.id[i]:
            self.id[i] = self.id[self.id[i]]
            i = self.id[i];
        return i
    
    def find(self, p, q):
        return self.root(p) == self.root(q)
    
    def unite(self, p, q):
        i = self.root(p)
        j = self.root(q)
        if self.sz[i] <= self.sz[j]:
            self.id[i] = j
            self.sz[j] += self.sz[i]
        else:
            self.id[j] = i
            self.sz[i] += self.sz[j]

2021/1/28

python defaultdict 的用法

主要目標:

紀錄 defaultdict 的概念跟常見用法。

說明:

帶有預設值的 dictionary ,第一個參數是一個可呼叫的物件,後面接的參數會直接給 dict 當參數使用。

例如:
defaultdict(int, {'a': 10, 'b': 20})
等同於會呼叫的意思:
dict({'a': 10, 'b': 20})

整理最常用的方法: 

1. 要計算所有的東西有多少個: 
d = defaultdict(int) 
d[x] += 1 

2. 要把同一個 key 的東西串在一起: 
d = defaultdict(list) 
d[x].append(y) 

3. 要使用指定的預設值: 
d = defaultdict(lambda :False)

參考資料:


2020/8/9

Python 如何產生指定 bit 數量的 mask

程式碼:
def n_mask(n):
    return 2**n-1
使用:
bin(n_mask(45))
輸出:
'0b111111111111111111111111111111111111111111111'