Skip to content

Instantly share code, notes, and snippets.

@githubgobi
Last active December 18, 2022 17:13
Show Gist options
  • Save githubgobi/292fa114cbd1df45eb819b9471d96506 to your computer and use it in GitHub Desktop.
Save githubgobi/292fa114cbd1df45eb819b9471d96506 to your computer and use it in GitHub Desktop.
Solve Any Patterns
<?php
/**
https://github.com/kunal-kushwaha/DSA-Bootcamp-Java/blob/main/assignments/09-patterns.md
* points for solve any patterns
* 1. Outer loop -> no of rows ( no of lines == no of rows)
* 2.Identify the values
* > how many columns are there for each row or
* > Type of elements like ( * or numbers or spaces)
* 3. What do you need to print like ( * or numbers or spaces)
* point no 2.1 and 3 look similar
**/
Pattern Questions
Print these patterns using loops:
```text
1. *****
*****
*****
*****
*****
2. *
**
***
****
*****
3. *****
****
***
**
*
4. 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
5. *
**
***
****
*****
****
***
**
*
6. *
**
***
****
*****
7. *****
****
***
**
*
8. *
***
*****
*******
*********
9. *********
*******
*****
***
*
10. *
* *
* * *
* * * *
* * * * *
11. * * * * *
* * * *
* * *
* *
*
12. * * * * *
* * * *
* * *
* *
*
*
* *
* * *
* * * *
* * * * *
13. *
* *
* *
* *
*********
14. *********
* *
* *
* *
*
15. *
* *
* *
* *
* *
* *
* *
* *
*
16. 1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
17. 1
212
32123
4321234
32123
212
1
18. **********
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
**********
19. * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *
20. ****
* *
* *
* *
****
21. 1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
22. 1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
23. * *
* * * *
* * *
24. * *
** **
* * * *
* * * *
* ** *
* ** *
* * * *
* * * *
** **
* *
25. *****
* *
* *
* *
*****
26. 1 1 1 1 1 1
2 2 2 2 2
3 3 3 3
4 4 4
5 5
6
27. 1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11
28. *
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
29.
* *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *
30. 1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
31. 4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4
32. E
D E
C D E
B C D E
A B C D E
33. a
B c
D e F
g H i J
k L m N o
34. E D C B A
D C B A
C B A
B A
A
35. 1 1
12 21
123 321
12344321
```
// your code goes here
Result: Pattern-8
$n=5;
for($i=1;$i<=$n;$i++){
$space = $n-$i+1;
for($j=1;$j<=$n;$j++){
if($j<$space){
echo " ";
}else{
echo "* ";
}
}
echo PHP_EOL;
}
https://github.com/kunal-kushwaha/DSA-Bootcamp-Java/blob/main/assignments/09-patterns.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment