Finished of e2, two ruby methods
This commit is contained in:
parent
907652a192
commit
2d574d4514
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
last = sum = 0
|
||||
current = 1
|
||||
while current < 4000000
|
||||
if current % 2 == 0
|
||||
sum += current
|
||||
end
|
||||
tmp = current
|
||||
current += last
|
||||
last = tmp
|
||||
end
|
||||
puts sum
|
|
@ -0,0 +1,7 @@
|
|||
(defun e2 ()
|
||||
(let ((sum 0))
|
||||
(do ((last 0 current)
|
||||
(current 1 (+ current last)))
|
||||
( (>= current 4000000) sum)
|
||||
(if (= (rem current 2) 0)
|
||||
(incf sum current)))))
|
11
e2/e2.m
11
e2/e2.m
|
@ -1 +1,12 @@
|
|||
#include <objc/Object.h>
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
int i, last, current, sum, tmp;
|
||||
sum = 0;
|
||||
last = 0;
|
||||
for(current = 1; current < 4000000; tmp = current, current = last + current, last = tmp) {
|
||||
if ( current % 2 == 0)
|
||||
sum += current;
|
||||
}
|
||||
printf("%d\n", sum);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
last = sum = 0
|
||||
current = 1
|
||||
while (current < 4000000):
|
||||
if current % 2 == 0:
|
||||
sum += current
|
||||
tmp = current
|
||||
current += last
|
||||
last = tmp
|
||||
print sum
|
Loading…
Reference in New Issue