In this Kata, you will be given two positive integers a and b and your task will be to apply the following operations:
当 a = 0 || b = 0
时回传 [a, b]
,否则重复 step 2 & 3 计算
i) If a = 0 or b = 0, return [a,b]. Otherwise, go to step (ii);
ii) If a ≥ 2*b, set a = a - 2*b, and repeat step (i). Otherwise, go to step (iii);
iii) If b ≥ 2*a, set b = b - 2*a, and repeat step (i). Otherwise, return [a,b].
(ns kata.core)
(defn solve [a b]
(cond
(or (zero? a) (zero? b)) (list a b)
(>= a (* 2 b)) (solve (- a (* 2 b)) b)
(>= b (* 2 a)) (solve a (- b (* 2 a)))
:else (list a b)))
<<: [Day 27] LeetCode - 7 Reverse Integer
>>: DAY27 - 使用 Istio 的 Kiali 可视化後端的 Service Mesh
There could be a number of reasons behind the Pacb...
GCD(Grand Central Dispatch)是由苹果开发用来操作Thread的API 而在...
前言 为了破解密码,我们必须尝试很多可能才能找到正确的密码。当攻击者使用数千或数百万个单字或组合来破...
修改的想法 整个结构应该会偏向某个知识领域,不太适合用於专案类型,但概念可以斟酌参考。 原先在记事本...
昨天说到单元测试,但有些时候可能由於时程关系没办法完整测试,就可能因为某个 Component 出错...