Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create A_Unique_Pattern #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MDAFSARALI
Copy link

Problem 22 :

5 5 5 5 5 5 5 5 5 
5 4 4 4 4 4 4 4 5 
5 4 3 3 3 3 3 4 5 
5 4 3 2 2 2 3 4 5 
5 4 3 2 1 2 3 4 5 
5 4 3 2 2 2 3 4 5 
5 4 3 3 3 3 3 4 5 
5 4 4 4 4 4 4 4 5 
5 5 5 5 5 5 5 5 5

Practice Link :

CODE SOLUTION

Approach for pattern22 (English Solution) 🚀

  • This function prints a square pattern of size 2*n-1 📏.

  • For each cell, four distances are calculated based on i and j:

    • 📍 Distance from the top: i
    • 📍 Distance from the bottom: 2*n-2 - i
    • 📍 Distance from the left: j
    • 📍 Distance from the right: 2*n-2 - j
  • The minimum of these four distances is taken 🧮, and n - min() is printed in that cell 🖨️.

  • This ensures that the value decreases symmetrically 📉 as we move towards the center of the pattern 🎯.


Approach for pattern22 (Hinglish_Solution)

  • Yeh function ek 2*n-1 size ka square pattern print karta hai.
  • Har cell ke liye, i aur j ke basis par 4 distances calculate hote hain: top, bottom, left, aur right.
  • Inn distances ka minimum leke, n - min() se jo value aati hai, woh us cell mein print hoti hai.
  • Har row ke baad endl se new line print hoti hai.
void pattern22(int n) {
        for(int i=0;i<2*n-1;i++){
            for(int j=0;j<2*n-1;j++){
                int top=i,bottom=j;
                int left=(2*n-2)-i,right=(2*n-2)-j;
                cout<<n-(min(min(top,bottom),min(right,left)))<<" ";
            }
            cout<<endl;
        }
    }

Thanks ♥️


Here I have tried to contribute a new pattern
@MDAFSARALI
Copy link
Author

A new pattern Problem Added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant