当前位置:网站首页>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))
}边栏推荐
- Taro--- day1--- construction project
- 单晶炉导电滑环的应用范围和作用是什么
- Alchemy (1): identify prototype, demo and MVP in project development
- 界面组件Telerik UI for WPF入门指南 - 如何使用主题切换自定义样式
- Official announcement! Apache Doris graduated from the Apache incubator and officially became the top project of Apache!
- NoSQL之Redis配置与优化
- Technical debt wall: a way to make technical debt visible and negotiable
- 最新MySQL高级SQL语句大全
- Ceiling scheme 1
- What is a through-hole conductive slip ring?
猜你喜欢

Installation and use of Zotero document management tool

N methods of data De duplication using SQL

Alchemy (7): how to solve problems? Only reconstruction

How about the market application strength of large-size conductive slip rings

Overview and deployment of GFS distributed file system

Sword finger offer 61 Shunzi in playing cards

大尺寸导电滑环市场应用强度如何

What are cookies and the security risks of v-htm

Download, configuration and installation of MySQL
![[untitled]](/img/15/21020badab0d70450ccfb71f49da8a.png)
[untitled]
随机推荐
CharSequence初探
哪个证券炒股开户佣金是最便宜,最安全的
MySQL十种锁,一篇文章带你全解析
股票投资交流群安全吗?入群免费开户靠谱嘛?
網頁鼠標點擊特效案例收集(直播間紅心同理)
Why stainless steel swivel
Is it reliable to invest in exchange traded ETF funds? Is it safe to invest in exchange traded ETF funds
Is it safe for Xiaobai in the stock market to open an account on the Internet?
What is the e-commerce conversion rate so abstract?
Modern programming languages: zig
Taro---day1---搭建项目
Alchemy (6): iteratable models and use cases
网页鼠标点击特效案例收集(直播间红心同理)
Taro--- day2--- compile and run
plot_model报错:没有安装pydot, graphviz
#796 Div.2 F. Sanae and Giant Robot set *
给女朋友看的消息中间件
Every time I started the service of the project, the computer helped me open the browser, revealing the 100 lines of source code!
单晶炉导电滑环的应用范围和作用是什么
How about the market application strength of large-size conductive slip rings