fibonacci number & fibonacci sequence

https://www.mathsisfun.com/numbers/fibonacci-sequence.html

http://www.shuxuele.com/numbers/fibonacci-sequence.html

fibonacci sequence with cache


"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-05-17
* @modified
*
* @description fibonacci 算法缓存优化 javascript
* @augments
* @example
* @link https://en.wikipedia.org/wiki/Fibonacci_number
*
*/ /* for n = 0 and n = 1, Fn = F(n) F0 = 0
F1 = 1 for n > 1, Fn = F(n - 1) + F(n - 2); F2 = F1 + F0 = 1
F3 = F2 + F1 = 2
F4 = F3 + F2 = 3
F5 = F4 + F3 = 5
... The beginning of the fibonacci sequence is thus: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... */ const log = console.log; const fib = (n) => {
const caches = [0, 1];
if(n > 1 && typeof caches[n] === "undefined") {
const temp = fib(n - 2) + fib(n - 1);
caches[n] = temp;
}
// log(`caches[n]`, n, caches[n])
return caches[n];
} // const fib = (n) => {
// const caches = [0, 1];
// if(n === 0 || n === 1) {
// return caches[n];
// } else {
// if(typeof caches[n] === "undefined") {
// const temp = fib(n - 2) + fib(n - 1);
// caches[n] = temp;
// }
// // log(`caches[n]`, n, caches[n])
// return caches[n];
// }
// } // const fib = (n) => {
// const caches = [0, 1];
// if(n === 0 || n === 1) {
// return caches[n];
// } else {
// // log(`caches[n]`, n, caches[n])
// if(typeof caches[n] !== "undefined") {
// return caches[n];
// } else {
// const temp = fib(n- 2) + fib(n- 1);
// caches[n] = temp;
// return temp;
// }
// }
// } const v0 = fib(0)
log(`fib0`, v0) const v1 = fib(1)
log(`fib1`, v1) const v3 = fib(3)
log(`fib3`, v3) const v5 = fib(5)
log(`fib5`, v5)

Fibonacci memory 缓存优化


// USING MEMOIZATION
function fibonacci(n,memo) {
memo = memo || {}
if (memo[n]) {
return memo[n]
}
if (n <= 1) {
return 1
}
return memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo)
}

Fibonacci languages race rank sorter

https://9wlnh.csb.app/

hackster

https://www.hackster.io/users/preferences?show_welcome=true




xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


fibonacci number & fibonacci sequence的更多相关文章

  1. 求四百万以内Fibonacci(number)数列偶数结果的总和

    又对啦...开心~~~~ 只是代码可能不符合PEP标准什么的... Each new term in the Fibonacci sequence is generated by adding the ...

  2. 【LEETCODE】44、509. Fibonacci Number

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  3. Buge's Fibonacci Number Problem

    Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...

  4. [UCSD白板题] The Last Digit of a Large Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  5. [UCSD白板题 ]Small Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  6. (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)

    根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输 ...

  7. Fibonacci number

    https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...

  8. Algorithms - Fibonacci Number

    斐波那契数列(Fibonacci Number)从数学的角度是以递归的方法定义的: \(F_0 = 0\) \(F_1 = 1\) \(F_n = F_{n-1} + F_{n-2}\) (\(n \ ...

  9. 【leetcode】509. Fibonacci Number

    problem 509. Fibonacci Number solution1: 递归调用 class Solution { public: int fib(int N) { ) return N; ...

随机推荐

  1. 记录list.remove()和list.pop()

    list.remove(obj):这个是移除列表中某个值的第一个匹配项 list.pop(index):这个是移除列表中下标为index的元素 当元素全是数字或者有数字时注意区分.

  2. ELK (elasticsearch+kibana+logstash+elasticsearch-head) 华为云下载地址

    https://mirrors.huaweicloud.com/elasticsearch https://mirrors.huaweicloud.com/kibana https://mirrors ...

  3. jQuery 文本段落展开和折叠效果

    jQuery 文本段落展开和折叠效果 <!DOCTYPE html> <head> <meta http-equiv="Content-Type" c ...

  4. hook笔记①

    汇编中push 0x*** retn表示跳转到某个地址继续执行 取消hook时会在多线程环境中可能被检测 去掉函数框架可以规避寄存器cpu前后状态监测 #pragma comment(linker,& ...

  5. shell命令分隔符 二叉树结构的命令行树

    shell命令分隔符 二叉树结构的命令行树 I  ;&

  6. Crypto.getRandomValues()

    Crypto.getRandomValues() - Web APIs | MDN https://developer.mozilla.org/en-US/docs/Web/API/Crypto/ge ...

  7. Ubuntu16 安装 OpenSSH-Server

    Ubuntu16.04 桌面版默认是没有安装 SSH 服务的,需要手动安装服务: 更新源:sudo apt-get update 安装服务:sudo apt-get install -y openss ...

  8. IDEA、Pycharm学生免费使用(无教育邮箱)

    一.打开JetBrains学生产品网站 JetBrains Products for Learning:https://www.jetbrains.com/shop/eform/students 二. ...

  9. 阿里云MQ

    阿里云众多中间件服务中有一款非常强大的中间见服务,在企业互联网架构中起到不可替代的作用,相比较开源的RabbitMQ,阿里的消息队列MQ承受的住阿里内部1000+核心应用的使用,每天转几千条消息,稳定 ...

  10. 【xml】控件常用属性

    https://www.cnblogs.com/xqz0618/p/textview.html (常用,生动) https://www.jianshu.com/p/992324336dd9 (全,简洁 ...