defis_square(num: int) -> bool: return math.isqrt(num) ** 2 == num
deffind_x(D: int) -> int: """ 求出给定D时,满足题目所给的丢番图方程的最小的x。 """ assertnot is_square(D) y = 1 whileTrue: candidate = D * y * y + 1 if is_square(candidate): return math.isqrt(candidate) y += 1
defsolve_66(limit): """ 找出不大于limi的D中,使find_x的返回值最大的那一个数字。 """ max_D = None max_x = None D = 2 while D <= limit: if is_square(D): D += 1 continue x = find_x(D) if max_x isNoneor x > max_x: max_D = D max_x = x D += 1 return max_D, max_x
if __name__ == '__main__': D, x = solve_66(7) print('D is {} and x is {}'.format(D, x))
(formatt"~(hello world~)~%") ; 打印hello world (formatt"~:(hello world~)~%") ; 打印Hello World (formatt"~@(hello world~)~%") ; 打印Hello world (formatt"~:@(hello world~)~%") ; 打印HELLO WORLD
(multiple-value-bind (sec min hour date mon year) (decode-universal-time (get-universal-time)) (declare (ignorable sec)) (formatt"~4D-~2,'0D-~2,'0D ~2,'0D:~2,'0D~%" year mon date hour min))
VS Code扩展的核心逻辑定义在文件src/extension.ts中。在yo生成的示例代码中,用registerCommand注册了一个名为helloworld.helloWorld的命令,其逻辑是简单地在右下角弹出一句Hello VS Code from HelloWorld!。这个回调函数,便是业务逻辑的落脚点。
This is a tool for powerful automation of OS X. At its core, Hammerspoon is just a bridge between the operating system and a Lua scripting engine. What gives Hammerspoon its power is a set of extensions that expose specific pieces of system functionality, to the user.
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() local windows = hs.window.allWindows() -- 在Lua中遍历表的方法:https://www.jianshu.com/p/de5a4b132918 for _, win inpairs(windows) do end end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() local windows = hs.window.allWindows() -- 在Lua中遍历表的方法:https://www.jianshu.com/p/de5a4b132918 for _, win inpairs(windows) do local app = win:application() end end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() local windows = hs.window.allWindows() -- 在Lua中遍历表的方法:https://www.jianshu.com/p/de5a4b132918 for _, win inpairs(windows) do local app = win:application() local bundleID = app:bundleID() end end)
现在,只要变量bundleID等于Emacs的bundle ID就可以聚焦到当前遍历的窗口上了
1 2 3 4 5 6 7 8 9 10 11
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() local windows = hs.window.allWindows() -- 在Lua中遍历表的方法:https://www.jianshu.com/p/de5a4b132918 for _, win inpairs(windows) do local app = win:application() local bundleID = app:bundleID() if bundleID == "org.gnu.Emacs"then win:focus() end end end)