Тёмный

Puzzles & Programming Problems (Think Like a Programmer) 

V. Anton Spraul
Подписаться 30 тыс.
Просмотров 292 тыс.
50% 1

This episode introduces the idea that problem solving is essentially the same no matter what problem we're trying to solve, and looks at the connection between puzzles and solving programming Your comments and suggestions for future videos are welcome.
"Think Like a Programmer" is a book I've written to help programmers with problem solving. If you've found that you are able to read programs and understand programming language syntax but aren't always confident writing programs from scratch, my book can help.
For more information on the book head to one of these:
Amazon page for the book: amzn.to/1MZlmlY
My site: www.vantonsprau...
My publisher's site: nostarch.com/th...
Connect with me:
My site: vantonspraul.com
Twitter: / vantonspraul
Facebook: / thinklikeaprogproblems .

Опубликовано:

 

21 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 524   
@vantonspraul
@vantonspraul 7 лет назад
Inspired by the talk in this comment section of this video, I've created a new video about performance and efficiency. I discuss what the terms mean, why we should care about this, and why we sometimes shouldn't. Check it out here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Xs-lY15vEec.html
@JiveDadson
@JiveDadson 6 лет назад
Here's more inspiration: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-YnWhqhNdYyk.html
@abelcasey9416
@abelcasey9416 3 года назад
Sorry to be so off topic but does anybody know of a way to log back into an instagram account?? I was stupid forgot the account password. I love any tricks you can offer me
@vibingcat9541
@vibingcat9541 2 года назад
@@abelcasey9416 no
@ieshamusgrove7883
@ieshamusgrove7883 6 лет назад
This comment section reminds me of something a senior programmer once told me. He said that there is a world of difference between the attitude of an inexperienced vs experienced programmers(with mid-level being the worst). Senior developers are much more nurturing and understanding while inexperienced developers have a tendency to berate others for mistakes/shortcomings/lack of knowledge. Most here didn't understand the point of the first problem and the lesson he was trying to convey. People just wanted to make themselves look smart while in reality looking very cringey.
@B1TruthBeTold1
@B1TruthBeTold1 5 лет назад
I agree
@sush2142
@sush2142 5 лет назад
Perfect
@forestmanification
@forestmanification 5 лет назад
Mid level represent! I thought of the if() solution as the easiest, least sophisticated solution which will 100% work right off the bat. The problem when you are so good at problem solving such as me, is that everyone start depending on you and you prevent them from developing their own problem solving skills. I curse the stars that made me so smart with bitter sorrow...
@cheems08213
@cheems08213 5 лет назад
I agree.
@iansalsich6508
@iansalsich6508 3 года назад
@@forestmanification hahahah
@ss-oq9pc
@ss-oq9pc 7 лет назад
One thing that's helped me a lot is whenever you see a 'for' loop or need one, instantly fill it in, in your mind, with 'for each'.
@charlesbaldo
@charlesbaldo 7 лет назад
I have been programming for 35 years. It is always good to go back to basics and review logic. It is like excercising your brain. Especially when you are learning a new language. Good video series
@systemvoid287
@systemvoid287 8 лет назад
I have 8 years of programming experience, but this is a great video. I actually benefited from this.
@vantonspraul
@vantonspraul 8 лет назад
+System Void Cool!
@ibrahimgreab8423
@ibrahimgreab8423 8 лет назад
hey man can i have your Facebook account or email
@vantonspraul
@vantonspraul 8 лет назад
+ibrahim greab Not sure who you meant to reply to...but if you meant me, I'm at facebook.com/vanton.spraul, plus you can contact me from my site at vantonspraul.com/contact.
@ibrahimgreab8423
@ibrahimgreab8423 8 лет назад
+V. Anton Spraul okay man thanks to you I need advice from an expert programmer
@systemvoid287
@systemvoid287 8 лет назад
Nobody ever said it was hard.
@ruskodudesko9679
@ruskodudesko9679 8 лет назад
my first course in my computer science education was just on how to think like this our professor was a master problem solver and sometimes would show off but it was good to see what we could eventually accomplish at first we didnt like it but he showed us the importance of solving the problem on paper before you even type any code out and it has helped tremensdously in the coding courses
@verseve
@verseve 7 лет назад
im a recent grad in programming. and i completely failed my first interview. this video helped me so much! i learned so much cause i am one of those over thinkers that writes complicated code making problem solutions more complicated than they have to be.
@fmaylinch
@fmaylinch Год назад
I think that for problem solving it's also very important to know what actions you can do. For example, in the water problem you can pour from one container to the other. In programming you also need to know what instructions you can do, what commands are available, what APIs you can call, and in general what components/pieces/actions are involved/possible in the problem.
@vantonspraul
@vantonspraul Год назад
Yes! In the book, I use the example of the fox, goose, and corn puzzle, which has the same issue. If you define your available actions as, "the boat can take the farmer and one item from the west side of the river to the east side," the problem isn't solvable. If you define the actions as, "I have a boat that can travel from one side of the river to the other, and at either end I can embark or disembark so long as I am only carrying one item at a time," the problem is solvable.
@vantonspraul
@vantonspraul 11 лет назад
Glad you are enjoying the book. I've got some good puzzles worked out for upcoming videos. Coming soon!
@FrenzyT0004
@FrenzyT0004 7 лет назад
I was so proud of myself when I heard the solution for the permutation problem's solution.... Thank you, this is what I and many other programming learners need.
@cvsshred7
@cvsshred7 8 лет назад
Who solved the watter puzzle imidiatly if you do thumbs up
@Walleggwp
@Walleggwp 8 лет назад
+Carlon van spijker Pretty easy, tbh.
@onofreisk8
@onofreisk8 8 лет назад
+Carlon van spijker as the 2nd container appeared on the screen !
@aidanmartin1860
@aidanmartin1860 8 лет назад
+Carlon van spijker I thought he was joking about it being difficult.
@connor43057
@connor43057 8 лет назад
lmao yeah I solved in under 10 seconds...
@saptarshisahoo5075
@saptarshisahoo5075 8 лет назад
+Carlon van spijker Man both the probs were pieces of cake.
@therealapollo6452
@therealapollo6452 7 лет назад
The "lesson" or message from this video means you should approach problems for a different angle and interpret it differently. It was not meant to be a video on how to write efficient code. Dont start comment wars please ^^
@Dawo0odz
@Dawo0odz 7 лет назад
I had started programming since 3 moths and I found the solution from the first time but I think that what you did in for loop is more more more interesting
@mxolisisilabela9803
@mxolisisilabela9803 4 года назад
My Professor has failed me twice in a TDD exam and when I asked what to do in order to pass his exam, he said I am not a programmer. Thank you for this Playlist. I can't wait for a retake!!!
@TheDeybith
@TheDeybith 8 лет назад
Thank you for the information, it's a great video. I am learning to program with Python. I consider myself a beginner in programming. Even though, I solved that problem (without looking at the answer) in 5 lines! Now I really understand why so many people prefer Python...
@harito16
@harito16 5 лет назад
Thank you for the video, it helped me get a clearer picture of how programming needs to be approached. I bought your book and I am going to start reading it RIGHT NOW!
@llucllumador380
@llucllumador380 7 лет назад
I just recently started to study programming. I'm a very beginner. As you suggested I paused the video and tried to make the department number program. I came up with a solution: I did the same 3 loops you did for your 0-10 permutations: for (int fire=1;fire
@gabecoelho647
@gabecoelho647 6 лет назад
This is GREAT. Thank you!
@vantonspraul
@vantonspraul 6 лет назад
You're welcome!
@ripndipp
@ripndipp 4 года назад
Oh boy did that department problem make my heart skip and beat. I'm watching this to improve my problem solving skills in JavaScript. I am coming from a medical background with JS bring my first language.
@nitiKT
@nitiKT 7 лет назад
Thank you for the video, I am a struggling software engineer who is trying to crack white board interviews and failing miserably. Looking at your videos make me realize that my thinking is right.. I should just fine tune the way I think and believe more in my abilities.
@richdadsummit7557
@richdadsummit7557 5 лет назад
Never programmed before but my first thought was to output all permutations, but them I figured maybe it wasn't allowed, then it turned out to be the solution. Maybe this programming thing will work out for me after all. This video will still be very helpful for me, as other problems have tripped me up in the past.
@blackicelyriclyamazin7599
@blackicelyriclyamazin7599 9 лет назад
Im a programmer and I solved both puzzles. I did the second one in java just to test it. These were really nice. I remember when I had to write a piece of code that displayed all prime numbers in an interval without using the modulus operator. Its rather easy but back then I was just starting to code. It was frustrating but once i figured it out I felt so special. LOL
@vantonspraul
@vantonspraul 9 лет назад
I define "original" code as "original for the programmer writing it." Figuring out a problem on your own should make you feel good, even if you know many have solved it before.
@PvblivsAelivs
@PvblivsAelivs 8 лет назад
That's funny. My mind jumped to generating all permutations and having an IsValid function while you were describing the problem. But I might include looping the "police" number by 2 and determining the "sanitation" number as forced by the other two as refinements to make the program faster. The most important part is always getting the code to work.
@rcoservicerapporter6257
@rcoservicerapporter6257 Год назад
The most important part is writing as many lines as possible for the same thing so the company can get paid per line.. So always do: var one = 1 var two = 2 print(one + two)
@hiota45
@hiota45 8 лет назад
This would be a situation where you could avoid brute forcing by just thinking of all possible number triples. If the PD has to have an even number between 1 and 7, it has to have either 2, 4, or 6. Whatever number it takes, the other two have to have two different numbers that are the difference between it and 12, which result in rather few possibilities. Below is a quick javascript solution. //in each sub array the 0th is the PD, 1st is FD, and 2nd is SD. var permutations = [[2,6,4], [2,7,3], [4,7,1], [4,6,2], [4,5,3], [6,5,1], [6,4,2]]; /*because the above are just all possible number triplets, not all possible permutations... we need to account for the possible permutations of the above triplets fortunately, this just means switching the FD and SD numbers, because the PD's number has to be fixed. This can be done with a for loop, and we'll just tack the results on to our array.*/ for(var i = 0; i
@TheNightFreaks
@TheNightFreaks 5 лет назад
Thanks for giving me the illusion of being a genius by solving this right away. Now let me get back to bagging groceries.
@Xblade45
@Xblade45 8 лет назад
Thank you Anton! Im looking forward to buy your book! This is really great tips you give.
@vantonspraul
@vantonspraul 8 лет назад
+Xblade45 Thanks! I think you'll like the book as well.
@makodoseznamcz
@makodoseznamcz 8 лет назад
Love this series ...it really gets my brain working as it should got all the problems in few seconds Thanks for making this
@peterbezak5204
@peterbezak5204 6 лет назад
Wohoo! I figured it out in like 5 seconds! Never heard of it before btw.
@sagarkapasi099
@sagarkapasi099 7 лет назад
i love this content so much no other channel does this thanks
@FernandoTheBeast28
@FernandoTheBeast28 10 лет назад
For the cup scenario, it only took me like 5 seconds. I feel soooo special right now.
@player95
@player95 8 лет назад
when u showed problem i paused video..opened turboC++ and started codding took approx. 20 min to solve it .. i used 3 vari. ...police vari was an array with all possible even numbers and then i put 3 for loops to travel all possible sequences ..finally in the center i put if condition like (all vari should equal and sum==12).. gave multiple solutions on console..! tx 4 brainteaser :D ...
@meunomejaestavaemuso
@meunomejaestavaemuso 8 лет назад
+Rushikesh Raskar I did the same, but instead I did it in python. Took me less than 5 minutes o.o for f in range(1, 8): for p in range(2, 8, 2): # police is even, we start at 2 and skip even for s in range(1, 8): if f != p and p != s and s != f and f + p + s == 12: print f, p, s
@player95
@player95 8 лет назад
+Fernando Santos cool ...!
@player95
@player95 8 лет назад
+Fernando Santos I used different methods .like I try to use just one for loop ...stuck at various points ...then came up with that array idea ...
@samguard8419
@samguard8419 8 лет назад
I made the it in small basic and the total outcomes were 14, although that wasn't the problem: For p = 2 To 6 For f = 1 To 7 For s = 1 To 7 If p + s + f = 12 And (p/2)-Math.Round(p/2) = 0 and p f And f s And p s Then TextWindow.WriteLine("police "+p) TextWindow.WriteLine("fire "+f) TextWindow.WriteLine("Sanitation "+s) outComes = outComes + 1 EndIf EndFor EndFor EndFor TextWindow.WriteLine(outComes)
@blackpilledbuddha4944
@blackpilledbuddha4944 4 года назад
There are thousnds of tutorails on learning various languages and frameworks.... but this series , i dont even need to mention it... thank you
@Blackdiamond929_
@Blackdiamond929_ 2 месяца назад
Becoming a programmer is first recognising you have a great need for this type of thinking . It’s like my brain need to lift som weight before I can flex and solve these problems
@JenniferDawe
@JenniferDawe 10 лет назад
Wow, I've always been good at puzzles and riddles, but programming made me feel like I was a 2 year old trying to jam a square block in a round hole. I had no idea how to turn my solution into code without just doing it by rote. I've been working with programmers in software for over 10 years... I can come up with "code" in my head and when I explain it to programmers I work with they can make it work...but I couldn't do it myself and I really wanted to be better at that! Thank you so much for this, I will definitely be buying your book!
@vantonspraul
@vantonspraul 10 лет назад
Thanks! I hope my videos and book help. Believe me, lots of people with demonstrated smarts in solving problems in other areas are initially stonewalled when it comes to programming, so you're not alone. But if you enjoy programing and have a plan for developing your problem solving skill, the ability will come.
@Chng30FsCenEry
@Chng30FsCenEry 5 лет назад
Finally, a video that answers the real challenge of programming.
@nameStringEmpty
@nameStringEmpty 8 лет назад
Saw the puzzle for fist time and solved it almost immediately. I think 90% CAN solve it not a few!
@joel9909
@joel9909 5 лет назад
I am thinking like a programmer already. Got the water challenge at first glance. Maybe its cos i studied science at school, and did this whenever i did not have the right measuring beaker....... But the second problem. That requires serious programming. Thanks Anton
@mishaerementchouk
@mishaerementchouk 3 года назад
These are cute little problems illustrating a whole bunch of important points. The measuring problem is fun to follow with an “exercise”: solve the same problem but with a 6 oz instead of 5 oz. The modified problem looks similar but has no solutions (see Diophantine equations). Thus, it is important to distinguish a general case from a particular given situation. Hence, there may be the need for finding out, if we’re in a good or bad situation. The enumeration problem brings about many contexts: from the 3-partition problem, to various linear and nonlinear programs. An important lesson: don’t fall into the trap of premature optimization. What if the next year another departments, say, building and finance, are added. And the whole enumeration thing must be done in literals (county started to comply with state’s recommendations) but no combination of chosen literals may contain a reserved word with the list of the words provided. Good video!
@ixuz07
@ixuz07 8 лет назад
I solved the first puzzle in a few seconds, but once you started emphasize the difficulty I had to go back and ensure I understood the problem correctly. My first solution was the right one. The second puzzle was quickly solved too. I'm a programmer.
@musaddiqali1
@musaddiqali1 3 года назад
My program using Python: def main(): for fir in range(1, 8): for pol in range(2, 8, 2): for san in range(1, 8): if fir != pol and pol != san and fir != san and (fir + pol + san == 12): print(f"Fire: {fir} - Police: {pol} - Sanitation: {san}") return 0 main() Not the best-optimized code, but it just works with 14 permutations as the result.
@10tmccarthy
@10tmccarthy 8 лет назад
this is saving my life right now thank you!!
@vantonspraul
@vantonspraul 8 лет назад
+Tom McCar Glad I could help!
@FourDotSkills
@FourDotSkills 4 года назад
My take away is "Take a holistic view of the problem first and keep all options open" and avoid confirmation bias as well
@alby7153
@alby7153 5 лет назад
Sir , please continue this.This is really helpful
@mehboobfazal
@mehboobfazal 7 лет назад
start with this: , then in another loops for other dept. skip that policeNum to reduce iteration count
@jaynjb7812
@jaynjb7812 8 лет назад
These videos are a great compliment to the book. I am very happy with my purchase. Thanks V. Anton Spraul.
@arantebw
@arantebw 8 лет назад
V. Anton Spraul, thank you!
@vantonspraul
@vantonspraul 8 лет назад
+Billy Wilson Arante You're welcome! Thanks for watching.
@xeno126
@xeno126 8 лет назад
Damn that's probably the least optimal solution! Try checking the necessary conditions at each loop and break if they are not met.
@terencekreft482
@terencekreft482 8 лет назад
Yes, but as a programmer you get a working solution and then optimise. My first technical directors mantra was KISS (Keep It Simple Stupid). It works as a principle for getting the right code, and for writing maintainable code.
@joshuaentwistle960
@joshuaentwistle960 8 лет назад
Red - Green - Refactor; Know what should happen, make it happen, make it better, repeat.
@jon8796
@jon8796 7 лет назад
New to programming here. Care to write down example in pseudo code. Thanks
@1Mirar1
@1Mirar1 7 лет назад
You negate the condition (what do we do if it is not the case) and break. Example in the inner most loop: if ( fireDeptNum == policeDeptNum) break; //... if( policeDeptNum % 2 != 0) break; // Iff we get this far we know all conditions were met therefore std::cout
@brainstorm9372
@brainstorm9372 7 лет назад
int N = 7; // which number can we use aka range from 1 to N int maxSum = 12; // what is the sum of all three numbers we need for ( int fireDep = 1; fireDep = maxSum ) // If the sum of the first two numbers exceeds maxSum -> break (all sums that follow will be greater than maxSum) break; int sanDep = maxSum - fireDep - polDep; if ( sanDep == fireDep || sanDep == polDep ) // If the third number equals one of the first two numbers -> continue continue; // Output the permutations that coresponds to all three rules std :: cout
@tommyeagen3763
@tommyeagen3763 4 года назад
Currently, eating the book it's an amazing book I have a bachelor's degree in computer science and informal system but your book is super awesome 🌟
@Mareritt
@Mareritt 8 лет назад
It was actually pretty simple. I just did the main loop with the police department at 2, 4 and 6, then I nested two more loops for the fire and sanitation departments. In the second nested loop, I checked to see if both the total equaled 12 and if the fire and sanitation departments didn't equal each other - you don't have to worry about either one being equal to the police department. Then displayed all those that passed the if statement. Mind you, I haven't watched what his solution is yet so I'm not sure what he did in the video to solve the problem.
@Mareritt
@Mareritt 8 лет назад
+Mareritt Here's the code if anyone's curious. int nTotal = 12; // needed total for ( int pDept = 2; pDept < 7; pDept += 2) // pDept = police department { for( int fDept = 1; fDept < 8; fDept++) // fDept = fire department { for ( int sDept = 1; sDept < 8; sDept++) // sDept = sanitation department { int dTotal = pDept + fDept + sDept; // dTotal = department total if ((nTotal == dTotal) && (fDept != sDept)) { std::cout
@ikirstenHD
@ikirstenHD 8 лет назад
Been programming for a little lest that 6 months. I did it my own way(little longer than your code) and these where the results: 1-5-6 1-7-4 2-4-6 2-6-4 3-5-4 3-7-2 4-2-6 4-6-2 5-1-6 5-3-4 6-2-4 6-4-2 7-1-4 7-3-2 Oh and I remember the water question, our lecturer gave us that on the first day of class. I never figured it out. Six months latter this video shows up on my homepage and instantly figured out the question when I saw it LOL
@JasonLayton
@JasonLayton 3 года назад
So pumped that I was able to solve the last one! Thanks!
@MrStefaneko
@MrStefaneko 7 лет назад
Those were not permutations, but variations. Permutations are something different, like if you have 3 peedifined digits, you can form 3! = 6 different numbers out of them (if you must use all of them exactly once). If you can use any digit and you can use it more than once, then you can form 10^n (in our case 10^3 = 1000) numbers. That is called the variations.
@them4309
@them4309 5 лет назад
he explained the difference between permutations and combinations and he was right. the algorithm *tests every permutation and prints only the valid ones.
@edgarsanmartinjr.4278
@edgarsanmartinjr.4278 4 года назад
The first problem was so simple, i can’t believe I didn’t get it immediately lolol I had identified that the difference between the two cups was exactly what was needed so I had thought just fill an empty 3oz cup with the 5oz cup over a pan, and the spilt over water should be collected which should equal 2oz
@joediertay2434
@joediertay2434 7 лет назад
I totally had the wrong idea with the measuring cup problem lmao. I though "well if you fill up both measuring cups to the max, place the 5 oz cup inside a bowl, and pour the 3 oz into the 5 oz: the displaced water will be exactly 2 oz"
@emptyFull123
@emptyFull123 4 года назад
I've written last permutuation problem in different approach in python. Please check anyone if I'm right or wrong. Please correct if i'm wrong :) for police in range(2,7,2): for fire in range(1, 8): for sanitation in range(1, 8): if police + fire + sanitation == 12: print(police, fire, sanitation) Here, police should be in even so initially I've looped from 2 to 6 in interval of 2, (So i don't need to worry about even number of police) within that loop I ran another for loop for fire, and within those both loops I ran another for loop for sanitation, and at last I'm printing only those values whose sum is equal to 12 Total permutuations: (Police, fire, sanitation) 2 3 7 2 4 6 2 5 5 2 6 4 2 7 3 4 1 7 4 2 6 4 3 5 4 4 4 4 5 3 4 6 2 4 7 1 6 1 5 6 2 4 6 3 3 6 4 2 6 5 1
@musaddiqali1
@musaddiqali1 3 года назад
All the permutations are valid except 2 5 5, 4 4 4, 6 3 3.
@AttestedFire66
@AttestedFire66 7 лет назад
It's 5am and I haven't slept but the water puzzle was easy as shit. Instantly got it.
@yukimori2104
@yukimori2104 6 лет назад
Maybe the first problem with the two cups is considered difficult, because the first example shows that both cups are already filled. If only the 5 oz. cup were filled, and the 3 oz. is shown as being empty, more people should instantly arrive at the solution: 1: 5-3 = 2 2: Pour water from 5 oz. to 3 oz. cup 3: Leaving 2 oz. of water in the 5 oz. cup Also the second example in which the problem is restated, for some people it ends up being difficult. They would remain being unable to see that pouring fluid from the 5 oz cup into a filled 3 oz cup to arrive at 2 oz remaining in the 5 oz. cup. The reason is that, when given a problem such like this, people tend to think that they aren't allowed to empty one cup, or pour liquid from one into the other. Specifically when there is no mention that such things are allowed in the problem description people wouldn't even consider doing it. Which makes an utmost simple problem a big thing. Would the description say, or the problem be given as: "You have a 5 oz. cup filled with water, you have an empty 3 oz. cup. You wish to measure exactly 2 oz. How are you going to do it?" instead of showing an additional example where both cups will be filled? It is simple maths that 5-3 is 2. And if one 5 oz. cup is filled, the other left empty, and you wish to arrive at 2, there is only one simple way to get there. ;-)
@KoshNaranick
@KoshNaranick 3 года назад
Just bought the book.. hope that being from 2012 that it still works.. not for C++ but for understanding the mind set
@greyskull6548
@greyskull6548 8 лет назад
okay! thanks for ideas but that water puzzle was common for me and once again thanks a lot Hope you will share more puzzle coming days
@alexandrenarolles7994
@alexandrenarolles7994 Год назад
very instructive! I do really benefit from it!
@andressuarez3079
@andressuarez3079 5 лет назад
That was a great approach. Thank you very much.
@ultort
@ultort 8 лет назад
I think there is something wrong with the puzzle, the aim is not to get 2oz (seriously there is nothing to think about). The puzzle is to get 4oz with 5oz and 3oz. Much less straight forward. Here is the answer: fill 5 fill 3 with 5 => 2 left in 5 empty 3 => 0 left in 3 put the 2 left from 5 in 3 => 2 in 3 fill 5 => 5 in 5 fill 3 with 5 => 4 in 5
@ThePimp4dawin
@ThePimp4dawin 7 лет назад
tbh that was still just as easy.
@fatalsg92
@fatalsg92 6 лет назад
or you could just fill another 3rd empty cup with the 2oz water left from the 5oz cup and repeat the process. (the rules did not say that there "should" only be 2 cups, so I added another variable.)
@purpletonkadog
@purpletonkadog 5 лет назад
if 5 = 4 stop loop fill 3 and pour in 5 if 5 = 5, empty 5 and fill with 3
@shubhamdeshkar1685
@shubhamdeshkar1685 5 лет назад
That was not the point of this video,
@vibsh625
@vibsh625 5 лет назад
@@shubhamdeshkar1685 Rules didn't say that you need to comment according to the point of the video.
@charlesbrown2782
@charlesbrown2782 6 лет назад
I assumed both jars were filled. I poured half of the water out of the 3oz jar leaving only 1.5oz. I then fill the 3oz jar back to 3oz from the 5oz jar of water leaving 3.5oz of water in the 5oz jar. I repeat the process again and that leaves me with 2oz of water in the 5oz jar and 3oz of water in the 3oz jar. This all works if I'm allowed to eyeball what I think to believe is half of the water left in the 3oz jar. But eyeballing half is pretty close in general, so I believe this should work. But if I knew only the 5oz was full and the 3oz jar was empty that would have been a no brainer addition and subtraction problem.
@fatimahatef7175
@fatimahatef7175 2 года назад
This video is very helpful and in the same time exciting 👍🏻
@vantonspraul
@vantonspraul 11 лет назад
Thanks for the comment. Problem solving develops with practice, like any other skill. My book has lots of exercises to work through. If you can't get your hands on it, my next video may give you some ideas on developing your own exercises.
@christophbuhler4513
@christophbuhler4513 8 лет назад
I would recommend to delimit your dataset. It is not only (way) faster, it makes the code more readable and allows you to actually solve complex problems. Programming is not about adding valid data; It's about subtracting invalid data. The code in this video (10:40) smells. JS approach: for (var i=1; i
@terencekreft482
@terencekreft482 8 лет назад
No, programming is primarily about getting the right answer.
@terencekreft482
@terencekreft482 8 лет назад
No, programming is primarily about getting the right answer.
@KingButcher
@KingButcher 8 лет назад
python approach :) for x in range(1,8): for y in range(1,8): for z in range(1,8): #If even number if z % 2 == 0: #If there aren't any duplicates if len(list(set([x,y,z]))) == 3: #If all add to 12 if x + y + z == 12: print "Police: {0} Fire: {1} Sanitation: {2}".format(z,y,x)
@soupra777
@soupra777 8 лет назад
+King Butcher Is your program producing 10 permutations? I got 14. I noticed in your program if police == 2 then fire/sanitation is (4, 6). But they can also be (3, 7)
@KingButcher
@KingButcher 8 лет назад
+ansquad0 ohh, its because the "range" function returns a list starting with 0. So I would have to do; *for _ in range(1,8)* instead. Ive fixed the mistake. Thanks for the correction :)
@heathergray4880
@heathergray4880 6 лет назад
My solution in Python 3 for the problem. It comes back with a solution of 17 permutations: num_list = [] for fire in range(1, 8): for police in range(2, 8, 2): for sani in range(1, 8): if fire + police + sani == 12: num_list.append((fire, police, sani)) print(len(num_list))
@sankeethganeswaran3024
@sankeethganeswaran3024 5 лет назад
the answer should be 14
@christophbuhler4513
@christophbuhler4513 8 лет назад
The riddle (10:40) would have been more interesting, if the police dept (i) only wanted odd numbers. You wouldn't have to check, whether the fire / sani dept have the same number, because the sum (12) minus any odd number (i) would always result in an odd number, that cannot consist of two times the same number. for (var i=1; i
@ArronSealmoyGuitar
@ArronSealmoyGuitar 5 лет назад
Your book is a life saver
@codykostyak3890
@codykostyak3890 9 лет назад
my thoughts on the water puzzle was to pour the two full containers into an unmarked container, then scoop it out with the 3 ounce cup, and the remainder is 2... i was close :P
@tytydraco
@tytydraco 8 лет назад
Extremely helpful! Will consider buying your book :)
@PalmerPaul
@PalmerPaul 8 лет назад
One-liner in Python: print ' '.join(map(lambda x:'{} - {} - {}'.format(*x),filter(lambda x:(len(x)==len(set(x))and sum(x)==12 and not x[1]&1),((a,b,c)for a in range(1,8)for b in range(1,8)for c in range(1,8)))))
@haraldpost
@haraldpost 7 лет назад
Nice video, but very inefficient way of solving the task. Time complexity is O(n^3). You are doing 7*7*7 iterations. You can reduce number of iterations by 4/7th's if you put policeDeptNum % 2 == 0) in the outer loop... And since you know that (12 - policeDeptNum - fireDeptNum = sanitaryDeptNum) you don't need the third loop. I was able to find all 14 solutions doing no more than 27 iterations.
@cnorris1193
@cnorris1193 8 лет назад
And I start geeking out over ham and Swiss and Swiss and ham lmao
@lecillefreakwizon7582
@lecillefreakwizon7582 8 лет назад
a great help for a BSIT student like me..😁👍👍 thank you sirrr
@swethaanand3088
@swethaanand3088 5 лет назад
i need more of this... thanks a lot
@Stickimations
@Stickimations 11 лет назад
Great tutorial. I was really suprised at the simple solution to the last problem :) I am reading your book, loving it so far. You should do more tutorials on puzzles like the last one in the video!
@kenhaley4
@kenhaley4 7 лет назад
Speaking as a programmer with over 40 years of experience, I find it too bad that the final solution he came up with was the most inefficient--discarding some of the optimizations that he'd already discovered. For example, it would still be valid to calculate the sanitation number by subtracting the sum of the other two numbers from 12, thus eliminating the innter loop. It would also still be valid to force the police department to be even, as he did in the earlier attempt. Part of "thinking like a programmer" is not being satisfied with the first solution that works. It is often worthwhile to re-examine your solution to see how it can be optimized. If you're writing production code that might be used thousands and thousands of times, it's not only worthwhile, it's vitally important. And--don't casually discard your earlier thoughts--they may still have value.
@ss-oq9pc
@ss-oq9pc 7 лет назад
Any interest in making programming tutorial vids on youtube? lol.
@sixtycats8652
@sixtycats8652 6 лет назад
Lmao you said “final solution” Is this really the right place
@SceneTurkey
@SceneTurkey 7 лет назад
An if statement checking for the correct answer was the first thing I thought of because I like to debug incorrect answers by seeing why they are incorrect. It's kind of a faster way to do trial and error. Also, for the cup problem, you used the wrong number; you're supposed to make 4 ounces of water, not 2.
@LiteDev
@LiteDev 8 лет назад
The permutations of the Department numbers are as follows: 147. 165. 246. 264. 327. 345. 426. 462. 507. 543. 561. 624. 642. 705. 723. 741.
@PhoenixPho
@PhoenixPho 8 лет назад
+Zachary Blasczyk You included 0 for the second number.. It should be 1-7
@LiteDev
@LiteDev 8 лет назад
+Raiki I see that you are correct. I will rework the program when I get to a computer.
@LiteDev
@LiteDev 8 лет назад
+Raiki The permutations of the Department numbers are as follows: 147. 165. 246. 264. 327. 345. 426. 462. 543. 561. 624. 642. 723. 741.
@risaverc1217
@risaverc1217 2 года назад
I have no experience with Programming whatsoever so I have no idea how this would be executed however I thought for the Dept problem the police number would always be 2,4 or 6 for each of these the sum of the other two has to be either 10, 8 or 6 I wonder if a loop could be coded only for numbers to add to those quantities and be different from one another
@lukedeets5016
@lukedeets5016 4 года назад
Very helpful videos! Thank you!
@formulaintuition8756
@formulaintuition8756 6 лет назад
import itertools a = [x for x in range(1, 11)] permutations = itertools.permutations(a, 3) for p in permutations: if sum(p) == 12 and p[1] % 2 == 0: print(p) I did this, not sure if it's right
@ydela1961
@ydela1961 7 лет назад
Funny, I came up with something like: tot = 12; maxNum= 7; for (p = 2; p
@mhc4124
@mhc4124 7 лет назад
Programming comment threads and forums always remind me that fundamentalism is everywhere and that just because someone knows how to write code does not mean they understand what it means to be a scientist. I'm not a scientist, but I do think ethics and experimenting are more important than how smart you think you are. EDIT: My first solution was to simply count by twos and subtract 7 from the counter to get all permutations. Then I just looped through the result to find the one that satisfied the police chief's non-primacy law and the sum-to-twelve requirement.
@DjNerDee
@DjNerDee 8 лет назад
Here is what the program looks like written in Python 3 for i in range(7): if (i+1) % 2 == 0: #i will be Police so this is to check if the number is even, the +1 is due to the fact the loop starts at 0 for j in range(7): if j != i: # checking to make sure j isn't equal to i for k in range(7): if k != i and k != j: #checking to make sure k isn't equal to j or i if i + j + k + 3 == 12: #checking if the sum is equal to 12, again the +3 is due to the fact counting starts at 0 print(i + 1, j + 1, k + 1) #if everything passes print the numbers
@supetorus9612
@supetorus9612 8 лет назад
I did this in Python. I wrote it on paper first to figure it out then did it on the computer. I made a mistake that made it so 4 solutions were cut off because I accidentally didn't include 7 in my possible numbers. Other than that it worked on my second try. I think the way I did it might be slightly more optimized because it checks if the number is valid before it goes on to generating the next number so each preceding for loop has to run once less instead of having to run 399 loops. It only has to run 154 loops.
@gun123456zak
@gun123456zak 8 лет назад
+Supetorus in Python the solution is nothing but a simple one liner
@gun123456zak
@gun123456zak 8 лет назад
+Pyramid Head print [(f, p, s) for f in range(1, 8) for p in (2, 4, 6) for s in range(1, 8) if f != p and f != s and p != s and (f + p + s == 12)]
@beegieb4210
@beegieb4210 8 лет назад
+Pyramid Head Better yet: [(f, p, s) for f in range(1, 8) for p in (2, 4, 6) for s in range(1, 8) if len({f, p, s}) == 3 and f + p + s == 12] Or if you want to make it even shorter and memory efficient: r = range(1, 8); [(f, p, s) for f in r for p in r[1::2] for s in r if len({f, p, s}) == 3 and f + p + s == 12]
@umair-anwar
@umair-anwar 4 года назад
The Department Number Permutation can be solved with only one loop. O(n). Just try solving it by getting total number of permutations by 7 raise to power 3. You will figure out the rest yourself.
@brahmabull4004
@brahmabull4004 2 года назад
this makes no sense
@MakeWithData
@MakeWithData 8 лет назад
Simply statistics would help a lot with the generation algorithm. No repeating numbers means there are 7x6x5 possible arrangements, so that's your for loops right there. The rest is straightforward
@Alexander_Meyer
@Alexander_Meyer 8 лет назад
Great video, thank you very much!
@derekbrown5123
@derekbrown5123 9 лет назад
Ordered your book today!
@vantonspraul
@vantonspraul 9 лет назад
Cool, thanks!
@confuciouskomj.9061
@confuciouskomj.9061 8 лет назад
This is how i solved problem with getting 2 ounces of water: 5\2=2.5 and 2.5\2=1.25 than 3\2=1.5 and 1.5\2=0.75 the solution is 1.25+0.75= 2 I feel i little dumb however, when you shoved you approach it seemed so obvious that i asked myself how couldn't i see it?
@andrei-ionutgranat9321
@andrei-ionutgranat9321 3 года назад
Your solution is good, but it can get simple optimisation aka you could at least do the police departament to be even always and not generate the sanitary, just check if the sum is < 12 in wich cas us true the sanitary becomes the remaining part and then check the if they are different. Way faster( 2 less checks for each posible combination and not generating a third value and generating 3 police values instead of 4. Further optimisation is posible but imma not go into details.
@ervins3910
@ervins3910 9 лет назад
SO FUCKING AWESOME ! THANKS for the book and videos! That is what I were looking for all the time! Greets from Slovenia.
@vantonspraul
@vantonspraul 9 лет назад
+Ervin S YOU'RE VERY WELCOME! :-). Seriously, glad these have helped you out.
@EagleTrue
@EagleTrue 7 лет назад
Thanks man !
@BradenBest
@BradenBest 7 лет назад
Hi! I am an optimizing compiler. I will now parse your puzzle: "If you have a 5oz cup and a 3oz cup, how do you get 2oz of water?" Whoops! You have invoked undefined behavior. Guess it's up to me to re-interpret your question. As it's not specified whether or not the two cups are filled before I can begin solving the puzzle, I can assume it's impossible for the cups to transfer any water. Thus they must be immovable. As immovable objects are an impossibility, your cups must not exist, therefore, I can delete some text here and there, and optimize your puzzle to just: "You have 2oz of water." I will now attempt to answer this puzzle: If I have 2oz of water, then I have 2oz of water Answer: yes
@TheOrbitalDropShock
@TheOrbitalDropShock 8 лет назад
My solution whould've been. Loop police first. Then fire from 1 to (7 or police + fire = 11). Then sanitation = 12- (police + fire). With "then" I ofc mean that it's inside the previous loop mentioned.
@ImZenaan
@ImZenaan 8 лет назад
I solved the department program extremely quickly :D I love problems like this, make the computer do the generating and make it check it too, no need to manually check :P
Далее
The Blank Screen (Think Like a Programmer)
8:00
Просмотров 72 тыс.
Recursion (Think Like a Programmer)
10:42
Просмотров 156 тыс.
How to Install and Use an Adjustable TV Arm
00:18
Просмотров 2,4 млн
Problem-Solving for Developers - A Beginner's Guide
10:44
The size of your variables matters.
11:03
Просмотров 117 тыс.
Mindset of Successful Programmers
4:56
Просмотров 1 млн
How to THINK like a Programmer
11:11
Просмотров 138 тыс.