피보나치 수열을 사용하는 프로그래머 유형

24151 단어 pythongofunctional

Warning: Not recommended for fainted ❤️ Enjoy 🤘


  • Functional prodigy
  • Meta functional expert
  • One liner wizard
  • The Librarian
  • Classy theorist
  • Closure fanatic
  • Lazy idealist
  • OO based lazy conservative
  • Generator magician
  • Iterator maniac
  • Rob Pike

  • 기능적 신동




    def fib(n):
        if n <= 1:
            return n
        return fib(n-1) + fib(n-2)
    

    메타 기능 전문가



    def fib(a, b, nth=0, current=0):
        if nth == current:
            return a
        return fib(b, a + b, nth, current+1)
    
    def main():
        series = [fib(0,1,n) for n in range(50)]
        print(series)
    

    원 라이너 마법사



    f = lambda n: n if n <= 1 else f(n-1) + f(n-2)  # f and not fib because functional laws
    

    사서



    pip install fibonacci
    



    from fibonacci import fibo
    
    series = [fibo(n) for n in range(10)]
    print(series) 
    
    

    고급 이론가



    class Fibonacci:
    
        def __init__(self, nth):
            self.nth = nth
            self.a = 0
            self.b = 1
            self.current = 0
    
        def get(self):
            while True:
                if self.current == self.nth:
                        return self.a
                  self.a, self.b = self.b, self.a + self.b
                  self.current += 1
    
    def main():
        f = Fibonacci(100)
        # God bless getters
        print(f.get())
    

    폐쇄 광신자



    from functools import wraps
    
    def closo_fibo_stream():
        # precious closures
        a, b = 0, 1
        @wraps
        def wrapper(*args, **kwargs):
            nonlocal a, b
            current = a
            a, b = b, a + b
            return current
        return wrapper
    
    def main():
        streamer = closo_fibo_stream()
        series = [streamer() for i in range(10)]
        print(series)
    

    게으른 이상주의자



    def lazy_fibo():
        a, b = 0, 1
        while True:
            yield a
            a, b = b, a + b
    
    def main():
        from itertools import islice
        for n in islice(lazy_fibo(), 100):
            print(n) # i feel good
    
    

    OO 기반 게으른 보수



    # refactored into class coz why not??
    class LazyFibo:
        def __init__(self):
            self.a = 0
            self.b = 1
    
        def __iter__(self):
            while True:
                yield self.a
                self.a , self.b = self.b, self.b + self.a
    
    def main():
        from itertools import islice
        for n in islice(LazyFibo(),10):
            print(n)
    

    발전기 마술사



    def fib_magico(a, b):
        yield a
        yield from fib_magico(b, a + b)
    
    def main():
        from itertools import islice
        for n in islice(fib_magico(0, 1), 10):
                print(n)
    

    반복자 미치광이



    class fib_iter:
    
        def __init__(self, n):
            self.n = n
            self.current = 0
            self.a = 0
            self.b = 1
    
        def __next__(self):
            if self.current > self.n:
                raise StopIteration("don't care anymore")
            current = self.a
            self.a, self.b = self.b, self.a + self.b
            self.current += 1
            return current
    
    class fib:
    
        def __init__(self, n):
            self.n = n
    
        def __iter__(self):
            return fib_iter(self.n)
    
    def main():
        for i in fib(10):
            print(i)
    

    롭 파이크



    def fib(n):
        res = []
        a, b = 0, 1
        for i in range(n):
            res.append(a)
            a, b = b, a + b
        return res
    

    감사!! 아래 레포를 확인하세요




    로부스골리 / n-way-to-fibonacci 시리즈


    하지만 왜?








    피보나치 수열의 11가지 방법



    지루하고 소프트웨어가 고장 났기 때문입니다. 날 믿지마


    Warning: Not recommended for fainted ❤️ Enjoy 🤘


    전문가에 의해


  • Functional prodigy
  • Meta functional expert
  • One liner wizard
  • The Librarian
  • Classy theorist
  • Closure fanatic
  • Lazy idealist
  • OO based lazy conservative
  • Generator magician
  • Iterator maniac
  • Abandoned

  • 기능적 신동


    def fib(n)
        if n <= 1:
            return n
        return fib(n-1) + fib(n-2)

    메타 기능 전문가


    def fib(a, b, nth=0, current=0):
        if nth == current:
            return a
        return fib(b, a + b, nth, current+1)
    
    def main():
        series = [fib(0,1,n) for n in range(50)]
        print(series)

    원 라이너 마법사


    f = lambda n



    View on GitHub

    좋은 웹페이지 즐겨찾기