* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
		
			
				
	
	
		
			79 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| ---
 | |
| id: 594db4d0dedb4c06a2a4cefd
 | |
| title: Babbage problem
 | |
| challengeType: 5
 | |
| forumTopicId: 302229
 | |
| dashedName: babbage-problem
 | |
| ---
 | |
| 
 | |
| # --description--
 | |
| 
 | |
| [Charles Babbage](https://en.wikipedia.org/wiki/Charles_Babbage "wp: Charles_Babbage"), looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example:
 | |
| 
 | |
| <blockquote>
 | |
|   What is the smallest positive integer whose square ends in the digits 269,696?
 | |
|   <footer style='margin-left: 2em;'>Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, <i>Electronic Computers</i>, second edition, 1970, p. 125.</footer>
 | |
| </blockquote>
 | |
| 
 | |
| He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.
 | |
| 
 | |
| The task is to find out if Babbage had the right answer.
 | |
| 
 | |
| # --instructions--
 | |
| 
 | |
| Implement a function to return the lowest integer that satisfies the Babbage problem. If Babbage was right, return Babbage's number.
 | |
| 
 | |
| # --hints--
 | |
| 
 | |
| `babbage` should be a function.
 | |
| 
 | |
| ```js
 | |
| assert(typeof babbage === 'function');
 | |
| ```
 | |
| 
 | |
| `babbage(99736, 269696)` should not return 99736 (there is a smaller answer).
 | |
| 
 | |
| ```js
 | |
| assert.equal(babbage(babbageAns, endDigits), answer);
 | |
| ```
 | |
| 
 | |
| # --seed--
 | |
| 
 | |
| ## --after-user-code--
 | |
| 
 | |
| ```js
 | |
| const babbageAns = 99736;
 | |
| const endDigits = 269696;
 | |
| const answer = 25264;
 | |
| ```
 | |
| 
 | |
| ## --seed-contents--
 | |
| 
 | |
| ```js
 | |
| function babbage(babbageNum, endDigits) {
 | |
| 
 | |
|   return true;
 | |
| }
 | |
| ```
 | |
| 
 | |
| # --solutions--
 | |
| 
 | |
| ```js
 | |
| function babbage(babbageAns, endDigits) {
 | |
|   const babbageNum = Math.pow(babbageAns, 2);
 | |
|   const babbageStartDigits = parseInt(babbageNum.toString().replace('269696', ''));
 | |
|   let answer = 99736;
 | |
| 
 | |
|   // count down from this answer and save any sqrt int result. return lowest one
 | |
|   for (let i = babbageStartDigits; i >= 0; i--) {
 | |
|     const num = parseInt(i.toString().concat('269696'));
 | |
|     const result = Math.sqrt(num);
 | |
|     if (result === Math.floor(Math.sqrt(num))) {
 | |
|       answer = result;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   return answer;
 | |
| }
 | |
| ```
 |