// 1. sheep produce next generation on 2th and 4th year // 2. sheep dies on 5th year // 3. calculate total amount on certain year var sheepfold = [], index = 0, amount; function Sheep() { this.age = 1; this.index = index++; } Sheep.prototype.grow = function() { this.age += 1; if(/2|4/.test(this.age)) { sheepfold.push(new Sheep()); } else if(this.age === 5) { for(var i = 0; i < sheepfold.length; i++) { if(this.index === sheepfold[i].index) { sheepfold.splice(i, 1); break; } } } } function calc(year) { if(!year || year < 1) return; for (var i = 1; i <= +year; i++) { if(i === 1) { sheepfold.push(new Sheep()); } else { sheepfold.forEach(function(sheep) { sheep.grow(); }); } } return sheepfold.length; } amount = calc(20); console.log('Total amount: ' + amount);
相关推荐
It is fundamentally a supervised learning learning problem in that a training set of labelled images is provided. The twenty object classes that have been selected are: Person: person Animal: ...
It is fundamentally a supervised learning learning problem in that a training set of labelled images is provided. The twenty object classes that have been selected are: Person: person Animal: ...
" 需要填写的是名词,结合选项,应该是"sheep",因为sheep单复数同形。 2. "These are your books and those are _________" 这里填入"we"的宾格形式"ours",表示"那些是我们的"。 3. "You’d better use some _____...
此外,针对不同的情境,如提议、请求、拒绝等,应选择合适的回应,如"Sure, no problem"表示同意,"Sorry, I'm not available now"则表示当前无法满足请求。 2. 习语和俚语:英语中,一些特定的表达方式具有特殊...
4. 没问题 - No problem 5. 看 - Look at 四、图片配对 这部分需要学生将句子与对应的图片连线,例如: 1. 不要在这里右转 - 图片可能与交通标志相关 2. 大象喜欢水 - 图片可能展示大象在水中 3. 上海既大又著名 - ...
11. **单句改错** - "The farmers built fences in order to defend their sheep with wolves."改为"The farmers built fences in order to defend their sheep against wolves." - 正确的介词是"against",表示防御...
* 题目1016:Prime Ring Problem,涉及到递归搜索的概念。 * 题目1026:Ignatius and the Princess I,涉及到完全搜索的概念。 2. 图的遍历:深度优先搜索(DFS)、广度优先搜索(BFS)等。 * 题目1043:Eight,...
文件中会定义类和方法,如`Farmer`、`Wolf`、`Sheep`、`Cabbage`等对象,以及解决问题的核心算法。 2. **状态表示**:在源代码中,农夫、狼、羊和白菜的位置可能用布尔值或者整型变量来表示,分别对应在左岸(0)或...
(Many sheep were kept by John’s family around the house.) - **比较级的倒装句**:他锻炼得越多,变得就越强壮。(The more exercise he took, the stronger he became.) - **独立主格结构**:我们应该独自...
5. "turn out" 在 "At first I thought that math problem would be rather difficult, but it turned out to be fairly easy." 中表示“结果是”,表明事情最后并不像最初预想的那样困难。 6. "of you to say so" ...
**词汇**:练习题中涉及到的词汇如`exact`(精确的)、`helpful`(有帮助的)、`donkeys`(驴的复数形式)、`discuss`(讨论)、`original`(原创的)、`cloning`(克隆的动名词形式)、`design`(设计)、`sheep`...
5. 感叹句:用在what引导的感叹句中,如"What a difficult problem!",强调问题的难度。 6. 固定搭配:在特定短语中,如"have a look"意为看一看。 【定冠词the】的用法: 1. 特指:特指已知的人或事物,如"The pen...
在计算机科学领域,哲学家就餐问题(Dining Philosophers Problem)是一个经典的多线程同步问题,由艾兹格·迪科斯彻提出,用以阐述并发控制中的死锁问题。在这个问题中,五位哲学家围坐在一张圆桌旁,每人面前有一...