Skip to content

Instantly share code, notes, and snippets.

@ex
Last active September 24, 2015 17:08
Show Gist options
  • Select an option

  • Save ex/781366 to your computer and use it in GitHub Desktop.

Select an option

Save ex/781366 to your computer and use it in GitHub Desktop.
IMO 1960 Problem 01
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