This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Emacs key bindings for Outlook/Word | |
print("Resume Emacs bindings over outlook/word") | |
function isKeyStroke(event, modifiers, chars) | |
return event:getFlags():containExactly(modifiers) and event:getCharacters(true) == chars | |
end | |
function targetApp() | |
local app = hs.application.frontmostApplication() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# purchase.py | |
# Copyright (C) 2019 Liu Xinyu (liuxinyu95@gmail.com) | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 有读者在《算法新解》群问,为什么下述程序的slow函数很慢? | |
* 主要原因是slow方法采用了性能不佳的双重循环搜索,它对n个元素数组中的每个元素,都逐一在含有m个元素数组中查找,复杂度是O(n*m) | |
* 次要原因是每次循环中都重复的做split操作,split实际使用了正则表达式匹配,是个比较昂贵的运算。 | |
* | |
* 为此,最主要改进是,把含有m个元素的数组,转换成效率较高的字典,例如Hash set或者Tree set。 | |
* 用Hash set的空间较大,但是每次查找时间较快,为O(1),故而总体性能为O(n)。变为线性时间的算法; | |
* 用Tree set会节省空间,但是每次查找的时间为O(lg m),故而总体性能为O(n * lg m),仍然能大大提高性能 | |
* 下面的例子fast()函数中,我们也可以使用函数式风格的collect或者reduce,为了照顾不熟悉的读者,我们使用了传统的风格。 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Given an integral number in [0, 999 billion), print the English phrase for this number. */ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class NumToEnglish { | |
static final String names[] = {"zero", "one", "two", "three", "four", "five", | |
"six", "seven", "eight", "nine", "ten", "eleven", | |
"twelve", "thirteen", "fourteen", "fifteen", "sixteen", | |
"seventeen", "eighteen", "nineteen"}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* problem 1, A generic Fibonacci number lookup program.*/ | |
/* | |
imperative solution. | |
fibo n | |
F: static array of n, with F[0] = F[1] = 1 | |
i = 2 | |
while i < n and F[i] != NIL do | |
++i | |
for i to n-1 | |
F[i] = F[i-1] + F[i-2] |