/
Package fun July   Type Package Title Use R for Fun Version Package fun July   Type Package Title Use R for Fun Version

Package fun July Type Package Title Use R for Fun Version - PDF document

trish-goza
trish-goza . @trish-goza
Follow
484 views
Uploaded On 2014-11-12

Package fun July Type Package Title Use R for Fun Version - PPT Presentation

10 Date 20110812 Author Yihui Xie Taiyun Wei and Yixuan Qiu Maintainer Yihui Xie Description This is a collection of R games and other funny stuffsuch as the classi cal Mine sweeper and sliding puzzles License GPL LazyLoad yes URL httpsgithubcomyihui ID: 10606

Date 20110812 Author Yihui

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Package fun July Type Package Title Us..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Package`fun'October23,2020TypePackageTitleUseRforFunVersion0.3MaintainerYihuiXie&#xxie@;&#xyihu;&#xi.na;&#xme00;DescriptionThisisacollectionofRgamesandotherfunnystuff,suchastheclassicMinesweeperandslidingpuzzles.LicenseGPLLazyDatayesURLhttps://github.com/yihui/funBugReportshttps://github.com/yihui/fun/issuesRoxygenNote7.1.1EncodingUTF-8NeedsCompilationnoAuthorYihuiXie[aut,cre](&#xhttp;&#xs://;&#xorci; .or;᠀g/0000-0003-0645-5666),YixuanQiu[aut],TaiyunWei[aut]RepositoryCRANDate/Publication2020-10-2318:00:02UTCRtopicsdocumented:fun-package.........................................2alzheimer_test........................................2gomoku...........................................3htmlspecialchars......................................4lights_out..........................................5mine_sweeper........................................6random_password......................................7shutdown..........................................8sliding_puzzle........................................91 2alzheimer_testtagData...........................................10tag_cloud..........................................11tower_of_hanoi.......................................13Index14 fun-packageUseRforFun DescriptionThisisacollectionofRgamesandotherfunnystuff,suchastheclassicalMinesweeperandslidingpuzzles.DetailsNewgamesarealwayswelcome;ifyouknowGITandwanttojointhedevelopment,pleasegotohttps://github.com/yihui/fun;orsimplycontributeideasathttps://github.com/yihui/fun/issues.Author(s)YihuiXie,TaiyunWei,andYixuanQiuExamples##Seetheexamplesineachfunction,orcheckoutthedemosdemo(package="fun") alzheimer_testTestAlzheimer'sdiseasebyndingoutthedifferentcharacterinacharacterrectangle DescriptionPleasetryhardtondtheletter"N"in300"M"s,one"6"in300"9"s,etc.Usagealzheimer_test(char1=c("9","O","M","I","F","D"),char2=c("6","C","N","T","E","O"),nr=10,nc=30,seed=NULL,...) gomoku3Argumentschar1the'background'characterchar2thecharactertobefoundoutnrnumberofrowsofthecharacterrectanglencnumberofcolumnsseedseedforrandomnumbergeneration...otherargumentspassedtoset.seedValueIfatleastonetestitemhasbeenpassed,adata.framewillbereturnedtellingtheresultofthetest.NoteDon'tbetooseriousaboutthistest.I'mnodoctor,butIthinkthiswillbeagoodpresenttoyourfriends.Author(s)YihuiXiehttps://yihui.org�Examples##Notrun:x=alzheimer_test()##End(Notrun) gomokuThegameofGomoku,a.k.aFiveinarow DescriptionTherearetwoplayersinthisgamewhoplayoneaftertheotherusingblackandwhitestonesrespectively.Thewinneristherstplayertogetanunbrokenrowofvestoneshorizontally,vertically,ordiagonally.Usagegomoku(n=19)Argumentsnthenumberofrowsandcolumnsintheboard(thedefault19generatesthestan-dardboard) 4htmlspecialcharsValueNULLNoteTheplayersshouldjudgethewinnerbythemselves;thisfunctiondoesnotdothisjob(patchesarewelcome,ofcourse).Author(s)YihuiXiehttps://yihui.org�;modiedfromthecodebypklinReferenceshttps://d.cosx.org/d/104750,https://en.wikipedia.org/wiki/GomokuExamplesgomoku() htmlspecialcharsReplaceHTMLspecialcharacterswithHTMLentities DescriptionThecharactersc("&",'"',"'&#x","0;",")willbereplacedwithc("&",""","'","<",">"),respectively.Usagehtmlspecialchars(string)Argumentsstringthestringwith(orw/o)HTMLspecialcharsValuethestringwithspecialcharsreplaced.Author(s)YihuiXiehttps://yihui.org�Referenceshttps://www.php.net/manual/en/function.htmlspecialchars.php lights_out5SeeAlsogsubExampleshtmlspecialchars("href='https://yihui.org' -50;�&#x/a00;Yihui)#<ahref='https://yihui.org'>Yihui</a> lights_outPlaythe“LightsOut”gameinR DescriptionBydefault,thewhitesquaresintheplotdenotethelightsthatareon,andblackonesfortheoff.Whenyouclickonalight,thislightaswellasthefourneighborswillswitchtheirsstatus.Yourmissionistocloseallthelights.Usagelights_out(width=5,height=5,steps=3,cheat=FALSE,col.off="black",col.on="white",col.frame="lightblue",seed=NULL)Argumentswidthnumberoflightsinxaxisheightnumberoflightsinyaxisstepsnumberof“seed”lightstoinitializethepuzzle.Ingeneral,thelargerstepsis,themorecomplexthispuzzlemaybecheatlogical.IfTRUEadataframeindicatingthestepstosolvethispuzzlewillbeprintedcol.offcolorwhenlightsoffcol.oncolorwhenlightsoncol.framecoloroflightsborderseedseedforrandomnumbergenerator 6mine_sweeperNoteLinux/MacusershavetouseX11(type='Xlib')ortheCairographicsdeviceCairo()inthepackagecairoDevice.Author(s)YixuanQiu&#xyixu; n.q;&#xiu@c;&#xos.n; me0;Referenceshttps://en.wikipedia.org/wiki/Lights_Out_(game)Examples##shoulduseXlibforthex11()deviceunder*nix,e.gif(interactive()){if(.Platform$OS.type=="windows")x11()elsex11(type="Xlib")lights_out()} mine_sweeperPlaytheMineSweepergameinR DescriptionThecontrolsshouldbefamiliartoyou:Clicktheleftmousebuttontodiginanarea,andrightbuttontomarkorunmarktheareawithags.Usagemine_sweeper(width=10,height=10,mines=20,cheat=FALSE)Argumentswidthnumberofgridsinhorizontalaxisheightnumberofgridsinverticalaxisminesnumberofminescheatlogical.IfTRUEamatrixindicatingthemineswillbeprintedNoteLinux/MacusershavetouseX11(type='Xlib')ortheCairographicsdeviceCairo()inthepackagecairoDevice.Author(s)YixuanQiu&#xyixu; n.q;&#xiu@c;&#xos.n; me0; random_password7Referenceshttps://en.wikipedia.org/wiki/Minesweeper_(computer_game)Examples##shoulduseXlibforthex11()deviceunder*nix,e.gif(interactive()){if(.Platform$OS.type=="windows")x11()elsex11(type="Xlib")mine_sweeper()} random_passwordGeneratearandompasswordwithaspeciedlength DescriptionThisfunctiongeneratesarandompassordsampledfromtheASCIItable.Usagerandom_password(length=12,replace=FALSE,extended=TRUE)ArgumentslengthlengthofthepasswordreplacesamplefromtheASCIItablewith(TRUE)orwithout(FALSE)replacement?extendedifFALSE,usealphanumericcharactersonly;otherwiseusealltheASCIIcharac-tersValueacharacterstringAuthor(s)YihuiXiehttps://yihui.org�SeeAlsosample 8shutdownExamplesrandom_password()#settheseedtogetfixedpasswordeverytime;youmayjustremembertheseed#andforgettherealpasswordbecauseit'sreproducibleset.seed(123)random_password()#longpasswordrandom_password(20,TRUE) shutdownShutdowntheoperatingsystemwiththecommand`shutdown' DescriptionThereisacommandshutdowninbothWindowsandLinux,andthisfunctionusesittoshutdownacomputer.Usageshutdown(wait=0)Argumentswaittimetowaitbeforeshuttingdown(inseconds);passedtoSys.sleepDetailsAfterthetimewaithaspassed,Rwillexecuteshutdown-s-t0(forWindows)orshutdown-hnowtoshutdownthecomputer.ValueThestatuscodeofsystem.Author(s)YihuiXiehttps://yihui.org�SeeAlsosystem,Sys.sleep sliding_puzzle9Examplesif(interactive()){#whenyourcodeisextremelytime-consuming,youmayneedthisfunction;e.g.#yougotosleep,andRisrunninglongcomputation...complexgraphics...and#longlongcomputation...atlast,shutdown()#thenextdayyouwakeup,'thankyou,R':)} sliding_puzzleSlidingpuzzleinR DescriptionUseRtoplayslidingpuzzleUsagesliding_puzzle(size=c(3,3),bg="lightblue",z=NULL)Argumentssizetwodimensionalvector,thesizeofslidingpuzzle.Note:theelementofsizemustbegreaterthan1.bgthebackgroundcolorofblocks.zthematrixofslidingpuzzle,ifzisspecied,sizewillbeomited.DetailsIfsizeisspeciedandzisNULL,thenthefunctionwillgenerateasolvableslidingpuzzle.NoteLinux/MacusershavetouseX11(type='Xlib')ortheCairographicsdeviceCairo()inthepackagecairoDevice.Author(s)TaiyunWeiReferencesAbouttheslidingpuzzle:https://en.wikipedia.org/wiki/Sliding_puzzle 10tagDataExamples##shoulduseXlibforthex11()deviceunder*nix,e.gif(interactive()){if(.Platform$OS.type=="windows")x11()elsex11(type="Xlib")sliding_puzzle()sliding_puzzle(z=matrix(0:11,3,4))} tagDataTaginformationofYihuiXie'sEnglishblog DescriptionTagdatacollectedfromYihuiXie'sBlog,containingthetagwords,frequencyandhyperlinks,etc.FormatAdataframewith45observationsonthefollowing5variables.tagacharactervector;thetagwordslinkacharactervector;hyperlinksoftagscountanumericvector;thefrequencyoftagsinblogs(seeDetails)coloracharactervectorinhexadecimalformatspecifyingtheRGBcomponentoftagcolorshicoloracharactervectorsimilartocolor;thecolorwhenmousehangsoverthetagDetailsThecountwasmultipliedby4inthedatainorderthatthetagcloudcouldbemoreclear.Sourcehttps://yihui.org/en/(accessedonJune10,2009)Exampleshist(tagData$count/4,10)#extremelyrightskewed#seehelp(tag_cloud)fortheexampleofcreatingtagcloudwiththisdata tag_cloud11 tag_cloudCreatingTagCloudinR(withFlashandJavaScript) DescriptionUseRtowritetagdata(tagwords,frequency,hyperlinksandcolors,etc)intoJavaScript,andtheJavaScriptcodewillgenerateaFlashmovie.Finallythetagcloudcanbecreatedwithfantastic3Drotationeffect.Usagetag_cloud(tagData,htmlOutput="tagCloud.html",SWFPath="tagcloud.swf",JSPath="swfobject.js",divId="tagCloudId",width=600,height=400,transparent=FALSE,tcolor="333333",tcolor2="009900",hicolor="ff0000",distr="true",tspeed=100,version=9,bgcolor="ffffff",useXML=FALSE,htmlTitle="TagCloud",noFlashJS,target=NULL,scriptOnly=FALSE,encode=FALSE,reserved=FALSE)ArgumentstagDataadata.framecontainingatleast3columns:tag,linkandcount.OptionalcolumnsarecolorandhicolorhtmlOutputlenameoftheHTMLoutputSWFPathpathoftheSWFsourcele(`tagcloud.swf');seesystem.file("js","tagcloud.swf",package="fun")JSPathpathoftheJavaScriptle(`swfobject.js');seesystem.file("js","swfobject.js",package="fun")divIdidofthetagclouddiv(HTMLlayer) 12tag_cloudwidth,heightwidthandheightofthetagcloudtransparentlogical;whethertousetransparentbackgroudfortheFlashmovie?tcolor,tcolor2,hicolor,distr,tspeedseeDetailsversiontherequiredFlashversionbgcolorbackgroudcoloroftheFlashmovieuseXMLuseXMLleforthetaginformationorjustastring;thiswillbepassedtotheFlashobjectasavariablehtmlTitletitleoftheHTMLlenoFlashJStexttoshowifFlashorJavaScriptisnotsupportedtargettargetwindowofthehyperlinks;possiblevaluesareNULL,'_blank','_top',etcscriptOnlyprintthescriptintheconsoleonly?(ifTRUE),noHTMLlewillbegeneratedencodeencodethetagXMLornot?(withURLencode)setittobeTRUEwhenyourbrowserdoesnotrecognizethetagXMLcorrectlyreservedshouldreservedcharactersbeencoded?seeURLencodeDetailsThisfunctionisbasedontheWordPressplugin“wp-cumulus”.Ifthereareanyargumentsyoudon'tunderstand,pleasecheckthereference.ValueNULLAuthor(s)YihuiXiehttps://yihui.org�ReferencesAbouttheWordPressplugin:https://wordpress.org/plugins/wp-cumulus/UsageoftheSWFObject:http://blog.deconcept.com/swfobject/Anexampleofvisualizingtagsinmyblog:https://yihui.org/en/2009/06/creating-tag-cloud-using-r-and-flash-javascript-swfobject/SeeAlsocat,sprintf,URLencode tower_of_hanoi13Examplesdata(tagData)htmlFile=paste(tempfile(),".html",sep="")if(file.create(htmlFile)){tag_cloud(tagData,htmlFile)if(!interactive())browseURL(htmlFile)} tower_of_hanoiDemonstratetheTowerofHanoipuzzleinR DescriptionThisfunctionusestherecursivealgorithmtosolvetheTowerofHanoipuzzle,anddemonstratesthegameinanimation.Usagetower_of_hanoi(n=7)Argumentsnanintegerindicatingthenumberofdisksontherot.DetailsThisfunctionwaswrittenbyLinlinYan&#xlinl;&#xin.y; n@c;&#xos.n; me0;inaChineseforum(See'Refer-ences')toshowtheusageofrecursivealgorithm.Author(s)LinlinYan&#xlinl;&#xin.y; n@c;&#xos.n; me0;&#xlinl;&#xin.y; n@c;&#xos.n; me0;ReferencesOriginalcode:https://d.cosx.org/d/101199AbouttheTowerofHanoi:https://en.wikipedia.org/wiki/Tower_of_HanoiSeeAlsobarplotExamples##Notrun:tower_of_hanoi(7)##End(Notrun) Indexdynamictag_cloud,11letag_cloud,11packagefun-package,2alzheimer_test,2barplot,13cat,12fun(fun-package),2fun-package,2gomoku,3gsub,5htmlspecialchars,4lights_out,5mine_sweeper,6random_password,7sample,7set.seed,3shutdown,8sliding_puzzle,9sprintf,12Sys.sleep,8system,8tag_cloud,11tagData,10tower_of_hanoi,13URLencode,12X11,914