Sha256: 8b781f2926b2b5e6d7f17a05240e7a8986eb3e8016213ec91cec2b6c00e30e5e

Contents?: true

Size: 719 Bytes

Versions: 11

Compression:

Stored size: 719 Bytes

Contents

# Problem 28
# What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral
# formed in the same way?

# Starting with the number 1 and moving to the right in a clockwise
# direction a 5 by 5 spiral is formed as follows:
#
# 21 22 23 24 25
# 20  7  8  9 10
# 19  6  1  2 11
# 18  5  4  3 12
# 17 16 15 14 13
#
# It can be verified that the sum of the numbers on the diagonals is 101.

taille = 1001
pas = taille - 1
number = taille ** 2
coins = 1
sum = number

while: { pas > 0 } do: {
  number = number - pas
  sum = sum + number
  if: (coins == 4) then: {
    coins = 1
    pas = pas - 2
  } else: {
    coins = coins + 1
  }
}

"The sum of the numbers of the diagonals of the matrix is: " ++ sum println

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fancy-0.10.0 examples/project-euler/28.fy
fancy-0.9.0 examples/project-euler/28.fy
fancy-0.8.0 examples/project-euler/28.fy
fancy-0.7.0 examples/project-euler/28.fy
fancy-0.6.0 examples/project-euler/28.fy
fancy-0.5.0 examples/project-euler/28.fy
fancy-0.4.0 examples/project-euler/28.fy
fancy-0.3.3 examples/project-euler/28.fy
fancy-0.3.2 examples/project-euler/28.fy
fancy-0.3.1 examples/project-euler/28.fy
fancy-0.3.0 examples/project-euler/28.fy