Skip to content

Commit 2353fee

Browse files
committed
solved 16_PatternChallenge
1 parent 974f655 commit 2353fee

File tree

3 files changed

+114
-43
lines changed

3 files changed

+114
-43
lines changed

Pattern Algorithms/15_PatternChallenge.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace std;
2323
void printPattern_15(char*);
2424

2525
int main(){
26-
// input string
26+
// input str
2727
char str[]= "program";
2828

2929
printPattern_15(str);
@@ -67,10 +67,4 @@ void printPattern_15(char* input){
6767
cout<<endl;
6868

6969
}
70-
71-
72-
73-
74-
75-
7670
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
/*******************************************************************************************************
3+
/* ___ _ _ _ _
4+
/* / _ \ | | (_)| | | |
5+
/* / /_\ \__ __ ___ | | __ _ ___ _ __ _ | |_ | |__ _ __ ___ ___
6+
/* | _ |\ \ /\ / / / _ \| | / _` | / _ \ | '__|| || __|| '_ \ | '_ ` _ \ / __|
7+
/* | | | | \ V V / | __/| || (_| || (_) || | | || |_ | | | || | | | | |\__ \
8+
/* \_| |_/ \_/\_/ \___||_| \__, | \___/ |_| |_| \__||_| |_||_| |_| |_||___/
9+
/* __/ |
10+
/* |___/
11+
/******************************************************************************************************/
12+
13+
/***********************************
14+
/* 16_PatternChallenge
15+
/***********************************/
16+
17+
// Library imports
18+
#include <iostream>
19+
using namespace std;
20+
21+
//Prototypes for the algorithms
22+
void printPattern_16(int);
23+
24+
int main(){
25+
// user input
26+
int userInput;
27+
28+
cout<<"Enter number of lines."<<endl;
29+
cin>>userInput;
30+
31+
printPattern_16(userInput);
32+
return 0;
33+
}
34+
35+
/**********************************************************
36+
/* <printPattern_16>
37+
/*
38+
/* @description : Algorithm to print a chessboard with 'nxn' grid
39+
/* @param : Integer<input>
40+
/* @return : None, void
41+
/* @complexity : O(n^2)
42+
/* @explanation : This algorithm iterates'inputxinput' times. The outer loop iterates input times.
43+
/* Inner loop iterates input times too, if the i value is odd, it adds a whitespace character
44+
/* to push the chars one space ahead giving it the illusion of a chessboard. In the inner loop,
45+
/* if 'j' is even, we print a "#", else, we print a whitespace. SO its pretty much same loop
46+
/* in every 'i' iteration, but the whitespace offset for every odd 'i' is what gives the output
47+
/* the chess board look.
48+
/* @author : Pranay Kothapalli @kotAPI
49+
/**********************************************************/
50+
void printPattern_16(int input){
51+
52+
// Outer
53+
for(int i=0;i<input;i++){
54+
// Check if i is odd;
55+
// Push the chars by a whitespace if its even
56+
if(i%2==0){
57+
cout<<" ";
58+
}
59+
60+
// Inner loop to print the alternating black and white squares of chessboard
61+
// black squares are represented by '#'
62+
// white squares are represented by " " (white space)
63+
for(int j=0;j<input;j++){
64+
// If j is even print white square
65+
if(j%2==0){
66+
cout<<"#";
67+
}
68+
// If j is odd print a black square
69+
else{
70+
cout<<" ";
71+
}
72+
}
73+
// Add a newline once the inner loops have finished executing.
74+
cout<<endl;
75+
}
76+
77+
}

Pattern Algorithms/README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,19 @@
241241
*
242242
* * * * * * * * * *
243243

244-
TODO :
244+
## TODO :
245245

246-
11111
247-
12221
248-
12321
249-
12221
250-
11111
246+
11111
247+
12221
248+
12321
249+
12221
250+
11111
251251

252-
1
253-
A B
254-
2 3 4
255-
C D E F
256-
5 6 7 8 9
252+
1
253+
A B
254+
2 3 4
255+
C D E F
256+
5 6 7 8 9
257257

258258
*******
259259
*** ***
@@ -271,29 +271,29 @@ C D E F
271271
* *
272272
*
273273

274-
* * * * * * * * * * * * * * * * *
275-
* * * * * * * * * * * * * *
276-
* * * * * * * * * *
277-
* * * * * *
278-
* * * * * * * * *
279-
* * * * * * *
280-
* * * * *
281-
* * *
282-
*
283-
284-
*
285-
* * *
286-
* * * * *
287-
* * * * * * *
288-
* *
289-
* * * *
290-
* * * * * *
291-
* * * * * * *
292-
* * * * * *
293-
* * * *
294-
* *
295-
* * * * * * *
296-
* * * * *
297-
* * *
298-
*
274+
- * * * * * * * * * * * * * * * *
275+
- * * * * * * * * * * * * *
276+
- * * * * * * * * *
277+
- * * * * *
278+
- * * * * * * * *
279+
- * * * * * *
280+
- * * * *
281+
- * *
282+
*
283+
284+
*
285+
- * *
286+
- * * * *
287+
- * * * * * *
288+
- *
289+
- * * *
290+
- * * * * *
291+
- * * * * * *
292+
- * * * * *
293+
- * * *
294+
- *
295+
- * * * * * *
296+
- * * * *
297+
- * *
298+
*
299299

0 commit comments

Comments
 (0)