项目作者: rodionovsasha

项目描述 :
Implementation of the Armstrong number (https://en.wikipedia.org/wiki/Narcissistic_number) search algorithm on GoLang.
高级语言: Go
项目地址: git://github.com/rodionovsasha/GoArmstrongNumbers.git
创建时间: 2018-05-31T11:29:13Z
项目社区:https://github.com/rodionovsasha/GoArmstrongNumbers

开源协议:MIT License

下载


Armstrong numbers

Implementation of the Armstrong number (https://en.wikipedia.org/wiki/Narcissistic_number) search algorithm on GoLang.

The number S consists of M digits, for example, S = 370 and M (number of digits) = 3.
It is necessary to implement the logic of the method, which must be among natural numbers less than N (int64) to find all numbers,
satisfying the following criterion:
the number S is equal to the sum of its digits raised to the power of M. The program must return all such numbers in ascending order.

Example of the number:
370 = 3 3 3 + 7 7 7 + 0 0 0
8208 = 8 8 8 8 + 2 2 2 2 + 0 0 0 0 + 8 8 8 8
The execution time must not be more then 10 seconds.

Run the program:

  1. go run ArmstrongNumbers.go

Output:

  1. 1. 1
  2. 2. 2
  3. 3. 3
  4. 4. 4
  5. 5. 5
  6. 6. 6
  7. 7. 7
  8. 8. 8
  9. 9. 9
  10. 10. 153
  11. 11. 370
  12. 12. 371
  13. 13. 407
  14. 14. 1634
  15. 15. 8208
  16. 16. 9474
  17. 17. 54748
  18. 18. 92727
  19. 19. 93084
  20. 20. 548834
  21. 21. 1741725
  22. 22. 4210818
  23. 23. 9800817
  24. 24. 9926315
  25. 25. 24678050
  26. 26. 24678051
  27. 27. 88593477
  28. 28. 146511208
  29. 29. 472335975
  30. 30. 534494836
  31. 31. 912985153
  32. 32. 4679307774
  33. 33. 32164049650
  34. 34. 32164049651
  35. 35. 40028394225
  36. 36. 42678290603
  37. 37. 44708635679
  38. 38. 49388550606
  39. 39. 82693916578
  40. 40. 94204591914
  41. 41. 28116440335967
  42. 42. 4338281769391370
  43. 43. 4338281769391371
  44. 44. 21897142587612075
  45. 45. 35641594208964132
  46. 46. 35875699062250035
  47. 47. 1517841543307505039
  48. 48. 3289582984443187032
  49. 49. 4498128791164624869
  50. 50. 4929273885928088826
  51. Execution time: 5.417459032s

The full list of the numbers is here: http://mathworld.wolfram.com/NarcissisticNumber.html