ajiyoshi
|
codepad
|
|
ajiyoshi
|
Saved pastes by ajiyoshi:
#include<vector>
#include<list>
#include<string>
#include<iostream>
#include<numeric> //accumulate
|
view (35 lines, 3 lines of output) |
<?php
echo array_reduce(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), create_function('$a,$b', 'return $a+$b;'));
echo array_reduce(array("a", "b", "c"), create_function('$a,$b', 'return $a.$b;'));
?>
|
view (4 lines, 1 line of output) |
#自分で書く必要はない
use List::Util qw/reduce/;
print reduce { $a + $b } (1 .. 10);
print reduce { $a . $b } ("a", "b", "c");
|
view (4 lines, 1 line of output) |
# -*- coding: utf-8 -*-
#自分で書く必要はない
print reduce(lambda x, y: x + y, range(1, 11))
print reduce(lambda x, y: x + y, ["a", "b", "c"])
|
view (4 lines, 2 lines of output) |