Last active
September 24, 2015 17:08
-
-
Save ex/781366 to your computer and use it in GitHub Desktop.
IMO 1960 Problem 01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function solve():void { | |
| txtResult.text = ""; | |
| var count:int = 1; | |
| var k:int = 10; | |
| while (k * 11 < 1000) { | |
| // Calculate sum of the squares of the digits | |
| var sumSquares:int = 0; | |
| var n:int = k * 11; | |
| while (n > 0) { | |
| var digit:int = n % 10; | |
| sumSquares += digit * digit; | |
| n /= 10; | |
| } | |
| // Check | |
| if (sumSquares == k) { | |
| txtResult.text += count + ") " + (k * 11) + "\n"; | |
| ++count; | |
| } | |
| ++k; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment