Codewar-006: A disguised sequence (I)
2019独角兽企业重金招聘Python工程师标准>>>
来源:
https://www.codewars.com/kata/563f0c54a22b9345bf000053/train/java
参考:
http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#BigInteger(java.lang.String,%20int)
Given u0 = 1, u1 = 2
and the relation 6unun+1-5unun+2+un+1un+2 = 0
calculate un for any integer n >= 0
.
Examples
fct(n) returns un
: fct(17) -> 131072, fct(21) -> 2097152
Remark: You can take two points of view to do this kata:
the first one purely algorithmic from the definition of
un
the second one - not at all mandatory, but as a complement - is to get a bit your head around and find which sequence is hidden behind
un
.
package codewars;
import java.math.BigInteger;class HiddenSeq {public static BigInteger fcn(int n) {return new BigInteger("2").pow(n);}
}
package codewars;
import static org.junit.Assert.*;
import org.junit.Test;
import java.math.BigInteger;public class HiddenSeqTest {private static void testing(BigInteger actual, BigInteger expected) {assertEquals(expected, actual);}@Testpublic void test1() {System.out.println("Fixed Tests: fcn"); testing(HiddenSeq.fcn(17), BigInteger.valueOf(131072));testing(HiddenSeq.fcn(21), BigInteger.valueOf(2097152));testing(HiddenSeq.fcn(14), BigInteger.valueOf(16384));testing(HiddenSeq.fcn(43), BigInteger.valueOf(8796093022208L));testing(HiddenSeq.fcn(19), BigInteger.valueOf(524288));}}
转载于:https://my.oschina.net/u/553266/blog/800448
Codewar-006: A disguised sequence (I)相关推荐
- Go语言实现A disguised sequence (I)
描述 Given u0 = 1, u1 = 2 and the relation 6unun+1-5unun+2+un+1un+2 = 0 calculate un for any integer n ...
- WebRTC 音频发送和接收处理过程
曾经整理过一个 WebRTC 音频发送和接收处理的关键过程,WebRTC Audio 接收和发送的关键过程 ,不过之前的分析是基于比较老的版本做的.分析所基于的应用程序,依然选择 WebRTC 的示例 ...
- docker 容器 exited_Docker实战006:docker容器使用详解
Docker容器也是docker的核心成员,是docker镜像的一个运行实例.一个镜像可以创建多个容器,多个容器也可以在同一台机器上运行并与其他容器共享操作系统内核同时将应用程序与系统其它周围环境隔离 ...
- 教你识别一些sequence的相关问题
本文分享自华为云社区<GaussDB(DWS)运维 -- sequence常见运维操作>,作者: 譡里个檔. GaussDB(DWS)是一个share nothing架构的产品,seqeu ...
- TMT: A Transformer-based Modal Translator for Improving Multimodal Sequence Representations in Audio
TMT: A Transformer-based Modal Translator for Improving Multimodal Sequence Representations in Audio ...
- 使用python解决codewar中问题,个人答题思路及代码总结(1)
Codewar 7kyu Two to One Take 2 strings s1 and s2 including only letters from a to z. Return a new so ...
- Bi-LSTM-CRF for Sequence Labeling
做了一段时间的Sequence Labeling的工作,发现在NER任务上面,很多论文都采用LSTM-CRFs的结构.CRF在最后一层应用进来可以考虑到概率最大的最优label路径,可以提高指标. 一 ...
- Oracle 12C -- 基于sequence的列的默认值
12C支持先创建一个sequence,然后再将该sequence指定为某个列的值的默认表达式. 和"identity column"具有以下不同点: ·对列的个数没有限制 ·seq ...
- DP UVALive 6506 Padovan Sequence
题目传送门 /*题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大DP:状态转移方程:dp[i][j] = max (dp[i][j], dp[1-i][j-1] + a[ ...
最新文章
- Devexpress的Datalayout控件
- Spring中Bean的概念
- java客户端api文档_Java 11:新的HTTP客户端API
- 怎么添加本地音乐_编辑视频如何添加本地音乐?原来方法这么简单,用手机就能制作...
- Andorid AlertDialog 点击后自动消失_Andorid-APP 安全(五)之android取证-文件系统与数据结构...
- javascript classList add报错
- 第四套人民币及8001的简介
- 图解数据结构(04) -- 哈希表
- 绘画技巧:怎样才能画好拟人化兽人?
- Failed to initialize NVML 长效解决方法
- java:文本框的简单使用
- opencv 涂抹区域得方法
- DBcontext应用于已存在数据库
- Delphi的编程语言Object Pascal(3)
- (图)Eee PC 904 HD闪亮登场!
- 2,uniapp功能之—扫码(条形码,二维码)点击扫码或者pda侧边按钮扫码
- k8s集群环境namespace共享和隔离
- 二阶龙格库塔公式推导_二阶龙格—库塔公式.PPT
- 宝元系统u盘使用说明_宝元系统简易操作指南
- linux ls和 ll 命令