Skip to content

Instantly share code, notes, and snippets.

@castaneai
Created April 16, 2014 15:21
Show Gist options
  • Save castaneai/10893120 to your computer and use it in GitHub Desktop.
Save castaneai/10893120 to your computer and use it in GitHub Desktop.
5 => 1,2,3,4,5,4,3,2,1 のようなピラミッド型ループを作る
#include <iostream>
#include <functional>
using namespace std;
void pyramid(int max, function<void(int)> each)
{
for (int i = 1; i < max * 2; i++){
each(i - (i / max) * (i % max) * 2);
}
}
int main(void)
{
pyramid(9, [](int i) {
cout << i << ", ";
});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment