All language subtitles for 10. Print Pyramid Numbers Pattern - Solution

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,800 --> 00:00:01,890 What is going on, guys? 2 00:00:01,910 --> 00:00:08,270 And welcome back to the Solutions video, and here we are going to talk about a couple of interesting 3 00:00:08,270 --> 00:00:08,660 things. 4 00:00:09,080 --> 00:00:13,660 We are going to see how we can prevent the falling shape to the screen. 5 00:00:14,000 --> 00:00:18,790 So basically, let's just make a quick summary of what we have to do. 6 00:00:19,130 --> 00:00:23,700 We have to receive some value from the user, let's say, and equals to three. 7 00:00:24,260 --> 00:00:28,400 And in this case, we should print the following triangle to the screen. 8 00:00:28,400 --> 00:00:38,210 So we should be the first row with the value of one, then two and three and finally four, five and 9 00:00:38,210 --> 00:00:38,810 six. 10 00:00:38,940 --> 00:00:44,990 OK, so that's basically the shape we should print for the value and equals to three and these. 11 00:00:44,990 --> 00:00:47,790 And it also should specify the number of. 12 00:00:48,380 --> 00:00:54,950 So number of rows of our given triangle. 13 00:00:54,980 --> 00:00:59,280 So that's, that's the triangle that we want to bring to the screen. 14 00:00:59,820 --> 00:01:00,140 Okay. 15 00:01:00,140 --> 00:01:02,170 One, two, three, four, five, six. 16 00:01:02,780 --> 00:01:09,200 And the first question that we should be asking ourselves, OK, we know that to print a right angle 17 00:01:09,200 --> 00:01:13,970 triangle is probably not a problem using just two loops. 18 00:01:14,960 --> 00:01:16,880 We already solved it. 19 00:01:17,510 --> 00:01:21,820 I think in the beginners exercisers, we know how to do it like this. 20 00:01:21,860 --> 00:01:24,280 So one, two, three, four, five, six. 21 00:01:24,560 --> 00:01:30,560 So we pretty much remember how these shape can be printed, but now the shape is a little bit different 22 00:01:30,560 --> 00:01:32,320 and we want to print it like that. 23 00:01:33,200 --> 00:01:40,340 So if we want to understand how it should be done, we should basically look at the shape, OK, and 24 00:01:40,340 --> 00:01:47,000 start to try get some knowledge and try to get some insights out of these shape. 25 00:01:47,720 --> 00:01:53,990 And the first things I should say that basically we know that An represents the number of rows. 26 00:01:54,000 --> 00:01:56,420 So this will be our first insight. 27 00:01:57,290 --> 00:02:04,090 The second insight should be like to understand that in these shape printing we have. 28 00:02:04,100 --> 00:02:06,410 OK, so that's row number one. 29 00:02:06,440 --> 00:02:08,150 That's room number two. 30 00:02:08,150 --> 00:02:10,520 And finally, we have row number three. 31 00:02:11,060 --> 00:02:17,480 And if we take a look at it, if we if we want to keep it in the same shape, we need, first of all, 32 00:02:17,480 --> 00:02:24,760 to understand that in the last row, there is probably no need at all to add spaces before printing 33 00:02:24,770 --> 00:02:25,820 the value itself. 34 00:02:26,450 --> 00:02:33,920 But if we want to keep it this way on the second row, we will have just one space printed before and 35 00:02:33,920 --> 00:02:38,350 on the first row will have two spaces, two spaces printed before. 36 00:02:39,110 --> 00:02:40,060 So that's OK. 37 00:02:40,670 --> 00:02:44,450 But what can we conclude for for ourselves? 38 00:02:44,450 --> 00:02:51,350 Basically, if we take a look at and let's say equals two for let's say we have one, two, three, 39 00:02:52,010 --> 00:02:58,140 four, five, six, seven, eight, nine and 10. 40 00:02:58,310 --> 00:03:04,820 OK, so in this case, we can see that in the last row there is no need to add spaces before here. 41 00:03:04,820 --> 00:03:07,760 We have to add just one space here. 42 00:03:07,760 --> 00:03:11,270 We will have to add two spaces and here three spaces. 43 00:03:11,270 --> 00:03:11,560 Right. 44 00:03:12,200 --> 00:03:20,120 So if we want to like to conclude some conclusion or insight out of that, we can say that in the last 45 00:03:20,120 --> 00:03:21,440 row there is no need at all. 46 00:03:21,440 --> 00:03:26,320 But in the first row, we should add the spaces before pruning the value. 47 00:03:26,330 --> 00:03:28,280 How many spaces we are adding here? 48 00:03:28,670 --> 00:03:32,000 The number of rows, which is four minus one. 49 00:03:32,210 --> 00:03:35,140 OK, so let's see if it's also applies here. 50 00:03:35,300 --> 00:03:42,390 So here we have the number of roses three and then we print just three minus one rose. 51 00:03:42,410 --> 00:03:44,540 OK, so three minus the row itself. 52 00:03:44,840 --> 00:03:46,190 That's what we print in here. 53 00:03:46,940 --> 00:03:54,110 And later on we print every time we just decrement the number of spaces we print before the first value. 54 00:03:54,260 --> 00:04:02,470 OK, so this will be rule number two, OK, how to print the spaces before OK, print spaces. 55 00:04:03,980 --> 00:04:10,970 So basically we also should consider how we print just not the same value like we've done it with using 56 00:04:10,970 --> 00:04:11,960 these stars. 57 00:04:11,960 --> 00:04:12,200 Right. 58 00:04:12,200 --> 00:04:13,430 We know how to print that. 59 00:04:13,760 --> 00:04:19,190 We should also take into account the printing of the value in incrementing it by one. 60 00:04:19,300 --> 00:04:22,460 OK, so that will be the third option. 61 00:04:22,460 --> 00:04:27,260 Like to increment increment station, let's call it this way. 62 00:04:27,290 --> 00:04:27,540 OK. 63 00:04:27,560 --> 00:04:29,270 So there will be instrumentation. 64 00:04:29,870 --> 00:04:30,380 Awesome. 65 00:04:31,190 --> 00:04:38,720 So for that, let's start solving this exercise and let's think about what should be the solution here. 66 00:04:38,840 --> 00:04:45,740 And instead of writing everything from scratch, I will simply use this technique to show you guys how 67 00:04:45,740 --> 00:04:51,290 it can be done and also talk about every one, every one of these lines. 68 00:04:52,190 --> 00:04:55,310 So, OK, so let's start with the declaration phase. 69 00:04:55,670 --> 00:04:59,600 We know that we have to create the variable m, OK? 70 00:05:00,360 --> 00:05:07,860 Also, we know that probably we are going to use a couple of loops here, so I will create in advance 71 00:05:07,860 --> 00:05:15,930 three variables I, J and K and I will explain you in a moment about each of these variables and where 72 00:05:15,930 --> 00:05:22,300 it's going to be implemented in our code and in the loops that we are going to use. 73 00:05:22,590 --> 00:05:30,270 So basically that we understand and also the blank spaces I will talk about in a moment, basically. 74 00:05:30,280 --> 00:05:32,120 Let's just explain them right away. 75 00:05:32,370 --> 00:05:38,910 So the blank spaces and that's actually the spaces that we want to the number of spaces that we want 76 00:05:38,910 --> 00:05:44,190 to print before printing the value at each and every row. 77 00:05:44,340 --> 00:05:50,010 OK, so we know that if we receive n OK, so that was that's what we do here. 78 00:05:50,020 --> 00:05:55,550 We receive the value of and which specifies the number of throws in these final pyramid. 79 00:05:56,190 --> 00:06:03,660 So we read this value and store it inside and that's we understand and the blank spaces for the first 80 00:06:03,660 --> 00:06:08,190 time we are going to print will be equal to the number of rows minus one. 81 00:06:08,250 --> 00:06:09,410 OK, we talked about it. 82 00:06:09,630 --> 00:06:16,290 So if we have three rows and we are going to set the blank spaces, which is the number of blank spaces 83 00:06:16,290 --> 00:06:22,380 printed before this value will be three minus one, which will be a total of two. 84 00:06:22,540 --> 00:06:26,510 OK, and then we will simply update this value. 85 00:06:26,520 --> 00:06:30,590 I will show you show you how it can be done for every row. 86 00:06:30,960 --> 00:06:32,300 Just a couple of moments. 87 00:06:32,310 --> 00:06:32,800 OK, guys. 88 00:06:32,970 --> 00:06:40,890 So for now, let's simply set this value to be equal to rows minus one for our first row, where we 89 00:06:40,890 --> 00:06:43,960 have to know the number of spaces printed for the screen. 90 00:06:44,820 --> 00:06:45,370 Awesome. 91 00:06:45,780 --> 00:06:47,550 So that's no. 92 00:06:47,550 --> 00:06:51,690 And the current value, what will be these current value here? 93 00:06:52,140 --> 00:06:57,080 The current value is just the value that we have to print at this moment. 94 00:06:57,480 --> 00:07:03,060 So it start we have to print one, then we have to print two, then we have to bring three and so on. 95 00:07:03,510 --> 00:07:09,120 We are not printing just some common character at each of the lines. 96 00:07:09,390 --> 00:07:15,990 We we have to keep some value, the current value that should be printed in each command. 97 00:07:16,020 --> 00:07:21,780 OK, so if we know that we printed the value of one, that the current value was initialized to one, 98 00:07:22,200 --> 00:07:29,370 then if we printed one, then we should increment this value by one because we know that we want to 99 00:07:29,670 --> 00:07:30,540 like to print. 100 00:07:30,540 --> 00:07:32,580 The next value is to and then to print. 101 00:07:32,580 --> 00:07:35,220 The next value is three and so on and so forth. 102 00:07:35,940 --> 00:07:36,480 Awesome. 103 00:07:36,630 --> 00:07:41,310 So now that it's clear, let's go for our first loop. 104 00:07:41,340 --> 00:07:41,710 OK. 105 00:07:41,730 --> 00:07:47,500 So for I equals to one as long as I is less than or equal to m i plus plus. 106 00:07:47,550 --> 00:07:50,050 So that basically says let's go. 107 00:07:50,100 --> 00:07:50,590 OK. 108 00:07:50,610 --> 00:07:57,240 And that says let's go over all the rows starting from row one and up to the final row. 109 00:07:57,250 --> 00:08:06,690 So read E to read over all of the rows. 110 00:08:07,420 --> 00:08:08,490 OK, awesome. 111 00:08:09,270 --> 00:08:16,530 And while iterating over all of the rows, ok, let's say that this will be the section that we executed. 112 00:08:16,950 --> 00:08:20,340 We know that I equals to one right. 113 00:08:20,340 --> 00:08:21,660 I equals to one. 114 00:08:22,110 --> 00:08:26,280 And we will say that four K equals two blank spaces. 115 00:08:26,460 --> 00:08:33,150 OK, the number of blank spaces that should be printed as long as K is greater or equal to one K minus 116 00:08:33,150 --> 00:08:36,220 minus and simply print a blank space. 117 00:08:36,240 --> 00:08:41,460 OK, so for equals to zero we know that blank spaces equals to two. 118 00:08:41,790 --> 00:08:42,230 Right. 119 00:08:42,280 --> 00:08:43,230 It's, it will be. 120 00:08:43,230 --> 00:08:48,180 For example, if we got in equals to three then it will be two. 121 00:08:48,180 --> 00:08:54,570 So we will print spaces like the first space, the second space and that's it. 122 00:08:54,750 --> 00:08:57,490 OK, so K equals two two. 123 00:08:57,960 --> 00:09:06,180 And as long as K is greater or equal to one, we will print it so close to two, then close to one. 124 00:09:06,180 --> 00:09:08,830 And then when key goes to zero, we are out of it. 125 00:09:08,850 --> 00:09:16,650 So basically we printed two blank spaces to the screen and once we are done printing that, let's simply 126 00:09:16,650 --> 00:09:19,480 understand what we are doing in the following line. 127 00:09:20,340 --> 00:09:22,080 So what's going on here? 128 00:09:22,410 --> 00:09:25,050 Um, let's first of all, just fix that. 129 00:09:25,050 --> 00:09:28,300 I think that, well, everything is removed. 130 00:09:28,320 --> 00:09:29,460 No, everything is OK. 131 00:09:29,680 --> 00:09:32,550 So, yeah, let's just fix that. 132 00:09:32,580 --> 00:09:34,690 So there you go. 133 00:09:34,710 --> 00:09:39,600 So it will be like G plus and that's it. 134 00:09:40,470 --> 00:09:40,560 OK. 135 00:09:40,680 --> 00:09:42,740 So there was some mistake probably. 136 00:09:43,110 --> 00:09:44,430 And yeah. 137 00:09:44,430 --> 00:09:47,870 OK, now we are set. 138 00:09:48,090 --> 00:09:57,330 So let's come back to our drawing process and also let's now talk about this one. 139 00:09:57,360 --> 00:09:58,250 OK, this loop. 140 00:09:58,620 --> 00:09:59,820 So all of that. 141 00:09:59,960 --> 00:10:07,190 Both of these loops happen inside of the outer loop, so we printed all the bases, so this loop is 142 00:10:07,190 --> 00:10:08,720 actually two ways. 143 00:10:08,720 --> 00:10:09,830 It's so big. 144 00:10:10,460 --> 00:10:14,780 Wait a sec and wait a second. 145 00:10:14,780 --> 00:10:15,740 Wait a second. 146 00:10:16,460 --> 00:10:18,040 Wait a second, guys. 147 00:10:18,050 --> 00:10:19,170 I'm sorry for that. 148 00:10:19,280 --> 00:10:21,030 So is this OK? 149 00:10:21,060 --> 00:10:21,440 Yeah. 150 00:10:21,450 --> 00:10:21,860 Awesome. 151 00:10:22,130 --> 00:10:22,460 So. 152 00:10:24,400 --> 00:10:30,940 Basically, we said that this loop is simply in charge, in charge of what? 153 00:10:30,940 --> 00:10:34,670 In charge of printing the blank spaces before. 154 00:10:34,690 --> 00:10:37,690 So printing blank spaces. 155 00:10:37,870 --> 00:10:39,970 Right, blank spaces. 156 00:10:41,450 --> 00:10:50,390 So that's the task of these for loop printing of a blank spaces before printing the values of each of 157 00:10:50,390 --> 00:10:51,380 these given row. 158 00:10:52,010 --> 00:10:58,060 And later on, we are in these for a loop and these for a loop simply prints the current value. 159 00:10:58,070 --> 00:11:03,250 So the current value is now one and we simply print the value of one to the screen. 160 00:11:03,590 --> 00:11:08,450 And we do that as long as J is less than or equal to I. 161 00:11:08,750 --> 00:11:11,140 So we are doing that. 162 00:11:11,400 --> 00:11:13,390 We know that equals to one. 163 00:11:13,400 --> 00:11:16,600 Then we know that only one value should be printed to the screen. 164 00:11:16,940 --> 00:11:23,690 And if I equals to two, then in this case we should print two values to the screen and so on and so 165 00:11:23,690 --> 00:11:24,080 forth. 166 00:11:24,080 --> 00:11:30,470 OK, and at the end of every duration we increment the current value by one because we know that we 167 00:11:30,470 --> 00:11:36,440 want to like to keep it up and to print every every, every time another value. 168 00:11:36,630 --> 00:11:37,100 Awesome. 169 00:11:37,910 --> 00:11:45,760 So now let's also see how it can be done in the second loop where I equals to two in the second iteration. 170 00:11:46,040 --> 00:11:53,050 So we print just one space, OK, we print just one space and then we print two values. 171 00:11:53,060 --> 00:11:56,960 So it will be two space and three. 172 00:11:57,200 --> 00:11:58,370 OK, just like that. 173 00:11:59,250 --> 00:12:01,430 And finally it equals to three. 174 00:12:01,700 --> 00:12:03,860 We will not print any spaces at all. 175 00:12:04,040 --> 00:12:06,260 It will be just something like this. 176 00:12:06,860 --> 00:12:09,470 So it will be four. 177 00:12:09,890 --> 00:12:13,100 Space five, space six. 178 00:12:13,610 --> 00:12:22,580 OK, so that's basically how it looks like every time at the end of the outer iteration we simply use 179 00:12:22,610 --> 00:12:29,510 these print off-line, OK, to print a new line and blank spaces minus minus, just to say that in the 180 00:12:29,510 --> 00:12:37,940 next iteration you have to print one blank space last before printing the values themselves. 181 00:12:38,240 --> 00:12:40,490 OK, so awesome. 182 00:12:40,500 --> 00:12:43,010 I think that we cover it up everything. 183 00:12:43,040 --> 00:12:47,480 So these for a loop basically let's say even like that. 184 00:12:47,840 --> 00:12:50,090 So this should be here. 185 00:12:51,860 --> 00:12:52,880 It should be here. 186 00:12:53,300 --> 00:12:54,190 That should be here. 187 00:12:54,590 --> 00:13:01,500 So we said that once again the blank spaces is OK, the return of zero is OK. 188 00:13:01,990 --> 00:13:05,060 Oh it's just like OK, awesome. 189 00:13:05,110 --> 00:13:08,420 So yeah, I think this is it for this video. 190 00:13:08,930 --> 00:13:11,810 Let's just build and run in to see that everything works correctly. 191 00:13:11,990 --> 00:13:14,510 And as we expected, let's go to three. 192 00:13:14,810 --> 00:13:16,880 So one, two, three, four, five, six. 193 00:13:17,240 --> 00:13:22,670 And also let's go with four, for example, one, two, three, four, five, six, seven, eight, 194 00:13:22,880 --> 00:13:25,940 nine, 10 Hossam guys. 195 00:13:25,950 --> 00:13:27,920 So that's the solution for these video. 196 00:13:28,190 --> 00:13:30,830 If you still have any questions, feel free to ask them. 197 00:13:31,550 --> 00:13:37,070 And basically, just to summarize, all that we've done here is simply splitting up the full solution 198 00:13:37,070 --> 00:13:43,880 to parts of the solution, like using the for loops and using the inner for loops and the other for 199 00:13:43,880 --> 00:13:50,180 loops and explaining exactly what each of these parts mean and what it will be used for. 200 00:13:50,750 --> 00:13:51,890 And yeah. 201 00:13:52,160 --> 00:13:54,770 So let me know if you like this video. 202 00:13:54,770 --> 00:14:01,460 Please leave some review and some feedback and of course, keep on practicing and we will meet up in 203 00:14:01,460 --> 00:14:03,320 the next exercise. 204 00:14:03,950 --> 00:14:06,500 So until then, have a great day. 18604

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.