[Kata] Clojure - Day 27

Recursion 101

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].

Solution

(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

What is the reason behind Pacbell email login issue?

There could be a number of reasons behind the Pacb...

【从零开始的Swift开发心路历程-Day28】认识GCD多执行绪Part1

GCD(Grand Central Dispatch)是由苹果开发用来操作Thread的API 而在...

Day 24 Password Attacks - 密码生成器 (Wordlists, CeWL, Crunch)

前言 为了破解密码,我们必须尝试很多可能才能找到正确的密码。当攻击者使用数千或数百万个单字或组合来破...

用资料结构看 evernote - 修改後 - DAY 11

修改的想法 整个结构应该会偏向某个知识领域,不太适合用於专案类型,但概念可以斟酌参考。 原先在记事本...

Day30 .NET 6 <ErrorBoundary>

昨天说到单元测试,但有些时候可能由於时程关系没办法完整测试,就可能因为某个 Component 出错...