资源描述:
《DIT027-RegularExamWithAnswers.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、EXAM–w.SolutionsDistributedFault-tolerantProgrammingDIT027(TIG027)Day:2/11-2011Time:8:30–12:30•Responsible:HansSvensson•Result:Nolaterthan18/11-2011•Aids:None•Grade:Thereare6assignments(with15+24+16+15+25+5=100points);atotalofatleast50pointsisapass(G)andatotalofatleast75pointsisapassw
2、.distinction(VG).Pleasereadthefollowingguidelinescarefully:•Pleasereadthroughallassignmentsbeforestartworkingontheanswers•AnswersshouldbegiveninEnglish•Begineachassignmentonanewsheet•WriteyouranonymousIDoneachsheet•Writeclearly;unreadable==wrong!•Fullmarksaregiventosolutionsthataresho
3、rt,elegant,andcorrect•Lessmarksaregiventounnecessarilycomplicatedorunstructuredsolutions•Don'tforgettowritecommentswithyourcode•YouareallowedtousestandardErlangfunctionsandlibraries,ifnothingisexplicitlymentionedintheproblemdescription•Theexactsyntaxisnotcrucial,youwillnotbepunishedfo
4、rmissingforexampleaparenthesisoracomma.GoodLuck!Problem1–Patternmatching(total15p)Inthisassignmentyouaregivenfivepatternmatchingexpressions.Ifmatchingsucceeds,whatarethevaluesoftheboundvariables?Ifmatchingdoesnotsucceed,explainwhy.(3p)QuestionA[H
5、T]=[1,2
6、3].Answer:H=1,T=[2
7、3](Note:[2,
8、3]/=[2
9、3])(3p)QuestionB[_
10、Sorted]=[a,4,1,0,2].Answer:Sorted=[4,1,0,2](Note:_isnotboundtoanything)(3p)QuestionC{{_,P},_}={{1,2},3}.Answer:P=2(Note:_matchesanything)(3p)QuestionD[A,B
11、B]=[1,2,3].Answer:DoesnotmatchsinceBcan'tbeboundtoboth2and3(3p)QuestionE{car,Brand,Year}={car,spijker,19
12、24}.Answer:Brand=spijker,Year=1924Problem2–Understandingsequentialcode(total24p)Inthisassignmentyouaregiventhecodeofthemoduleexam(listedbelow).Firstly,youhavetoexplaintheresultofevaluatingthefollowingexpressions:(3p)QuestionAexam:f1(1,[2,3,1,4]).Answer:[2,3,4](f1isactuallyadeleteAllfu
13、nction,thatgivenXandXswillremovealloccurrencesofXinXs).(3p)QuestionBexam:f1(1,[1,2,3,1,4]).Answer:[2,3,4](3p)QuestionCexam:f1(6,[1,aap,2,1]).Answer:[1,aap,2,1](3p)QuestionDexam:f2([p,p,q,p]).Answer:5(f2willstartfrom0,add1oneachpandmultiplyby2oneachq,thus(0+1+1)*2+1=5(3p)QuestionEexam:
14、f2([d