Apakah sensitivitas kasus penting?

13

Tom akan menerapkan bahasa pemrograman baru dari penemuannya. Tetapi sebelum benar-benar mulai mengerjakannya, ia ingin tahu apakah bahasanya harus peka terhadap huruf besar atau kecil.

Di satu sisi, ketidaksensitifan kasus tampaknya lebih mudah diterapkan kepadanya, tetapi ia khawatir hal itu dapat menyebabkan kurangnya kemungkinan kombinasi karakter yang membentuk suatu variabel, yang berarti bahwa nama variabel yang lebih panjang harus digunakan untuk menghindari bentrokan penamaan (untuk contoh, Anda dapat menggunakan Hello, HEllo, heLLodan sekelompok kemungkinan lain jika bahasa adalah kasus sensitif, tetapi hanya HELLOjika tidak).

Tetapi Tom adalah orang yang sangat teliti, jadi khawatir saja tidak cukup baginya. Dia ingin tahu angkanya.

Tantangan

Tulis fungsi (atau program lengkap jika bahasa Anda tidak mendukungnya) yang, diberikan bilangan bulat nsebagai input, menghasilkan (atau mengembalikan) perbedaan dalam jumlah permutasi yang mungkin untuk string panjang ndengan sensitivitas case dan tanpa.

Dalam bahasa Tom, nama variabel dapat mencakup semua huruf alfabet, garis bawah dan, mulai dari karakter kedua, digit.

Testcases

Input (length of the variable) -> Output (difference between the possibilities with case sensitivity and the possibilities with case insensitivity)
0 -> 0
1 -> 26
2 -> 2340
5 -> 784304586
8 -> 206202813193260
9 -> 13057419408922746

Implementasi referensi C ++ yang tidak bersaing

void diff(int n) {
    long long total[2] = {0, 0}; //array holding the result for case insensivity ([0]) and case sensitivity ([1])

    for (int c = 1; c <= 2; c ++) //1 = insensitivity, 2 = sensitivity
        for (int l = 1; l <= n; l ++) //each character of the name
            if (l == 1)
                total[c - 1] = 26 * c + 1; //first character can't be a number
            else
                total[c - 1] *= 26 * c + 1 + 10; //starting from the second character, characters can include numbers

    std::cout << total[1] - total[0] << std::endl;
}

Mencetak gol

Tom suka golf, jadi program terpendek dalam byte menang.

Catatan

Tidak apa-apa jika mungkin dua testcases terakhir tidak tepat karena ketepatan angka. Lagi pula, saya bahkan tidak yakin kode saya menangani nomor 9 dengan benar.

pengguna6245072
sumber
4
Test case 5 tampaknya hilang tiga digit terakhirnya.
Dennis
1
Spesifikasinya mengatakan bahwa hanya angka genap yang dapat digunakan, tetapi output menyiratkan bahwa 10 digit diperbolehkan?
feersum
@ Dennis Oh, terima kasih, saya lupa;)
user6245072
19
"Kasus tidak sensitif tampaknya lebih mudah diimplementasikan" membuat saya berpikir Tom tidak benar-benar memikirkan hal ini ..
pipe
2
@dorukayhan Saya tidak dapat mengomentari pertanyaan Anda karena saya bukan bagian dari situs ini, tetapi bagaimanapun juga dalam hal ini tidak, C ++ tidak dilarang karena kode yang diberikan sangat golfable dan bahkan ada pendekatan lain yang lebih pendek untuk tantangan. .
user6245072

Jawaban:

5

Jelly , 16 15 byte

“~J“6j”OH*"’ÆḊḞ

Cobalah online! atau verifikasi semua kasus uji .

Bagaimana itu bekerja

“~J“6j”OH*"’ÆḊḞ  Main link. Argument: n

“~J“6j”          Yield ['~J', '6j'].
       O         Ordinal; replace the characters with it code points.
                 This yields [[126, 74], [54, 106]].
        H        Halve, yielding [[63, 37], [27, 53]].
           ’     Yield n-1.
         *"      Exponentiation (zipwith); elevate 63 and 37 to the power n-1.
            ÆḊ   Take the determinant of the matrix
                 [[63 ** (n-1), 37 ** (n-1)], [27, 53]], thus yielding
                 63 ** (n-1) * 53 - 37 ** (n-1) * 27.
              Ḟ  Floor; round the result down to the nearest integer.
                 This is required for n = 0.
Dennis
sumber
11

JavaScript (ES7), 43 byte

f=(n,a=53,b=27)=>n?--n?f(n,a*63,b*37):a-b:0
<input type=number value=0 min=0 max=9 style=width:4ch oninput=o.textContent=f(+this.value)><div id=o>0</div>

Bukan reducehari ini - 55 byte.

Neil
sumber
Hari ini bukan harimu, pancake!
kucing
Sepertinya Anda memiliki formula yang salah. Ini tidak memberikan hasil yang benar. Coba 2 sebagai input.
t-clausen.dk
@ t-clausen.dk Maaf, saya salah ketik. Diperbaiki sekarang
Neil
8

TSQL, 41 byte

DECLARE @ INT=10

PRINT 53*POWER(63.,@-1)-27*POWER(37.,@-1)

Biola

t-clausen.dk
sumber
5

Java, 77 76 Bytes

O (1) solusi, tidak ada loop yang terlibat

long x(long n){return 53*(long)Math.pow(63,n-1)-27*(long)Math.pow(37,n-1);}
pengguna902383
sumber
Bagus tapi salah untuk input 0
edc65
3
Salah saya, maaf Tampaknya salah karena Math.pow untuk eksponen <0 tidak akan memberi Anda hasil integer. Saya tidak memikirkan konversi (lama). Upvote
edc65
1
Ada ruang ekstra setelahn-1
kucing
6
yang powfungsi tidak waktu yang konstan
pppery
1
Anda mungkin dapat menggunakan seluruh nilai pengembalian untuk long.
PurkkaKoodari
4

JavaScript (ES6) 47

n=>n&&eval("for(a=53,b=27;--n;a*=63)b*=37;a-b")

Catatan: nilainya benar hingga 53 bit presisi angka javascript.

Uji

F=n=>n&&eval("for(a=53,b=27;--n;a*=63)b*=37;a-b")

for(i=0;i<=10;i++)O.textContent+=i+' '+F(i)+'\n'
<pre id=O></pre>

edc65
sumber
3

MATL , 17 16 byte

37iqY"27vt26+hpd

Cobalah online!

Kasing uji terakhir (input 9) tidak tepat karena presisi numerik.

Penjelasan

37      % Push number 37
iq      % Input number n and subtract 1
Y"      % Row array [37 ...37] of size n-1
27v     % Concatenate 27 vertically. Gives column array [37; ... 37; 27]
t26+    % Duplicate and add 26. Gives column array [63; ... 63; 53]
h       % Concatenate horizontallty. Gives 2D array [37 63; ... 37 63; 27 53]
p       % Product of each column
d       % Difference of the two values. Implicitly display
Luis Mendo
sumber
3

Python 3, 36 byte

lambda n:n and 53*63**~-n-27*37**~-n

Fungsi anonim yang mengambil input melalui argumen dan mengembalikan output.

Hore untuk prioritas operator!

Bagaimana itu bekerja

lambda n:   Function with input string length n
n and ...   Base case: return 0 if n=0

(Case sensitive)

53*...      The first character can be any of [a-z], [A-Z] and _ , giving 53 possibilities
...63**~-n  63^(n-1): the remaining n-1 characters can be any of above and [0-9], giving
            63 possibilities

(Case insensitive)

27*...      The first character can be any of [A-Z] and _ , giving 27 possibilities
...37**~-n  37^(n-1): the remaining n-1 characters can be any of above and [0-9], giving
            37 possibilities
...-...     Subtract the case insensitive value from the case sensitive value
:...        Return the above

Cobalah di Ideone

TheBikingViking
sumber
1
Ini sebenarnya cukup bagus, selamat.
user6245072
2

Pyth, 16 byte

L*b^+TbtQ-y53y27

Coba di sini!

Bekerja sama dengan jawaban Pyke saya

Biru
sumber
2

Faktor , 54 byte

[ 1 - [ 63 swap ^ 53 * ] [ 37 swap ^ 27 * ] bi - ⌊ ]

Uji keluaran (terlalu malas untuk membuat test suite sekarang)

masukkan deskripsi gambar di sini

Ke 100 karena saya bisa:

0   0
1   26
2   2340
3   173394
4   11884860
5   784304586
6   50726849940
7   3244471004034
8   206202813193260
9   13057419408922746
10  825083183338785540
11  52071473691679633074
12  3283878468805254213660
13  207009241705220196670506
14  13046203459736972095009140
15  822081803558828931061964514
16  51797480091236011152730146060
17  3263475325027970876967575323866
18  205607606410125945699743561920740
19  12953599658372394455762938112142354
20  816088635295235866150191568376990460
21  51414022725857535138635748098295218826
22  3239099663712558709867478263942757120340
23  204063879397281956578587897577149556950594
24  12856046623614221305157697924464388847546860
25  809931759486357889731081403194103267502851386
26  51025731268991039110785546457483836346653407940
27  3214622195536403670115403894902928918116194213234
28  202521239965622254844299280697898069287570327415260
29  12758839658766868529390921590771079620628184030477546
30  803806955516821376897030535770307562553491969842783540
31  50639840307096567147692815348943369659664900009235194274
32  3190310017399946085222303356013750037654300219219990995660
33  200989533984152510500958383022988009088751140000471861713306
34  12662340747855976725442649179430749571102940189045387160447140
35  797727471068538170566530927116489907924415111563438806390997714
36  50256830823601535309646277474395913542200557575679083168097488060
37  3166180347299391055374044156331053378848244132513532459112333134666
38  199469362080123926730618942840288463417954913542445303046398068798740
39  12566569818457512122984997355621160915700234281355486142448958342967554
40  791693898836982339089426979801403683342770524668108612843741935926892460
41  49876715636873773150264669144187442239779806356971223086325671695231877626
42  3142233085498371482609012624501672238105982542695761132093804716877601438340
43  197960684400284383047634318675066295949671525651476192195155330966174637087794
44  12471523117731734378801823439793231607942107258123800020604874301575774756008860
45  785705956436110540996146747147743624935526399518788998053580353675424396549238186
46  49499475256178381262627624276616339615439587933192321957328073370569308698667165940
47  3118466941165264455200744360060243571819246756040935041269911532639516601510442382434
48  196463417294374638796889443817231669538334996131822201644459414237154601574451074437260
49  12377195289581232434616009278422739187922835424850800583245777641132746959324266250272346
50  779763303244935960426051634304306897098424666501802506291342869526467319662381170513981540
51  49125088104479743237515245802427284662794337274853034469588379271166298804053252422013315474
52  3094880550584028599998398220679389089143005829869601804793717698250434558272314733733240577660
53  194977474686860578513191784102480908365326982799277757130761257743954813314983341977611019396106
54  12283580905274687184722912157844434869740351690501733906101969819773718376165568553428918153085140
55  773865597032396709958041167041560489574457972145056938738392490176213167779330685193080529096190914
56  48753532613044375168215008464220671276081037423946152138715557367728779243091128221265244694777630060
57  3071472554621920785909306886048189626410042209324487489672362842172125030215492994941453756154541985466
58  193502770941185640073821503874720577896459322697230268331890319993036718605903879610376090231927542876740
59  12190674569294866655427556036093727770484123879787646494762754214200448415158073789829080317596516919552754
60  768012497865582938530677678077399109971765706771520893994639085516276250445445435611121365429028589509594460
61  48384787365531959679266134687605431564178077913367085420171928478326379788811073557020550322585378011481976426
62  3048241604028522138211603801162125831073621928852293338115689139494198039092774045292531129443472159001332956340
63  192039221053797215808791020159404322131263093269170657697148148666441012621558792067838210142400699755368808584994
64  12098470926389236476707853555431516900893696610762369998567143482483125633030622907206930951507336372904773737270860
65  762203668362522337620493487551580215201395390665800196764662013706838562882208746410562227308797606160712680915464986
66  48018831106838923534843342117447155624156332266892935209806189913015690437626492644356866682916159530830240509968123940
67  3025186359730852784490963892261982080781180571047313262322191837350928353684220676552666116434808733122402791782863511634
68  190586740663043747689376558750428888318209646590603894258160955047853260958314713301270755405603305445874988549550654259260
69  12006964661771756928289219042180208601520032747949102211343066331920312103393552933082810823150791387679177947309210580307146
70  756438773691620716964985145770771121482256588592212543618533446975485259045523696603018951464617833773583196421918482952379540
71  47655642742572106296656344989755045898082462523751897107212657077842278391541997773285863117697288652678155847014078432541996674
72  3002305492782042738420254124183837105633106144366742271546464242884371700319084040546949135905704694741593153841915859492202959660
73  189145246045268694064519472247264698574880394293808554997733720639986819101224007245165566663218089624766534104801769122964901718906
74  11916150500851927783194334861253945564257269006861979264798563913835211476678615826001618230525611319033999768874671043820165072923140
75  750717481553671452455038596317020544047680701587330184780139088571711872342908421711680887160599764988069185889174180556385321385544114
76  47295201337881301582877865070119107294484376103737744811768456374021309282152988680758316620704776514138665127670559852493727353570572060
77  2979597684286522002615091538996935841273293894973707820454341421941470553783979337065903514099119599226677240459390970372438551207353876266
78  187714654110050886271820850421245945023886308799558098889201870386303383441699317091742715367049125868210495633339022021080976659562384154740
79  11826023208933205839086306664722737056380582810772096959441117184084770483299475874473650445339864801023664915823061850169943403091896529897954
80  745039462162791968009016264140349407787379295265439767433382158538003861527346479306512775013394967703567826260992924685854583715749735525096460
81  46937486116255893989991445578566240700314790994634218730880971697698786156163569667253198313252271919170619707315735295839320298967762741317515226
82  2957061625324121321570127646145469600479097962199681775200883358217791614396112323461838552769003522200045367717199022141204995255363640622751674340
83  186294882395419643266342704970909052975476018411475813658404790794443290909593951451816650008709306376417822233966923239519043908642509112264039442194
84  11736577590911437526054302953925815658830824491260123147847219971438656837802057319192119334366383427393476471247901403340755546923998264934769791332860
85  739404388227420564151585450105392563397247850208862193146980429802018372669942231085027322266336949575917703497413242262756663341354137752789503193531786
86  46582476458327495541925964824938180038990133131758872257066173226778328178077627497465902058225655188337576695262466055088365154255573819716001935756281940
87  2934696016874632219155250798298147938620028574339029453481005940809327991114127409087391517619734089372293502673776337794350733176860886869847861631505600834
88  184885849063101829807295655822883896191116857103773014116879344289312516128313791212146134064249406693214458990720825405024094143116346113226785650902666881260
89  11647808490975415277878675971455406774188399103593023755623709580904708065544348130631903778853340506994629744339509897103777855276371884029063199627227132581946
90  733811934931451162507061423422398315397346516450407479655925206552083331459335365747677739381568683697580070526580745691266622080032985612974682610468596757977540
91  46230151900681423237970948652777278349101493334565409591233653622119458645149661082264806229649731647953525118602676998977756027354075699625721942715793229749237874
92  2912499569742929663993134687280117361718934603610641124045403705739039618883255370668643812466536563096293367462807981691433106666850680498728209106577023932078141660
93  183487472893804568831603187418387900340137879398192142647374723980743503786481677084105117925340131838249669694817958084526161366922717594045263062187188374662340681706
94  11559710792309687836392321785788836463846951378802809804587636359996649027031299439381903065674516455247507129925990403129885565051842823161990850791287794680559919961140
95  728261779915510333692765148706621450691833741003095095947733154400551795376841154655141276683483798209790732933978380017958074358887427604479576881170443366718075867057314
96  45880492134677151022646012787988367271956130436320159940279535084902990655674156472314911622261081963797134173540354372100044183752897139657357014922552487271422413276314060
97  2890471004484660514426765717163702125632948593353801325373787525582612830543998915730356846276907462752691218884931833388144147044723120219693807782246945239322406481520807066
98  182099673282533612408888715907569328452365119288317839716587156275352411836023432836069625636200164217658002129970617297449211712144308789428081576440224676102555002804992632740
99  11472279416799617581760080704048343190386108757724073082212416905402170675604281811039500754948545126089276981776285626117157164453181285710701891703604838257394970772074262003154
100 722753603258375907650888473624290214416147782711338423841877029262370595570657559163071778136871929817566895212667053691361603944309744782913331015678320105744441365668988373398460
kucing
sumber
Itu adalah bahasa yang tidak pernah saya dengar. Apakah semua ruang itu benar-benar diperlukan?
user6245072
@ user6245072 Saya menautkan bahasa, dan ya, spasi diperlukan :-)
cat
@ user6245072 suka angka besar? : D
cat
Saya lebih suka desimal uu
user6245072
1
@ user6245072 Saya harus mengakui - kesalahan kompilasi bisa agak sulit dibaca ketika Anda salah ketik ...
Toby Speight
2

dc, 19 byte

1-d63r^53*r37r^27*-

Ini hanya perbedaan dua eksponensial 53 × 63^(n-1) - 27 × 37^(n-1),. Kasus khusus nol jatuh secara alami, seperti yang dcdimulai dengan ketepatan 0, yang berarti bahwa x ^ -1 == 0untuk semua x positif .

Seperti biasa untuk dc, input diambil dari atas tumpukan, dan output didorong ke atas tumpukan. Untuk program lengkap, lampirkan di antara ?dan puntuk membuat filter pipa.

Uji keluaran

$ for i in {0..30}; do printf '%2d -> %s\n' "$i" `./85108.dc <<<$i`; done
 0 -> 0
 1 -> 26
 2 -> 2340
 3 -> 173394
 4 -> 11884860
 5 -> 784304586
 6 -> 50726849940
 7 -> 3244471004034
 8 -> 206202813193260
 9 -> 13057419408922746
10 -> 825083183338785540
11 -> 52071473691679633074
12 -> 3283878468805254213660
13 -> 207009241705220196670506
14 -> 13046203459736972095009140
15 -> 822081803558828931061964514
16 -> 51797480091236011152730146060
17 -> 3263475325027970876967575323866
18 -> 205607606410125945699743561920740
19 -> 12953599658372394455762938112142354
20 -> 816088635295235866150191568376990460
21 -> 51414022725857535138635748098295218826
22 -> 3239099663712558709867478263942757120340
23 -> 204063879397281956578587897577149556950594
24 -> 12856046623614221305157697924464388847546860
25 -> 809931759486357889731081403194103267502851386
26 -> 51025731268991039110785546457483836346653407940
27 -> 3214622195536403670115403894902928918116194213234
28 -> 202521239965622254844299280697898069287570327415260
29 -> 12758839658766868529390921590771079620628184030477546
30 -> 803806955516821376897030535770307562553491969842783540

Kinerja masuk akal untuk n kecil , tetapi mulai berbelok begitu mencapai beberapa ratus ribu atau lebih:

   1024:   0.00s
   2048:   0.00s
   4096:   0.01s
   8192:   0.04s
  16384:   0.12s
  32768:   0.38s
  65536:   1.16s
 131072:   3.48s
 262144:  10.41s
 524288:  30.63s
1048576:  93.70s

Contoh terakhir itu memang menghasilkan hasil 1941435 digit, jadi mungkin tidak terlalu buruk untuk semua itu.

Toby Speight
sumber
Berapa ukuran angka-angkanya? OO
user6245072
Maksud saya, dalam implementasi C ++ saya menggunakan integer 8-byte, yang dapat menampung hingga 2 ^ 64 nilai, yang cukup sedikit . Tetapi sudah gagal menghitung testcase 11, karena hasilnya melebihi kapasitas byte tersebut. Jadi, ukuran apa yang dihuni angka-angka dalam bahasa Anda, untuk dapat menyimpan hasil testcase 11 ke atas?
user6245072
1
dc menggunakan aritmatika presisi sewenang-wenang, jadi itu hanya dibatasi oleh memori yang tersedia (meskipun itu mulai melambat setelah n mencapai 100.000 atau lebih). Saya akan menambahkan beberapa angka.
Toby Speight
Kerja bagus, bung! Saya hanya melihat-lihat untuk melihat apakah dcsudah digunakan ... tapi ini tidak dapat dikalahkan!
Joe
1

Pyke, 17 15 byte

53[DT+Qt^*)27[-

Coba di sini!

  [DT+Qt^*)     - [ = lambda a: a*(a+10)^(input-1) 
53[        27[- - [53)-[27)
Biru
sumber