15-110: principles of computing, spring 201815110-s18/assignments/pa1.pdflightbot-1-4.txt...

Post on 17-Jul-2020

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Page1

15-110:PrinciplesofComputing,Spring2018

ProgrammingAssignment1Due:Tuesday,January23by9PM

Note:Youareresponsibleforprotectingyoursolutionstothefollowingproblemsfrombeingseenbyotherstudentsbothphysically(e.g.,bylookingoveryourshoulderorverbaldiscussion)andelectronically.Inparticular,sincethelabmachinesusetheAndrewFileSystem(AFS)tosharefilesworldwide,youneedtobecarefulthatyoudonotputfilesinaplacethatispubliclyaccessible.IfyouaredoingtheassignmentontheGates-HillmanClustermachinesweuseinthelaboronunix.andrew.cmu.edu,pleaseremembertohaveyoursolutionsinsideaprivatefolder(whichisunderyourhomedirectory).Ourrecommendationisthatyoucreateapa1folderunder~/private/15110forthisassignment.Thatis,thenewdirectorypa1isinsidethedirectorynamed15110,whichisinsidetheprivatedirectory.Overview

Forthisassignment,youwillcreateatextfileforeachoftheproblemsbelow.Youshouldsaveallofthesefilesinafoldernamedpa1.Onceyouhaveeveryfile,youshouldzipupthepa1folderandsubmitthezippedfileonAutolab.SeeLab1forareminderofhowtodothis.LightBotAsyousawinclass,weusedagamecalledLightBottointroducetheideaofcomputationalthinking,solvingaproblembybreakingitdowntosimplerstepsandputthesestepsintherightordertosolvethelargerproblem.Inclass,wesolvedsomeproblemsfromthiswebsite:http://lightbot.com/hour-of-code.html(YouwillneedtomakesureyouhaveFlashactiveonyourcomputertoruntheonlineversion.YoucanalsodownloadaniOSorAndroidappforthisprogramifFlashdoesn'tworkonyourcomputer.)Whenwesolvethepuzzles,weputinstructionblocksinplacetoforma"program"fortherobot.Asyousawinlab,youcanalsowritetheseprogramstextually,whichiswhatwewillbedoingwhenwestarttolearnPython,aprogramminglanguageforcomputers.

Page2

Asanexample,hereisthesolutionforLevel1,Puzzle3andit'scorresponding"program":

IfthesolutionrequiresanadditionalprocedurelikeinLevel2,Puzzle1,wecanincludebothtocreatethe"program"insinglefile:

Assignment

SolvethefollowingfiveproblemsfromtheLightBotactivityonline.Firstsolvethemusingtheinstructionblocksaswedidinclass.Thenwritethesolutionasa"program"inatextfile,onesolutionperfile.

def main(): jump() right() jump() right() jump() light()

def main(): p1() right() p1() right() p1() def p1(): forward() forward() forward() light()

Page3

1. [2points]SolveLevel1,Puzzle4andstorethesolutionasa"program"inthefile

lightbot-1-4.txtinyourpa1directory.

2. [2points]SolveLevel1,Puzzle6andstorethesolutionasa"program"inthefilelightbot-1-6.txtinyourpa1directory.

3. [2points]SolveLevel2,Puzzle3andstorethesolutionasa"program"inthefilelightbot-2-3.txtinyourpa1directory.

Page4

4. [2points]SolveLevel2,Puzzle5andstorethesolutionasa"program"inthefilelightbot-2-5.txtinyourpa1directory.(HINT:UseP1toclimbandlightthetiles.UseP2tosetLightBotupforthenextclimb.)

5. [2points]SolveLevel3,Puzzle3andstorethesolutionasa"program"inthefile

lightbot-3-3.txtinyourpa1directory.(HINT:lookforsomethingyoucanrepeatoverandoverandputthisintheprocedure1andyourlastinstructioninprocedure1willbeP1toallowyoutorepeattheinstructions.Whatdoyouputintomaintostarttheprocessgoing?)

Submission

Youshouldnowhavethepa1folderthatcontainsthefollowing5files:

lightbot-1-4.txt lightbot-2-3.txt lightbot-3-3.txt lightbot-1-6.txt lightbot-2-5.txt

Zipupthefolderandsubmitthezippedfilenamedaspa1.ziponAutolabtothepa1assignmentbytheindicateddeadline.Youcanresubmitasmanytimesasyouneedtoupuntilthedeadline,butonlythelastsubmissionwillbegraded.BesuretocheckonAutolabwhenyousubmittomakesureyoucanseeyourfivefilesandthecontentsarecorrect!Ifyouseeemptyfilesorthewrongfiles,fixthiserrorandresubmit!

top related