-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathre_ID.py
43 lines (40 loc) · 11.1 KB
/
re_ID.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Re-ID
# =====
#
# There's some unrest in the minion ranks: minions with ID numbers like "1", "42",
# and other "good" numbers have been lording it over the poor minions who are stuck
# with more boring IDs. To quell the unrest, Commander Lambda has tasked you with
# reassigning everyone new, random IDs based on her Completely Foolproof Scheme.
#
# She's concatenated the prime numbers in a single long string: "2357111317192329...".
# Now every minion must draw a number from a hat. That number is the starting index in
# that string of primes, and the minion's new ID number will be the next five digits
# in the string. So if a minion draws "3", their ID number will be "71113".
#
# Help the Commander assign these IDs by writing a function answer(n) which
# takes in the starting index n of Lambda's string of all primes,
# and returns the next five digits in the string. Commander Lambda has a lot of minions,
# so the value of n will always be between 0 and 10000.
#
# Languages
# =========
#
# To provide a Python solution, edit solution.py
# To provide a Java solution, edit solution.java
#
# Test cases
# ==========
#
# Inputs:
# (int) n = 0
# Output:
# (string) "23571"
#
# Inputs:
# (int) n = 3
# Output:
# (string) "71113"
primeString = '235711131719232931374143475359616771737983899710110310710911312713113713914915115716316717317918119119319719921122322722923323924125125726326927127728128329330731131331733133734734935335936737337938338939740140941942143143343944344945746146346747948749149950350952152354154755756356957157758759359960160761361761963164164364765365966167367768369170170971972773373974375175776176977378779780981182182382782983985385785986387788188388790791191992993794194795396797197798399199710091013101910211031103310391049105110611063106910871091109310971103110911171123112911511153116311711181118711931201121312171223122912311237124912591277127912831289129112971301130313071319132113271361136713731381139914091423142714291433143914471451145314591471148114831487148914931499151115231531154315491553155915671571157915831597160116071609161316191621162716371657166316671669169316971699170917211723173317411747175317591777178317871789180118111823183118471861186718711873187718791889190119071913193119331949195119731979198719931997199920032011201720272029203920532063206920812083208720892099211121132129213121372141214321532161217922032207221322212237223922432251226722692273228122872293229723092311233323392341234723512357237123772381238323892393239924112417242324372441244724592467247324772503252125312539254325492551255725792591259326092617262126332647265726592663267126772683268726892693269927072711271327192729273127412749275327672777278927912797280128032819283328372843285128572861287928872897290329092917292729392953295729632969297129993001301130193023303730413049306130673079308330893109311931213137316331673169318131873191320332093217322132293251325332573259327132993301330733133319332333293331334333473359336133713373338933913407341334333449345734613463346734693491349935113517352735293533353935413547355735593571358135833593360736133617362336313637364336593671367336773691369737013709371937273733373937613767376937793793379738033821382338333847385138533863387738813889390739113917391939233929393139433947396739894001400340074013401940214027404940514057407340794091409340994111412741294133413941534157415941774201421142174219422942314241424342534259426142714273428342894297432743374339434943574363437343914397440944214423444144474451445744634481448344934507451345174519452345474549456145674583459145974603462146374639464346494651465746634673467946914703472147234729473347514759478347874789479347994801481348174831486148714877488949034909491949314933493749434951495749674969497349874993499950035009501150215023503950515059507750815087509951015107511351195147515351675171517951895197520952275231523352375261527352795281529753035309532353335347535153815387539353995407541354175419543154375441544354495471547754795483550155035507551955215527553155575563556955735581559156235639564156475651565356575659566956835689569357015711571757375741574357495779578357915801580758135821582758395843584958515857586158675869587958815897590359235927593959535981598760076011602960376043604760536067607360796089609161016113612161316133614361516163617361976199620362116217622162296247625762636269627162776287629963016311631763236329633763436353635963616367637363796389639764216427644964516469647364816491652165296547655165536563656965716577658165996607661966376653665966616673667966896691670167036709671967336737676167636779678167916793680368236827682968336841685768636869687168836899690769116917694769496959696169676971697769836991699770017013701970277039704370577069707971037109712171277129715171597177718771937207721172137219722972377243724772537283729773077309732173317333734973517369739374117417743374517457745974777481748774897499750775177523752975377541754775497559756175737577758375897591760376077621763976437649766976737681768776917699770377177723772777417753775777597789779378177823782978417853786778737877787978837901790779197927793379377949795179637993800980118017803980538059806980818087808980938101811181178123814781618167817181798191820982198221823182338237824382638269827382878291829382978311831783298353836383698377838783898419842384298431844384478461846785018513852185278537853985438563857385818597859986098623862786298641864786638669867786818689869386998707871387198731873787418747875387618779878388038807881988218831883788398849886188638867888788938923892989338941895189638969897189999001900790119013902990419043904990599067909191039109912791339137915191579161917391819187919992039209922192279239924192579277928192839293931193199323933793419343934993719377939193979403941394199421943194339437943994619463946794739479949194979511952195339539954795519587960196139619962396299631964396499661967796799689969797199721973397399743974997679769978197879791980398119817982998339839985198579859987198839887990199079923992999319941994999679973100071000910037100391006110067100691007910091100931009910103101111013310139101411015110159101631016910177101811019310211102231024310247102531025910267102711027310289103011030310313103211033110333103371034310357103691039110399104271042910433104531045710459104631047710487104991050110513105291053110559105671058910597106011060710613106271063110639106511065710663106671068710691107091071110723107291073310739107531077110781107891079910831108371084710853108591086110867108831088910891109031090910937109391094910957109731097910987109931100311027110471105711059110691107111083110871109311113111171111911131111491115911161111711117311177111971121311239112431125111257112611127311279112871129911311113171132111329113511135311369113831139311399114111142311437114431144711467114711148311489114911149711503115191152711549115511157911587115931159711617116211163311657116771168111689116991170111717117191173111743117771177911783117891180111807118131182111827118311183311839118631186711887118971190311909119231192711933119391194111953119591196911971119811198712007120111203712041120431204912071120731209712101121071210912113121191214312149121571216112163121971220312211122271223912241122511225312263122691227712281122891230112323123291234312347123731237712379123911240112409124131242112433124371245112457124731247912487124911249712503125111251712527125391254112547125531256912577125831258912601126111261312619126371264112647126531265912671126891269712703127131272112739127431275712763127811279112799128091282112823128291284112853128891289312899129071291112917129191292312941129531295912967129731297912983130011300313007130091303313037130431304913063130931309913103131091312113127131471315113159131631317113177131831318713217132191322913241132491325913267132911329713309133131332713331133371333913367133811339713399134111341713421134411345113457134631346913477134871349913513135231353713553135671357713591135971361313619136271363313649136691367913681136871369113693136971370913711137211372313729137511375713759137631378113789137991380713829138311384113859138731387713879138831390113903139071391313921139311393313963139671399713999140091401114029140331405114057140711408114083140871410714143141491415314159141731417714197142071422114243142491425114281142931430314321143231432714341143471436914387143891440114407144111441914423144311443714447144491446114479144891450314519145331453714543145491455114557145611456314591145931462114627146291463314639146531465714669146831469914713147171472314731147371474114747147531475914767147711477914783147971481314821148271483114843148511486714869148791488714891148971492314929149391494714951149571496914983150131501715031150531506115073150771508315091151011510715121151311513715139151491516115173151871519315199152171522715233152411525915263152691527115277152871528915299153071531315319153291533115349153591536115373153771538315391154011541315427154391544315451154611546715473154931549715511155271554115551155591556915581155831560115607156191562915641156431564715649156611566715671156791568315727157311573315737157391574915761157671577315787157911579715803158091581715823158591587715881158871588915901159071591315919159231593715959159711597315991160011600716033160571606116063160671606916073160871609116097161031611116127161391614116183161871618916193162171622316229162311624916253162671627316301163191633316339163491636116363163691638116411164171642116427164331644716451164531647716481164871649316519165291654716553165611656716573166031660716619166311663316649166511665716661166731669116693166991670316729167411674716759167631678716811168231682916831168431687116879168831688916901169031692116927169311693716943169631697916981169871699317011170211702717029170331704117047170531707717093170991710717117171231713717159171671718317189171911720317207172091723117239172571729117293172991731717321173271733317341173511735917377173831738717389173931740117417174191743117443174491746717471174771748317489174911749717509175191753917551175691757317579175811759717599176091762317627176571765917669176811768317707177131772917737177471774917761177831778917791178071782717837178391785117863178811789117903179091791117921179231792917939179571795917971179771798117987179891801318041180431804718049180591806118077180891809718119181211812718131181331814318149181691818118191181991821118217182231822918233182511825318257182691828718289183011830718311183131832918341183531836718371183791839718401184131842718433184391844318451184571846118481184931850318517185211852318539185411855318583185871859318617186371866118671186791869118701187131871918731187431874918757187731878718793187971880318839188591886918899189111891318917189191894718959189731897919001190091901319031190371905119069190731907919081190871912119139191411915719163191811918319207192111921319219192311923719249192591926719273192891930119309193191933319373193791938119387193911940319417194211942319427194291943319441194471945719463194691947119477194831948919501195071953119541195431955319559195711957719583195971960319609196611968119687196971969919709197171972719739197511975319759197631977719793198011981319819198411984319853198611986719889198911991319919199271993719949199611996319973199791999119993199972001120021200232002920047200512006320071200892010120107201132011720123201292014320147201492016120173201772018320201202192023120233'
def answer(n):
return primeString[n:n+5]
print answer(3)