Java_programmer

Hexa.cpp

Jan 31st, 2023 (edited)
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. /*
  2.  
  3. Pattern challenge
  4. Author A.S.
  5.  
  6.         @ @ @ @ @ @ @ @
  7.        @ @   @   @   @ @
  8.       @   @ @     @ @   @
  9.      @ @ @ @       @ @ @ @
  10.     @       @ @ @ @       @
  11.    @ @     @ @   @ @     @ @
  12.   @   @   @   @ @   @   @   @
  13.  @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
  14.   @   @   @   @ @   @   @   @    
  15.    @ @     @ @   @ @     @ @        
  16.     @       @ @ @ @       @            
  17.      @ @ @ @       @ @ @ @                
  18.       @   @ @     @ @   @                    
  19.        @ @   @   @   @ @                        
  20.         @ @ @ @ @ @ @ @                            
  21.  
  22. */
  23.  
  24. #include<stdlib.h>     // abs
  25. #include<iomanip>
  26. #include<iostream>
  27. using   std::setw,
  28.         std::cout, std::endl;
  29.  
  30. auto main()
  31.     -> int
  32. {
  33.     const int n = 3;
  34.     const int w = 1 << n;
  35.     for( int y = 0; y < 2*w - 1; ++y ) {
  36.         const int cw = w - 1;
  37.         cout << setw( abs( cw - y ) ) << "";
  38.         const int cy = cw - abs( cw - y );
  39.         for( int x = 0; x < w + y; ++x ) {
  40.             const int tx = (x < cy? x : x < w? w - 1 - x : x + 1 - w);
  41.             const int ty = (x < cy? cy : x < w? w - 1 - cy : cy);
  42.             const char ch = (tx & ~ty? ' ' : '@');
  43.             cout << setw( 2 ) << ch;
  44.         }
  45.          cout << endl;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment