当前位置:网站首页>Programming questions (continuously updated)
Programming questions (continuously updated)
2022-06-24 09:51:00 【IT_ wangxianda】
One 、 Xiaoming is hijacked by unknown forces . After being thrown to x There's no more space for star stations . Xiao Ming learned that every day there are spaceships flying to the earth , But you need 108 A ticket for $1 , And he's broke .
He decided to be in x Star Wars work . The kind-hearted boss promised to pay for food and accommodation , The first 1 God give it to him 1 Yuan .
also , Every day after that is better than the previous one - More days 2 Yuan , Until he has enough money to buy the ticket .
Please program to calculate how many days Xiaoming will be able to make up 108 element , Back to earth .
javascript Familiar with , Use javascript, In fact, it's almost the same in any language
【 The question 】
// Need to save 108 A ticket for $1
// The first day 1 element
// the second day 1+2
// On the third day 1+2+2
// On the third day 1+2+2+2
// How many days can I save 108 element ( Every day's money adds up )
【 Code 】
var m = 1;
var sum = 0;
for (let i = 1; sum < 108; i++) {
if (i > 1) {
m = m + 2; // More money per day 2 element
}
sum = m + sum; // The money accumulated every day
console.log(" How many days does it take :", i, " Money per day :", m, " What's the total cost? ", sum)
// console.log(i)
if (sum >= 108) {
// console.log(i)
}
}
【 analysis 】
if (i > 1) {
m = m + 2; // More money per day 2 element // Note that there Don't go on the first day +2 , The first day 1, otherwise , Calculate the i Namely 10 You can save enough money in a day , That is to say, only one yuan on the first day counts as one day
}
【 result 】

Ongoing update , I've been learning some basics recently , And some simple algorithms , Brush up on logic
边栏推荐
- Oracle 12c升级至19c后ORA-28000错误
- ThinkPHP5多语言切换项目实战
- php单例模式详解
- Oracle viewing data file header SCN information
- June 13-19, 2022 AI industry weekly (issue 102): career development
- 二十、处理器调度(RR时间片轮转,MLFQ多级反馈队列,CFS完全公平调度器,优先级翻转;多处理器调度)
- Thinkphp5清除runtime下的cache缓存,temp缓存,log缓存
- 有关二叉树 的基本操作
- 使用Live Chat促进业务销售的惊人技巧
- LeetCode: 240. 搜索二维矩阵 II
猜你喜欢

医学图像开源数据集汇总(二)

indexedDB本地存储,首页优化

PTA monkey chooses King (Joseph Ring problem)

使用Live Chat促進業務銷售的驚人技巧

Latex formula and table recognition

Servlet快速筑基

Conseils étonnants pour promouvoir les ventes d'entreprise avec le chat en direct

Analysis of 43 cases of MATLAB neural network: Chapter 32 time series prediction of wavelet neural network - short-term traffic flow prediction

LeetCode: 240. Search 2D matrix II

20、 Processor scheduling (RR time slice rotation, mlfq multi-level feedback queue, CFS fully fair scheduler, priority reversal; multiprocessor scheduling)
随机推荐
Practical analysis: implementation principle of APP scanning code landing (app+ detailed logic on the web side) with source code
Oracle viewing data file header SCN information
PHP使用递归和非递归方式实现创建多级文件夹
WindowManager 简单悬浮框的实现
《MATLAB 神经网络43个案例分析》:第32章 小波神经网络的时间序列预测——短时交通流量预测
port 22: Connection refused
观察者模式
el-table表格的拖拽 sortablejs
Amendment to VPP implementation policy routing
Learn Tai Chi Maker - esp8226 (12) esp8266 multitasking
GIS实战应用案例100篇(十四)-ArcGIS属性连接和使用Excel的问题
Dragging El table sortablejs
Literature Research Report
Arbre binaire partie 1
ssh远程免密登录
算法--找到和最大的长度为 K 的子序列(Kotlin)
canvas 绘制图片
js单例模式
Honeypot 2 hfish, ehoney
开源一款监控数据采集器,啥都能监控