Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

I just wanted some review and opinions. Any better implementations or suggestions would be great.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

var sequence = [1,2]
var index = 1
var sum = 0
repeat {
 sequence.append(sequence[index-1] + sequence[index])
 index = index + 1
} while sequence[sequence.endIndex - 1] < 4000000
sequence.popLast()
for numbers in sequence {
 if (numbers % 2 == 0) {
 sum += numbers
 }
}
print(sum)

I just wanted some review and opinions. Any better implementations or suggestions would be great.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

var sequence = [1,2]
var index = 1
var sum = 0
repeat {
 sequence.append(sequence[index-1] + sequence[index])
 index = index + 1
} while sequence[sequence.endIndex - 1] < 4000000
sequence.popLast()
for numbers in sequence {
 if (numbers % 2 == 0) {
 sum += numbers
 }
}
print(sum)

I just wanted some review and opinions. Any better implementations or suggestions would be great.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

var sequence = [1,2]
var index = 1
var sum = 0
repeat {
 sequence.append(sequence[index-1] + sequence[index])
 index = index + 1
} while sequence[sequence.endIndex - 1] < 4000000
sequence.popLast()
for numbers in sequence {
 if (numbers % 2 == 0) {
 sum += numbers
 }
}
print(sum)
deleted 7 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

JustI just wanted some review and opinions. Any better implementations or suggestions would be great thanks.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

var sequence = [1,2]
var index = 1
var sum = 0
repeat {
 sequence.append(sequence[index-1] + sequence[index])
 index = index + 1
} while sequence[sequence.endIndex - 1] < 4000000
sequence.popLast()
for numbers in sequence {
 if (numbers % 2 == 0) {
 sum += numbers
 }
}
print(sum)

Just wanted some review and opinions. Any better implementations or suggestions would be great thanks.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

var sequence = [1,2]
var index = 1
var sum = 0
repeat {
 sequence.append(sequence[index-1] + sequence[index])
 index = index + 1
} while sequence[sequence.endIndex - 1] < 4000000
sequence.popLast()
for numbers in sequence {
 if (numbers % 2 == 0) {
 sum += numbers
 }
}
print(sum)

I just wanted some review and opinions. Any better implementations or suggestions would be great.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

var sequence = [1,2]
var index = 1
var sum = 0
repeat {
 sequence.append(sequence[index-1] + sequence[index])
 index = index + 1
} while sequence[sequence.endIndex - 1] < 4000000
sequence.popLast()
for numbers in sequence {
 if (numbers % 2 == 0) {
 sum += numbers
 }
}
print(sum)
Source Link

Project Euler solution #2 using Swift 3

Just wanted some review and opinions. Any better implementations or suggestions would be great thanks.

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

var sequence = [1,2]
var index = 1
var sum = 0
repeat {
 sequence.append(sequence[index-1] + sequence[index])
 index = index + 1
} while sequence[sequence.endIndex - 1] < 4000000
sequence.popLast()
for numbers in sequence {
 if (numbers % 2 == 0) {
 sum += numbers
 }
}
print(sum)
default

AltStyle によって変換されたページ (->オリジナル) /