Skip to content

Instantly share code, notes, and snippets.

@sjakobi
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjakobi/9327400 to your computer and use it in GitHub Desktop.
Save sjakobi/9327400 to your computer and use it in GitHub Desktop.
Some timings for code_eval challenge 125
import Data.Bits (popCount)
import Data.Char (intToDigit)
import Data.List (intersperse)
import System.Environment (getArgs)
digitAt :: Integer -> Char
digitAt = intToDigit . (`rem` 3) . popCount
main = do
(fileName:_) <- getArgs
contents <- readFile fileName
putStrLn $ intersperse '\n' $ map (digitAt . read) $ lines contents
import sys
def n_set_bits(x):
return bin(x).count('1')
def n_at(ix):
"""Return the digit at index ix in the sequence 01121220…
The solution works because the number of transformations that the digit at
ix has made is equal to the number of 1 bits in ix."""
return n_set_bits(ix) % 3
if __name__ == '__main__':
filename = sys.argv[1]
with open(filename) as f:
for line in f:
print(n_at(int(line.strip())))
7105315123025034088397786376986851161595
2992859901117580673662094330984123576269
6942201377668966549038960660769066750325
9756722068277209331974272218955927646943
3312366061890363936260175370762170889485
7689262913422012770412829457156452176117
1190797799412506501594555044459298856769
365736696505344841540494712426868977132
6622399306787783652113505519288217523979
1835919517714149076827149951321857596745
690192002242149388593631171575620928704
2807723432905936984989625408568576019325
3462070920954970162212630790693901172358
6587870784012840886493493814964683354882
2424160809726378120832294587184033882505
1289779470091439863386526474214016117118
1338744500407894606095712697532380563497
2891038829552616577176244525095886068185
8736443973260434294581905964406930194636
286092536165385230563545113623798587969
9183571019976768230460605538109989344407
2944712178169921461999980131399755787844
8367917303082168542870892422299690281365
8590778920267508646109677472471466877518
6515291797792608676199089303985864397115
2851795804084515848450422834369100875885
2598955486564063736817439849999796006095
8840414949832641959284620872980877718588
5891259340034406190787810870924472801474
3009769788038370059936259920484923545654
255277846509237897732726267191496251187
955214315313248626858172570051837357030
131794868163674055445898385801888152529
4305851362955337175396407731042955401897
8653169545735052660975888466206312448073
5049446021451595855219497629355421777368
3535265068225439435261895636272973480958
3146292099030346585767055133529266609739
2070543501823247765453131825384022605947
9996395282003082464035970243418926821220
6593646789070059711146829242678148549277
8131088257094054444574599974425008920066
3107268964983195923527704755482679816554
6102281208344303868626067800465301792273
2318656322464935930078999881272363115390
709900070625512767145399765380543223217
4631928726908816252628939491510551583552
7156382383874406234141396019628418280729
840811754744205087661756043213066897192
8918753068554995527704719697465147534190
7543737539737037670790700460675935673395
8986685647000416276403224724389908214614
7611458718829553703036549538893078745554
5691794996874234818051377871835937196200
5603420203404179392899785285885173474115
4963505759675144464550892752200581064658
5850404432578782593669491870821816210437
4003930962386281856805779188808030293544
15371172287810937310680778173185511004
7885002401130222503910841692168291055907
4355541113458808991547114442466142138054
5956073843992469611489907519289992585550
6179070429491685206929147113914557373919
9100824443397817162352049983003735639446
7959521876572121791582303183585706894790
4763227304403272160959090558821396310935
1650463861552648161219176032771832948196
440757734557986641168522646420599748368
3863861945375639354005925476997993369800
2197623684948028203284286428890049878721
2173483022889008482236225391591003255742
8933960753729690075455257393249685949696
1766934175838011491750757273823735275400
9987610685255462660339039910425642029718
9229400277189615984902189594798040772043
4740940597989316935420686966113924006232
9078933551540932886824715677663571530318
6324524411762862588996915472860686877886
7115662220364747584734150111364584697615
2048521948103454120259304713504748296260
2851500828104128924191414933624860754788
2589813779078098246164487582696694701643
3871052223426441088399618841464561564975
6811058932938024923675952471085514800196
557565282385341007276440112892283166725
850491103704814392868326600150478659115
5028865485371964854248638060956560849859
1335814661796212286268773549045144250295
9970612436113344936187563772843437768026
3364776238161970878345336930756708120664
7355333873207153904607179144240237645608
7776139934428716470971902294659921010925
6166200743565713570260132636407735093085
799969157308384468434592768599847117917
452621426719530999855066471581245611268
5579091133741369472755345572708371769181
5033211881989572919567920108177631871519
2426516950344844927107114263932317261450
3633156489710427308562466750172562988336
1550487289947100160570139846949466088836
6087205548048336422268570526632659865444
2212587509552520980979155784512784892453
4681388539082816936517723578587871523875
8447696214358012604181273172276624828636
2623503210674683463802353468151139946767
1935855625911544001905983507392211225215
8574086812746826367399751351414017528297
4092045216925310923517454012829736725782
9737508612683824692896719504613678213071
8078302798485712583996902248041206502384
3042373754578683558961150711505924040355
3339279144333993338683946262436446621836
3112055894296487391672848066374632585783
4578869268567733896757009549214269014225
9957387771383077320324979919801692645657
5741803687234387890936072076917113977584
6617869322741034893090582630922879269360
3081829636211126537020500831207815277389
7055028363941371738118622965900537188808
8835871149025325736834916439469105006789
2566097938618404579174848961395273926961
8775624515528797498176182777958389683372
3964420222497908538624793432901651294969
1960571659800653435514379008369988278991
4260022947777753616141549817563362580160
8773510602069414883286145254184398941103
6175685001278957852645507715303231441985
5719328110189156639570309239279689477489
8124116926738622490088097622909719203878
4838319766038640065740495653563827035570
9854017110041927500902322020305801846735
8634000456981846391313312368258591429547
5141838972067665657300001317895409439667
2086104904743279177510523737003490270470
4718539793250626865788414987517825162156
1326507687673753222602843966367797376414
6857708976287671966556207123477469016079
3571847086814613251351744964169963586568
7634143861536439146389744822610996990357
3431122074010599777410683510902696533003
4201861521670212712976090276748938362097
4523998156902333078657735683977046630356
478305524416819782133511413168132005942
8447574582041582375514620275184962603621
6054627411945744576577025495950851271313
8473834061050925526686795396581956980809
7012203511019735132294303255778948941354
2043894020534461086371067978847526337368
2849196968985381973026106356224471091110
9463735019254423666814776324845695741439
3252734941001400065216535266749067013648
1955806261838940577699516696552169664380
3879386468098846395020687901479952101341
2027548282097715596894467861905147757309
869866179578945502909067962050691274187
1875962978698022846416892878998731504771
1229074491798847823945909327169945968027
8930021953528948290537103348328206146380
7460353606474648604874778033428507324571
4060297151073747098587058856400970669117
2040862974540041944748218855537604152259
9054477972413785934095705342981436556755
3684093711726975383921248484180680785343
7476814846928616767251978882437648683059
1964929792950495351913680816360894256148
7282131816086441040344851541111411317137
858360220608281955183322211407827063114
6731568128847154877818624762904066433900
4404127488495309183425530944262534390279
5399558298334775245234182714466760665825
8333286439903880070685458991521599138914
2784410216925196061484660881978331927771
4280316660513552865413561707366469584639
2052077815914949195738744151020243107286
3182014142595833930973856766807588447582
4363623109074955107863046926187960535880
4975524281586720079153331768038784297533
2571733328240300928122537848049387911497
9303364525023398593992765937614368609657
4127164093675647698025616953849939897008
996588560618658974740441609298818485447
5343923623326474065005158131348229720525
7662683220245133717224483011370515270755
4396183863814969916183429015401593950027
9102510876135518316390221250165462606656
6850535813541698470280083049370409711384
7881705376373413384581906750678463323398
8284809332794900155436746777675112706667
9586840333471622721268199795651566380237
5221344734981549273564715494103087262794
3796656982793969563092211942988290184843
8688469194884544221204618060859095136307
255153081555984926146651682381510571907
3520691417386910371230184381252798942762
4663038256155251918532425979465632994675
4617326806550721051636181957147381312577
3330113228632723431238189488080479804625
8064026790524309702675905216063130991687
4561511119443191268697450696827022301076
5274535941689672470063589748990814397681
$ ghc-7.4.2 125_predict_the_number
[1 of 1] Compiling Main ( 125_predict_the_number.hs, 125_predict_the_number.o )
Linking 125_predict_the_number ...
$ tm ./125_predict_the_number input
2
0
1
<...>
0:00.03 elapsed
2544 kB used
$ tm python 125_predict_the_number.py3 input
2
0
1
<...>
0:00.03 elapsed
6356 kB used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment