Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Created March 13, 2015 15:22
Show Gist options
  • Select an option

  • Save alphaKAI/3e05347274d86d3ea167 to your computer and use it in GitHub Desktop.

Select an option

Save alphaKAI/3e05347274d86d3ea167 to your computer and use it in GitHub Desktop.
等差数列
import std.stdio;
int f(int a, int d, int n){
return a + d * (n - 1);
}
int sumf(int n, int function(int) fx){
return n * (fx(1) + fx(n)) / 2;
}
void main(){
auto fn = ((int n) => f(1, 1, n));
sumf(10, fn).writeln;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment