How to convert this extensive Python loop to C++? -


i know little on python, i'm quite experienced in c++. looking algorithm loop through points in hexagon pattern , found 1 written in python seems need. problem have no idea how interpret it.

here python code:

for x in [(n-abs(x-int(n/2))) x in range(n)]:     y in range(n-x):         print ' ',     y in range(x):         print ' * ',     print 

i'd show attempts there 30 different ones failed (which i'm sure bad interpretation).

hope helps you.tested both python , c++ code .got same results.

#include <iostream> #include <cmath>   using namespace std;  int main() {     // code goes here     int n = 10;     int a[n];      for(int j = 0; j < n; j++) {        a[j] = n - abs(j - (n / 2));      }      for(int x = 0; x < n; x++) {         for(int y = 0; y < (n - a[x]); y++) {             std::cout << " " << std::endl;         }     }      for(int k = 0; k < a[n-1]; k++) {         std::cout << " * " << std::endl;     }      std::cout << "i" << std::endl;      return 0; } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -