A Software Engineer Plays Human Resource Machine (Part 1)

Copy Help
  • Public/Private: Change the visibility of this video on your My Videos tab
  • Save/Unsave: Save/Unsave this video to/from your Saved Videos tab
  • Copy: Copy this video link to your system clipboard
  • Email: Copy this video link to your default email application
  • Remove: Remove this video from your My Videos or Saved Videos tab
search-icon
Watch at: 00:00 / 00:00:20welcome to asoftware engineer plays the youtubechannel wherea software engineer that's me playsthrough games that are designed to teachyou how to write some codejust looking at human resource machinesis going to be a multi-partseries let's uh dive right inWatch at: 00:20 / 00:40all right let's go ahead and get started[Music]level one of human resource machine themail roomyear oneit's our first day we got three numberscoming in we got foursix and oneWatch at: 00:40 / 01:00so so we're going to be building aprogram over here on the right sideWatch at: 01:00 / 01:20tell our worker to do things okay solet's uhgo to the inbox and then straight to theout boxlet's do it three times it looks like wegot three numbers so let'smove three boxes across let's seeWatch at: 01:20 / 01:40all right so far so good[Music]moving on up good stuffWatch at: 01:40 / 02:00okay level two a busy mayorall right it took us a year to do thatlast one rightwe're in year two now we've got somesec we got promoted everyoneWatch at: 02:00 / 02:20all right a new assignmentso we got a jump command now so we canjump around inside the programthere is aum there's a statement you can use insome programming languages called ago to statement which is similarWatch at: 02:20 / 02:40it's basicallybe like kind of like a loopin a way but a little bit less elegantso basically what this is gonna let medo is tell it where to jump to in theprogramWatch at: 02:40 / 03:00um so it says once i get toline three here we're gonna jump back tothe start of the programand go through it again so see kind oflike a loopin a way but it's not a formal loopstructureit's just um jumpingthe place in the code so go ahead andWatch at: 03:00 / 03:20run this you see we go to inboxoutbox and then we jump back tostep one so let's just go aheadand speed up our little man here thatseems to be workingWatch at: 03:20 / 03:40all right you getjump sequences in umthey're more low level programminglanguagesa lot of assembly languages that operateon the actualprocessing unit of your computer mightbe executing jump statements butWatch at: 03:40 / 04:00most higher level languageswould rather use loop structures like afor loop or a while loop to do that kindof operationall right floor three the coffee flooryear three let's see what we gotta dohereWatch at: 04:00 / 04:20oh no the inbox comparescompletely broken but that doesn't meanwe get to take a break from work allrightignore the inbox and just send thefollowing three letters to outboxb-u-g okay soWatch at: 04:20 / 04:40some items the carpet uhso we gotta figure out exactlyokay so we want to send b you g so itlooks like we're going to copyfrom looks like b's in slot 4so let's see if we can okay so what's itthere so we want to copy bWatch at: 04:40 / 05:00and then u we're going to be out boxfirstnow i would want to use a jump statementherebut if i do that you can see it's goingto try and copy from four every time andthere's not going to be anythingin four so we don't want to do thatWatch at: 05:00 / 05:20um instead i think we want tojust go like this i don't think there'sany way for us to change that parameteruh on the copy from command every timethroughso let's go ahead and get the gWatch at: 05:20 / 05:40and move that to the out boxlet's see how this works okay so we copyfrom band move it over there and then we go tothe zeroand go over there and then the ge u g all rightgood stuffWatch at: 05:40 / 06:00so it looks like this game's kind oftrying to emulate uma more of a low level assembly typelanguage with the the commands that it'shaving us execute um copy fromcopy to um would be kind of likeum what we call a register in assemblyWatch at: 06:00 / 06:20basically it's a bank that stores anumber so you can copyto this bank a certain number and thencopy from it anddo things like that and that's a morelow-levellow-level computing but like acomputer engineer might deal withWatch at: 06:20 / 06:40but software engineering usually dealsat a higher levelwriting code that's more easily readableby humanslet's jump into level four here thescrambler handlerokay so this is year fourokay the conveyor system has been fixedWatch at: 06:40 / 07:00it only took a yearwhat are we gonna do oh we gotta get towork the data won't collate itselfokay sowe got a swap basically so we want totake the three and the nineand then send the nine out firstand then the three so we wanna copyWatch at: 07:00 / 07:20these intoum our carpet area herewhich you can call it's kind of likememory in your computer i guessbut basically we want to pick up fromthe inbox i think pick up that threeand copy it to we'll copy it to slotzeroWatch at: 07:20 / 07:40then we want to go back to the inbox andcopy that to slot oneokay and nowum we want to send out the firstWatch at: 07:40 / 08:00[Music]itemor actually let's think about this wedon't actually need to storethe second item right if you think aboutit becausestoring it's just an extra step we couldsend that one straight there then pickup the one that we stored so let's getrid of this copy tooWatch at: 08:00 / 08:20and let's just move it straight to theoutbox thenwe should be able to copy from the spacethat we storedand move him straight to the outbox nowthat should work for the firsttwo and then becausethis code is reusable we should just beable to make it jump back to the startWatch at: 08:20 / 08:40and just execute all of these steps overand over again it'll pick up two andreverse them so let's see what happenshere so he's gonna store number threehe's gonna pick up the nine and move itstraight acrosshe's gonna pick up the three and placeitand then he's gonna continue looks likethe end's gonna overwrite the threeWatch at: 08:40 / 09:00there and move it acrosspick that up and we're gonna do the samething we're gonna store the one inmemory herepick up the nine move it across and thenpick up the onesobasically this is teaching you how toWatch at: 09:00 / 09:20swap two numbers and it's a prettycommon thing that you need to do inprogramming especially when it comes tosorting lists of thingsyou've got one item that's larger thananother and you want tosay sort things from smallest to largestif you're if your numberWatch at: 09:20 / 09:40if your first number is larger and thesecond number is smaller you want toswap them but what this is teaching youis that more often than not you need tohave a placeto store one of those numbers whileyou're doing your swap sothe traditional method for swappinguh in programming is to create a thirdWatch at: 09:40 / 10:00variable that we would call a temporaryvariable and we would set that variableequal tothe the value of the first number andthen we wouldset that variable equal to the secondand thenum we would use our temporary variabletoto write back to the to the secondWatch at: 10:00 / 10:20number umand maybe i'll do somebasic drawing and have that overlaid onthe screen here to helpexplain thatall right so just a little furtherexplanation on that swapping thereso basically i figured the best way todo this would be to show youWatch at: 10:20 / 10:40how code itself would actually look sowe'll start with a little functiondeclaration you don't really need toworry about what that means but we'regoing to declare a couple of what wecall variables these areinteger types so we've got a equal tofivefive's the blue circle here we've got bequal to ten bis the yellow circle down here so to doWatch at: 10:40 / 11:00a swap we might be tempted just to set aequal to b so we did that here right bwas equal to ten so now a equals tenbut now a is equal to tenand b is equal to ten so we've actuallylost the original value of awe have no way to know that a was 5Watch at: 11:00 / 11:20anymoreso it's not going to workso instead what i mentioned earlier waswe need to have athird variable so we'll start out likewe did before we'll declare aand b blue and yellow five and tenand i will do the swap we'll declarethis third variable called tempWatch at: 11:20 / 11:40it's an integer type temp we'll set itequal to a so temphere is equal to a which is equal tofive so it's just a copy basicallyand now what we'll do is we'll do whatwe did before we will set aequal to b so now we see we've got twovalues of tena and b are both ten but we also havethis temporary variable which is stillWatch at: 11:40 / 12:00pointing to the value ofa from before which is five so now whatwe can dois a third operation and set bequal to temp and now you can seethat what once was five a was once fivewhen we started the program up hereit's now ten and b which when we startedWatch at: 12:00 / 12:20was ten is now fiveso we have to do two swaps actually toswapuh one set of numbersso hopefully that clears it up a littlebit with the pictures and get to see alittle bit of actual code thereWatch at: 12:20 / 12:40let's move on to the next level levelfivecoffee time i'm a big fan of coffeeso i resonate with this uhcool had some good coffee this morninglet's look at these back to workeveryonethis lady's getting some coffee we gottaWatch at: 12:40 / 13:00get back to work okayoh newsflash regions of the citycontinue to[Music]are experience all right[Music]looks like the power has gone out whatWatch at: 13:00 / 13:20are we gonna dooh okay well that wasa pretty pretty easy level for us theremove on to uhlevel six here it's a rainy summer inyear six okaylooks like the carpets turned green idon't know what that meansbut it's raining outside it's dark andWatch at: 13:20 / 13:40stormyokay so we're doing some math nowso now what we want to do is add twonumbers togethersolet's see how does the add commandWatch at: 13:40 / 14:00work okay so it adds the contents of atile on the floor to whatever your valueyou're currently holding okay so that'sgood to knowso basically what we're going to want todo is similar to the last one where wecopied we need to store the first numberin memory and then when we're holdingWatch at: 14:00 / 14:20the second number we need to add thatnumber to it so we will pick a numberfrom the inbox and we will store thatin memory we'll just choose index 0thereit's another thing a lot of computersum a lot of computer systems are what wecallzero indexed which means that the firstWatch at: 14:20 / 14:40slotin uh in memory orin whatever structure you're looking atlike this carpet the first slot we wouldcallindex zero um it's the first positionbut we would refer to it byzero and then the last position is twoso this is a this carpet has three slotsWatch at: 14:40 / 15:00in itbut the highest slot is number two andthe lowest slot is number zeroso just a way that uh the computers tendto handle numbers anyways we'll pick upslot uh we'll pick up number one herewe'll store it in slot zero the firstslotand then what we'll want to do is wepick up the next number which in thisWatch at: 15:00 / 15:20case would be9 and then we just want to add itto what's in 0 and thenwe should be able to just move thatstraight to the outboxand that ought to do itthe one question iWatch at: 15:20 / 15:40might have is what happensto the second number but i don't thinkit's going to be a problem hereand then because this code is againgeneralizable it's generalized soyou know it doesn't care what's in slot0. as long as there's a number in thereit'll add it we should just be able toloopor do a jump to go back to the start andWatch at: 15:40 / 16:00then keep adding two numbers together solet's see how this workspick up one and store it in slot zeroand we pick up nine come alongadd them together and ten goes on thereokay sowe'll pick up the seven add themtogether get thirteen goodokay we got a negative number now that'sWatch at: 16:00 / 16:19interesting let's see what happens we'regonna add two to negative eight weshould get negative six okay looks goodand now one plus negative one we shouldget zero let's seeall right good dealall right anotherWatch at: 16:19 / 16:40level complete let's see what'sup nextall right so looks like we've got acouple of paths to go down herei think i'm gonna finish off this yellowline and then we'll call it a day forthis video so let's take a look at thetripler room here inWatch at: 16:40 / 17:00step 8.who are you this optional area is forhigh performing employees only ohthank you very much is that you wellyou're layout but we are seven yearslateri don't want to see 100 performanceincrease your performance will beevaluated with extra scrutiny all rightWatch at: 17:00 / 17:20so we need to triple the number soone thing i noticed in the earlierlevels was thatthe number in memory stayed there evenwhen we copied from it so i think whatwe should be able to dois go to the inbox copy toWatch at: 17:20 / 17:40slot zero and then we should just beable to movethe out box three times but i know thatthey are now evaluating our performanceso i can actuallywell let's see no i can't speed thingsup because the jump isn't terribly smarti can't just say jumpthree times so if i do that it's justWatch at: 17:40 / 18:00going to go to the outboxjust forever uh so that's no good wecan't do thatbut uhlet's think what else can we do here ohi'm misreading it see i thought weneeded to copy a number three times butactually we need to multiply a numberWatch at: 18:00 / 18:20by three so we need to add it to itselfuh two additional times so the copy twois still correctbut then what we need to do ispick it up again so we need tocopy from zero does that make sensewe're gonna copy it there then we'reWatch at: 18:20 / 18:40gonna pick up a copy of itand then we want to add onceso that would be let's see three pick upa three add it that would be six and wewant to add againso that would be multiply by two thatwould be multiplied by three and then wemove to the outer boxlet's just look at this now and think isthere any way we can speed this upWatch at: 18:40 / 19:00i don't think souh so we'll go ahead and put in thefinal jump statement here so that we doit over and over and over againand we will see what happens here onethingi do have a question about is thisnegative numberWatch at: 19:00 / 19:20in if you triple[Music]um because we're adding hereit should be okay if we were gonna do astraight multiplication by itselfthen we might run into trouble becausethe sign flips every time right if youmultiply a negative number by a negativenumber you get a positive numberWatch at: 19:20 / 19:40but if you multiply that positive numberby a negative number you end up with anegative again because we're adding herethat shouldn't be a problem so let's seewhat happenslet's store that three there and we'regonna add it if it doesn't add it sotriple three three times three is nineall right now we're gonna do the samewith negative three put it there add itget negative six add it get negativeWatch at: 19:40 / 20:00nine yeahnegative three times three is negativenine do the same with twookay two get four add another two weshould get sixlooks good now we come in and do zerookay zero plus zero is going to be zeroand zero againzero all right how did we doWatch at: 20:00 / 20:20okay size ohokay so we can do it in one fewerokay let's see let's see if we canfigure this out here soWatch at: 20:20 / 20:40umtrying to thinkone two three four six sevenyeah so one of these isn't necessaryWatch at: 20:40 / 21:00or we canslim it down how are we gonna do thatum we have to store it in order to get acopy of it[Music]um maybe we don't need the copy fromWatch at: 21:00 / 21:20let's let's see what happens herebecause if we just put it in zero we'restill okay yeah that's it so we're stillholding on to it so we don't throw itaway and thenthat makes sense so the copy from wedidn't need an additional copy so that'show we optimized that every now we gotour six stepsand we should get our 24 operationsWatch at: 21:20 / 21:40[Music]you see in earlier missions i'd seen uhour little guy throw away the numberafter he did the copy too so i thoughtwe needed to copy from after copyrightbut it makes sense that that's kind of aWatch at: 21:40 / 22:00an unnecessary stepall right we did itokay let's move on to the oct topoctoplier octupler sweetum let's see what we get here so i thinkwe're going to be multiplying a numberby eightessentially hereWatch at: 22:00 / 22:20is there anything in life more thrillingthan self-improvement i don't think socan you do it using only three adcommandsthat is an excellent question so let'sthink about this clearly we're gonnaneed to pick up something from the inboxWatch at: 22:20 / 22:40and we're gonna need to store itand then[Music]and then whatWatch at: 22:40 / 23:00[Music]okay sooh i see i see okay so here's what i'mthinkingWatch at: 23:00 / 23:20if we copy it to copy it to zeroright we're gonna store five there andthen we wanna addso we're going to get 10. then we wantto copy it toand then we want to add again so we'regoing to get let's walk through thiswe're going to have five add to it we'llget 10. we'll add two we're holding 10Watch at: 23:20 / 23:40we'll add 10 again we'll get 20.and then if we do it one more timewe should get oureight so essentially what this is doingis a um a squaring processWatch at: 23:40 / 24:00so um in computers we deal a lot withpowers of twoand if you think about it if you havetwo numbers let's use two justas an easy example you have two and twoand you add those together you get fourthen if you take that four as twosquared two times two is fourWatch at: 24:00 / 24:20if you take that four and add anotherfour to it you'll get eightso two times two is four times two againis eight so that's two to the thirdpowertwo times two times two is eight so youcan see by doing these three copyoptionsthat's essentially doing the theoperationof the um exponentWatch at: 24:20 / 24:40so this should do it hereum we'll i'll step through the logicbefore werun the little man again we're gonnacopy five so we'll have five herewe're holding at five so we'll add to itwe'll have 10. put 10 herewe're holding a 10 already so then wewilladd another 10 to it we'll get 20.Watch at: 24:40 / 25:00store 20 we'll add that 20 back to ourhands and get 40.five times eight is 40 so then we canmove it to the outbox and that should begoodso we'll go ahead and put our loop inhere and see how it worksso five comes in as the 10 stores itmakes 20 makes 40 andWatch at: 25:00 / 25:20out we do it okay so negative 4we get negative 8 we get negative 16 weshould get negative 32and out we go so for one we should endup with uheight here twofour and eight beautifulWatch at: 25:20 / 25:40and then zero again we should just getzero so let's see what happenszero and last time zero okaylooks pretty good to me let's see how wedid in our performancenine or fewer nice and 36 stepsWatch at: 25:40 / 26:00excellentall right off to the elevator okay sotetraconto player tetracon to playerwhat how many is that going to be tetrisforall your workers comes together itWatch at: 26:00 / 26:20culminates in a well-executed assignmentmultiply it by 40. ohokayso in this case we're not going to beable to use powers of2 because 40 isn't the power of 2. thenearest power of 2Watch at: 26:20 / 26:40is 32 and that's 2 to the fifthso i think we're gonna have to do theadd that we did last time five times[Music]Watch at: 26:40 / 27:00one two three that gets us to the eighth[Music]go againokay so that's times 8 there that shouldbe times 16. we'll do it againthat's multiplied by 32Watch at: 27:00 / 27:20but now we need an additional 8sowhat i'm gonna do is use an additionalum[Music]i'm actually gonna copy to i'm gonna usetwo memory slots i think hereWatch at: 27:20 / 27:40because i want toget um the number times eightseparately because 32 plus eight is 40.so then i'm going to do this copy 2operationthree times in slot oneWatch at: 27:40 / 28:00one more[Music]okay um but we got a problem umWatch at: 28:00 / 28:20we've gotta copy two zero and one firstso we have the same copy of the numberthen we wanna pickup the number in zeroand start there okay so by the end ofthis we should have32 times the number in our hands ialways want to add it to what's in oneand then move it to the outboxWatch at: 28:20 / 28:40let's just see if this works one timepick up the onestored in both okay we're gonna geteight times hereoh okay all right you see that we misseda store operationso we want to copy we went down to thelast coffee tooWatch at: 28:40 / 29:00here okay let's see how this worksnow so fourtimes eight should be 32 so we shouldstore32 then we're going to go over here andget 32 times 4 which isa big number 128.Watch at: 29:00 / 29:20and then we add those together 160should be four times fourso i think we're good to go uh they'reunhappy with me because i didn't put myfinal loop in here buti will go ahead and do this herewe'll step through it and see whathappens i'm not sure if this is the mostWatch at: 29:20 / 29:40optimal solutionlet's see what happens herebig number there 240.Watch at: 29:40 / 30:00i'm going to speed them up[Music]all right how do we do performance wiseit's a lot of stepslet's see okay i used a lot moreWatch at: 30:00 / 30:20so let's think about it nowso we get our 32 and we get oureight what can we do to speedthat upWatch at: 30:20 / 30:40um oh okay soyou know i'm using the two registers andthat's finebut here's what i'm noticing okay wedon't actually need to dothe operations multiple timesso because we already get the eight hereWatch at: 30:40 / 31:00you can see after this step here weshould beat uh the number times eight so i'mactually going to put another copy 2here and then what's going to happen iswe're going to get 8 times the numberstored in register 1 here bank number 1and we're also going to get it stored inWatch at: 31:00 / 31:200 then we're going to keep doing themultiplication to zero and then add itto one after the factso let's step through and see if thisworkswe get six we get there's three timesso there's eight times and then we keepon goingWatch at: 31:20 / 31:40but i'm noticing we're still one over soi thinklet me see if i can pause it herewhere i think we can optimize[Music]yes so it's right there we can actuallyadd fromWatch at: 31:40 / 32:00one here instead of copying to zerodoes that make sense um so if instead ofcopying to zero we just add what's inonethen we've saved ourselves a stepbecause we had the result of eight timesthe number stored in one we don't needto store it in zero and then keepmoving here so let's go through we'llWatch at: 32:00 / 32:20store threewe'll add it add it again get 12get 24 store it there now we'll comeback we'll add that and then store itover there and then we'll keep doing ourmathsoWatch at: 32:20 / 32:39so this was the critical step right hereokayso we're gonna now add to what's in oneinstead of storing in zero becausethat's a wasted step because we'vealready got this number stored in oneseeso now we're going to add those togetherand then we'll keep on movingWatch at: 32:39 / 33:00do the final addition and away we go[Music]and last but not least do the math withWatch at: 33:00 / 33:20zeroand we should have completed it let'ssee what they saythere we goall right[Music]Watch at: 33:20 / 33:39oh we've completed the first uhwhat if we not get on number two herelet's go back to number two because wehaven't got two green lights let's seelet's see what we can do with number twoinbox outbox jumpWatch at: 33:39 / 34:00using only three commands yeahlet's see what they say what are we notdoing properlyi don't know how we could possibly speedthis up butWatch at: 34:00 / 34:2030. okay[Music]so they do say that you may not be ableto dobothoptimizations at the same time now thereare 10 lettersWatch at: 34:20 / 34:40umi doubt we can handle multiple letterslet's find outnope we cannotum there are ten lettersWatch at: 34:40 / 35:00we do two per iteration it should stillbelet's find out that's twofour six eight ten that should beWatch at: 35:00 / 35:20how many operations was thatyeah we failed that oneand this one 25 steps okay sothat it's kind of interesting that theyWatch at: 35:20 / 35:40let you do thatum you can't you don't necessarily solveboth at the same uh at the same timei don't think there's any way that thiscould bedone in three three commands and also 25steps[Music]but we got green lights on everything onthe yellow path here nowWatch at: 35:40 / 36:00so uh just got an achievement therelooks like we've got quite a way to gosoi'm going to call it a day there and saythank you very much for watching uh ifyou enjoyed thisplease consider liking and subscribingand we'll see you in the next video

About The Author

You Might Be Interested In

Other videos in this game title

Comment (0)

LEAVE YOUR COMMENT

Your email address will not be published. Required fields are marked *