当前位置:网站首页>Golang monkeys eat peaches and ask for the number of peaches on the first day
Golang monkeys eat peaches and ask for the number of peaches on the first day
2022-06-28 01:05:00 【Cloud sunwenbo】
/*
The problem of monkeys eating peaches , There is a pile of peaches , The monkey ate half of it on the first day , And one more ! Later, every day monkeys eat half of them , And then one more .
By the tenth day , Want to eat again , Found only one peach . ask : How many peaches were there at first
Thought analysis :
1. The first 10 There is only one peach in the sky
2. On the ninth day, there were some peaches = ( The number of peaches on the tenth day + 1) * 2
3. law : The first n Number of peaches per day peach(n) = (peach(n + 1) + 1) * 2
*/
func peach(n int) int {
if n > 10 || n < 1 {
fmt.Println(" The number of days entered is incorrect ")
return 0 // return 0 Express Input error
}
if n == 10 {
return 1
} else {
return (peach(n + 1 ) + 1) * 2
}
}
func main() {
fmt.Println(" The number of peaches in the monkey on the first day was ",peach(1))
}边栏推荐
- Mongodb- install a mongodb database locally on the windows computer
- Informatics Olympiad all in one 1359: enclosed area
- What are the requirements for customizing the slip ring for UAV
- plot_ Model error: pydot and graphviz are not installed
- GFS 分布式文件系统概述与部署
- Leetcode 720. 词典中最长的单词(为啥感觉这道题很难?)
- Redis主从复制、哨兵模式、集群的概述与搭建
- Squid proxy server (Web cache layer for cache acceleration)
- 1696D. Permutation graph thinking
- Alchemy (6): iteratable models and use cases
猜你喜欢

MATLB|改进的前推回代法求解低压配电网潮流
![[untitled]](/img/e4/7c65c6823559b8501a1777cc4eb7ba.jpg)
[untitled]

Redis主从复制、哨兵模式、集群的概述与搭建

Taro--- day1--- construction project

logging日志的使用

Proe/creo product structure design - continuous research

Arduino uno realizes simple touch switch through direct detection of capacitance

Alchemy (1): identify prototype, demo and MVP in project development

剑指 Offer 65. 不用加减乘除做加法

electron窗口背景透明无边框(可用于启动页面)
随机推荐
Taro--- day2--- compile and run
【无标题】
SPuG - lightweight automatic operation and maintenance platform
Overview and construction of redis master-slave replication, sentinel mode and cluster
Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
Summary of wuenda's machine learning course (11)_ Support vector machine
每次启动项目的服务,电脑竟然乖乖的帮我打开了浏览器,100行源码揭秘!
Ten MySQL locks, one article will give you full analysis
Informatics Olympiad all in one 1359: enclosed area
云厂商为什么都在冲这个KPI?
Deep parsing of kubernetes controller runtime
796 div.2 C. managing history thinking
#795 Div.2 E. Number of Groups set *
Squid proxy server (Web cache layer for cache acceleration)
Technical debt wall: a way to make technical debt visible and negotiable
The development of the Internet provides new solutions for industrial transformation
golang 猴子吃桃子,求第一天桃子的数量
LabVIEW continuous sampling and limited sampling mode
CharSequence初探
Latest MySQL advanced SQL statement Encyclopedia