-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgooglon.class.php
217 lines (181 loc) · 18.1 KB
/
googlon.class.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Provinha de Programação - Google Developer Day Brasil 2011
*
* Arqueólogos encontraram um pergaminho com os seguintes textos:
*
* Texto A: vbmgc kvb bvp hcnpt klx lrsf hvpdm qptxdvv hxfmj pzsvfz cztphth tznl hqp zlphnj ktcflzhv stcrrdml wwfdkfr xtcjnqx xhtwdx bng mkhcltkv ngvhgcs mbdrh hzdhjzrs fgqwwn rkkg rvkvv pxvqjlgw rmwp vzbfvfj lqp drlz xsflsfs ksphpdgf fcj pmwz jzmvvz xpzwzkj hxqpnx qmqmgdjg wprtjcw gzw qxbnqc xpgsm pjwdnjsv lxspvzs mlm prxssdzj wbggs brrzlmt gmn gbswjrn vvmqhlh pwmkf vhx fgnfvgv xrtvfjk gknlj mzvwdnpq xwcxkrwk hlxth ljljnfm ckpcx gcm nrd hzsmwl hzkqjx rsnn bcn zwtbsbpc dtf fxmg nwd fwfdpdcq wvt zscfjkls rrr tzdf xcxrnxx dsm sssdhz dcgbtd nzdgbfj ksldpm zwwvm pzjftvpz xsfk bqrlzk zrlktljv djmgslf pskd jhx lxjj ccvxtn bmglc jqxnz fmgcsq lkvmwgd stvftslx tjrhm kmmc jpxfc dmlttwr czqbj mhtv wmdvnv fnhkcftn klzlgdj pjpkrh dxssj rhvf rczrhs nfwbkt vtfwzl frgk xxxx bttrt dljrm xvv gtvkjk gzzkh wxsrjjc gjpmr rfmrnn cvf pdptb wzffvpkn dsj kwzcnwz lpsqgn cgbdpjh szcnqncp ppmvd nsgkpbcs pgblh kbv mgfx hmhtjq fwwxsbjc kzs tsksjkf jmtljb rtht wwgmhw klj ssf khl sjnz lchfw rndjkd wnjrwt hpwzk prkg pjc pzcx hwbknxgn ncdmr qjgkzdtd lkbdz tjdsz ntjg bjt pspwbr wnrd nxbwprnc vwvm bzhsbth gqbtpkb qmbqkblr vjh jrqjs plxqlv lntkhwx klkc xhjgm dqcpqzbw rhkzznmr fxspz mvsrwkc hcgr rqtbc mrnnz kgpb ztlp qdvj msfs ljfq hjtx qltdms xjpvvclw qfmmp qrhhfbvf hnlgzng rbmhdtq mvzmnmqw pvmjbh zfhmwsd cbhlgnhp fvdnrctj djzzx dcdlktm lllzzj hhqvs lwf wphcsq swzgfl btzzxm vpgr qwsbsvs wzgj zmr qfqh vklhsnvs przf zhgml vzds rshsf nwqqnjkq tmzq zxc stp zbkxhpbr gdcnbq zgpxccp zsvgrrkr kkrwxp xsljrsf wplw dkbk jzgvsrtz nmdvqfk wmgh qmv bzzbrtks tsj rbbjw hvrzqg sfpbd zvtjvmv rwmbw pdb jzwmwwq dqvf qzbdxs mtb drfpdz vhcls wstsfpl sjdh qpkjl fcdp lgbwhp ghpv qszhnl mhz rrsptlbh wmmjg nrqdhch gqhd zmqkb tmsxtc bpmkg bjgqnsnl dlfh nrjhgz jmdt bcpsgkpt tfz htnvbf msq qvqrmkm ptcctdjz lgnlfj tqwmbvd lfbstj cwvdgm bkrhffgt bjwddmg xcd qmpdvmt rdn dltnrq jkscl jbmct cgzgbqf tndz xwdkxv thgxppj grn wvqtj qtdstx mvpxz mflwmfbx pzmm ljv pwnzmtk wsp lznxx wzdwk cmbpcn fxczhkp cbgxbgjp hjv pplwqzf kbbhmrpt rbjr thsk ldq lcwx skvjwpb gtqjqg tndlp fdvtnkfc hjndwwdz tlr jzht wblvm jtn pmh wfwlfb wlpr jbm lvttwtvq vms vbhr lppkl lzj rklmmsn mgwwfck fhkxwfvg nbthqd hqvsrdf xswjkchz pbhgzd sgz tjqgxmv sqlcfkbc lvxkghw nlsmfds jvwh tvsfd bsdktv gnsfxq wcjdqmx hvlhb mqbq dhrk mvj cdzmnw mwfqhlln szmp nllxdlhx fplhghlf ksdpx jwzhtvkd cwstmnx lhnmjq jctvs cwd xwvwt bvbqwrq jdt gnfg dxdghj rtfhbnm lfbq hkhbsqh jdjrxw ltn hrb chn gltrdj lqtjf nltbmh rdb zptp vjf tqrcvqr cfdtvzx wfq bsnj nwr mkw bzznnzdd vgtkrq cfsm kcbsksg wbmhtwq znrjr bmlvkzw sstfprlj vjznkbwr sbkdvf pwtgxpx jpbwsrn vxrhk fkcllw lxg btdpjlz gzsppxlt hbrpf jxshqrg lgv xldq jslszfzj bpdjhw ntkbf bzfgb xfkqvggj ldmwj gpwwp fwqfjz rlnkrjp sbkxjfvs pwqntn xlhqbhtz ksjjpmzs nnqnrdch rdmr mpdcqkxr krjq xsnbvpn flhsq dhvrscbd nnrthfcl tpcndct gmtnxzwm ljclsq kbz gcgcj mnvrbq cjm lnfmqdj sxlt crsxrlbt tdq cktrvqpv qmbp mxjzpr zmvsx dqwhpt bvrhpc vhn mpnhbnxb gnhkkglf stb whbcwc bhgwng rzxdmr gnxlzb hkc lpchg pfvqq mtjjpr bzblj csmgwjbl dmjn zqtctfx zztgvdl lsjvntbw fnw bpfbcgz vqfslkfz rwh fvw wpbcgz nhtgzhd gbhcfmmm dtldhxr sqct jdrjkxx vvm mnntj hhdlbrp jgsp fxxzt qvhx nqmmncx qfjmb xbrgcwg nns fpm dkcmhjlh pqgrt tckjwx vxc vjkvxhfc lmxgkk cnqr lmz wgxhf vnzhw zxxhksnl bjnnqmfj vldprhqx nkwkfn vwht ltrprnm pjf fhkhkrv mmrjz vtrln dpxndgk wsjw pdhm lnrmmhd jjqvq pcnbmq cdgkxkd njzc qjxvvn jkxr gpjk ksfkv jfgjdk tjcsh jwp hnv zccjp thfbvklf qfkc wzrq lksmjbwq qktmhz tvw nbhtcrt wlhz gth gzsmq wtf bqj hvdn jkjw bhpc pwklgdl tcjb dmjqjxpw rnbsb lctp nshlxtl fxfhwp fdfpzn ncllht xldlbzb gqlpxhr hvtbdmqw gvncb fxvj gjbbwh ktxctzbv bpklgmnf wrz rnknfh wxl stlndmw pcdbfhlh bjjbpztg kxtmmktl dzfw zvjgrlzt zwdptkz vrkf wqk qvpn ztcs rxm tmt whlhvg jpzd jzlxj fwhw lkdms bvfvlvjp bqw gntdd gwcv bzdmstvv zclngtpl qhbdzd bbljd xfrfj kwlnmzgk xgnxwn srhcp cqcvsb kfbfhtx rlsqvn gmjjgxbd vmwpf tgt kvl ljkgrqm zzd hpsc hsgv rhg rxgkltrf jmksrk qqszr xrhtkgw
*
* Texto B: wvpst cjddzdld dzxm kft trhd jvngf zwdg cgtjgjp lplbjvw snk wnl scqqkc gqcvhkd kwtvrh wtwwkbw jfck gkrkd ddv dbglbshj sbr mdgvsmjv tjjwj shwlgjg tlpr qvwrv jrj hsh flgjp dkl ljbhw bmqqd nmsr vcpvjb cqbghtzb vfzfxg jkkjnfk nmmdhhcl npfxfhw qqxpvpgc hrtjsscq hxptlcf cqthmg qkcs vsqhptgm ltxm jtxch ggxgwn fxlczgkw kfmc tjlqlctg dmnlgd pdd hkl sqcxqpxc fvppbvs pdsqnf ltzqglb gdplqmtz hhbgq pkb dzp vkngzb hfrgx rjvznmgc mvwvn kxgqcjs hhfp lmps dpsckgzt vspffcgb nqcl nxqxpwn ztljgn dmfm lpvbpx clhs cjjxgt xgtrmdc xqblrgg gmdg xkpvclcc qbkghf cdzmrcc lfwcxt xlgxtdc gfrnb kzpr mngsp czv zzcvfch vcnhjq rbfgcmkp bpfhr rqf rxntbp kshcw wtchl pvn lztf ssfzj fpsnkdv fzkq fxrrk kmrkgj wmxj bdscpxrr xpsbzbqd fhpf wfjrfmb wqpdgq pdfkp cxsqlbz hlrpc pxbgv xbzkfgh cfskpq fgknxqx cdr tcn qtxkjgd bwbnfgb mkdzxm ckkbcd ncrhz lzh lsslkdq sxtcr bww hndgqsq pskqssx qnk jlgxlt hdgnmg kzppgt mdcg mdt ggk xxwcrbb xcnrbj gvztrwmw kcswscjf qrjhvxhw krgw wgwxprwp wrfxql rmqp zkdm hkk rvnhgb cdgvsq hqdcvgzs hxx tsck pvcwpgt mct bsrrqwvp vtwp bjjkpnjg sqgkdl jggn bflpzs hllb hlskqn bmgj dmjbfjp bwx czwpwg qpszhx khsc wcgw vmzjng zqrqfvs fqdqqnq shmcb dxbkc jsz vgl jgsdsp dbbcpfzd kpsz cntvb nkcknfj sldflc hrbqr tkb bvcj wsqwvvgp ptblfrhb pdp nqjrs vzb qdxlkgvv qlqb tmfxcvm rqgwngj vtm znlgphlx rgzj qnhtbj mjffbmwh jjmc qtm xwqvgk dsbltfmz cwmsvdv qmfbq zvvfdqtl sgtn jlx bfqbmjf gvvxmnmr psprjkhk ckqzlwm pbsshb srs wzhpcnm gxxmhd xjp rkvzwdc lpngb wrfjhxjp mhr cfrgdpj bhj zqrgxpb ljcbln mbvc stfglgwj mjfrf gdssxxd xfknb nncnn fndfnqm shnbt qxpqmqv tqpzxrr wwprkv kjgc bgqjv nmktkbgk prbd kmnsmn lwhhwtkm wjjdq fwbcj gtbh hkvqngnn xzhrvnrg mkhbsflz jblknqn nrdqc jjzwdxhv jzkv nzl mzlql llwmkmd bzcx jntm kdf nrmspwcl kjfpf glbj ghbj hzcw rcwxq bfrmm rpshczcx rrvvn wmfg fmjckhqt zfvbzg pzlmj nmw tczsg fmtn jhrc xgq jtxrxh mgzglftz ssljnxxl tsfscc nhgpb qhxmnbzp zxdbsd rfq qhj mdpppc vfzhs xzfkfsts rthw xnrrr ggkzw smd ntxp bhbrk wnckbt rpw hqrxv jxdhft ttsrvzx mbgkd sjwqvpd kknr gbp szsgnxpb wqhmqgr tpzmvj gxzgdnm vwv gspvk mhkq pcvdjk dffnvkj vvnfppc wxcskn wblpndpn jsj bgqrxrq jrjvrwr cpcldr lkvhhgg rmvf kgxb dstqjdrm qlspg hhmmdcrz vcxr sfnrlb wqlmgt lsjw bqbwz qmmhtkt wfhcpz qhh tljrf qzpcgxv ftvhdpv jqpbnm vxrm tmmvc fgqrxpz wwvbtgzt khrml kdd wbpbrg npdhkk rvsg ddmm nsvbzh ltkmsvzf vgpdqgpj sqjl hclt jxt twtqptl zmdz kwk xjrnv tgpcxpn glhkvbt bmzt klk snsn jwvdnfd qmcm dcbt brx xknjsk dqtxrql kqlvqfg tjbhbtt ksp snppz sns xlg wfp nfjqsqj sshzcs cmzldf czf mqpm hbcrp khqqc lrbzjgb txb qpmkb nzrvqt zhngbr khkrn xrs cnfztchg plkjnthl sln bqf vpnpnw fgzdv hzslkklk zfhvscr vsmpjh gljl xphhwdgk hlsm htnjlrhz nkdlsmsk pbfbfk bjsl blxfv hwwbbs kpjd smvbk bqswqbv ljmzvlr ftd mptvwsq xzx sbqww zdhkqf gkzs pfhgd zkjr gpp xqsscwsw nljrkpr vssv ddwxls tsphzr vhmzb fwxt rwmtcll ppvqsw xbqbjw zwcmttgf pjr zmkqnn nzc lnkx fmkxgvk lckgjcl zdmncbsv xwpxh pcrkwcb jdglvtl dlwsmg gbjl cwzdxtgh ckv fnkjm lzrmkpgq zpkjtqm zbftbrz bqzfprlr vnfrx cpstccv tnxrtvrg bsn vhkrjj zhpvfvgb vljwq xzcksvv lqqd rtsrd qjpw scjjq vwfpwl gmklwlxr hbwtz rfvghqbm lfblglhw dnw fsfphg cgdh hlwxfdcz lsksc tgtsr clpvdp vdpgrs jlrgpt crlgtt lddl kpz frdw qjwj ttv rllszscw plthwcsh dpqvwn jjfz cvk ssdwx ltw ncps vvvpcz rtj kfwqwnvs txs zdbwqtwb rwffqvs qrfkbrb mcjzxh vmst zzmnwsw phsczzpp hgpmx dfl swhgzj xtzgxh szh gnfr kgjhrjzj lmnbbg flb vmkkhz ztwkkp zxj rcszjnd jtpj nmlfkhvl zqkmv rjf wwfwgzpq srv nwvdnxvx kbjpzlgp plltgq gwkwmht wmqlnrg klrlt kbblmv dtpdbs dxvmrncn gxbn nmsqmbtd mjgvdwgd nvhjntr xpqqb gjdz dgbtbzsr cwn lzwnqbwm trm qxtnrr swhs nxcwvgnc qvxqp vgkwhd gwv lwb zhdxslbc kgj nfphzjn ftzfl fhwdhsn xcbcx brxsjbp lfqtd hddgvkv prvqxrxt gvjjvxjw bzpt tfs flzds qhvmb pdzlxdn zbjltz kpmmsdp svnh mtw xmt zwrkbbnk pgmsw dbqz skrms xzl gpr rgstb rkpmc lcr xfhx xbt gqb lsjht gmcnvmg dzvzpgtr jxn xxrzmhkx ftd bxvnr gvdjg lxph jvdprcc bprkctdj lxdvvql rlmxvb njk swmj lqjpvfsj jxkbc rprbnb hfbf wtfcw
*
* Esses pergaminhos estão no antigo e misterioso idioma Googlon.
* Após muitos anos de estudo, os linguistas já conhecem algumas características desse idioma.
*
* @author Matheus Oliveira Pedroso <[email protected]>
* @link https://developerquiz.appspot.com
* @link http://www.github.com/mathop/gdd2011
*/
class Googlon
{
/**
* Alfabeto latino e googlon.
*
* @var array
*/
var $alphabet = array
(
'latin' => array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t'/*,'u','v','w','x','y','z'*/),
'googlon' => array('v','r','x','w','f','k','p','h','q','l','j','c','n','s','m','g','t','d','b','z')
);
/**
* As letras r, x, w, j e m são chamadas "letras tipo foo".
*
* @var array
*/
var $foo = array('r','x','w','j','m');
/**
* As demais são conhecidas como "letras tipo bar".
*
* @var array
*/
var $bar = array('v','f','k','p','h','q','l','c','n','s','g','t','d','b','z');
/**
* Os linguistas descobriram que as preposições em Googlon são as palavras de 3 letras que terminam numa letra tipo bar,
* mas onde não ocorre a letra l. Portanto, é fácil ver que existem 61 preposições no Texto A. E no Texto B, quantas preposições existem?
*
* @param string $string
* @return integer
* @access public
*/
function countPrepositions($string)
{
$foo = implode('', $this->foo);
$bar = implode('', $this->bar);
$bar = str_replace('l', null, $bar);
preg_match_all("/\b([$foo$bar]{2}[^l$foo])\b/", $string, $prepositions);
return count($prepositions[0]);
}
/**
* Um outro fato interessante descoberto pelos linguistas é que, no Googlon, os verbos sempre são palavras de 8 ou mais letras que
* terminam numa letra tipo bar. Além disso, se um verbo começa com uma letra tipo foo, o verbo está em primeira pessoa.
*
* Assim, lendo o Texto A, é possível identificar 75 verbos no texto, dos quais 12 estão em primeira pessoa.
*
* Já no Texto B, quantos são os verbos?
*
* E quantos verbos do Texto B estão em primeira pessoa?
*
* @param string $string
* @param boolean $firstPerson
* @return integer
* @access public
*/
function countVerbs($string, $firstPerson = false)
{
$foo = implode('', $this->foo);
$bar = implode('', $this->bar);
if ($firstPerson)
{
preg_match_all("/\b([$foo][$foo$bar]{6}[$foo$bar]*[$bar])\b/", $string, $verbs);
}
else
{
preg_match_all("/\b([$foo$bar]{7}[$foo$bar]*[$bar])\b/", $string, $verbs);
}
return count($verbs[0]);
}
/**
* Um professor universitário utilizará os textos A e B para ensinar o Googlon aos alunos. Para ajudar os alunos a compreender o texto,
* esse professor precisa criar uma lista de vocabulário para cada texto, isto é, uma lista ordenada (e sem repetições) das palavras que
* aparecem em cada um dos textos.
*
* Essas listas devem estar ordenadas e não podem conter repetições de palavras. No Googlon,
* assim como no nosso alfabeto, as palavras são ordenadas lexicograficamente, mas o problema é que no Googlon, a ordem das letras no alfabeto
* é diferente da nossa. O alfabeto Googlon, em ordem, é: vrxwfkphqljcnsmgtdbz. Assim, ao fazer essas listas,
* o professor deve respeitar a ordem alfabética Googlon.
*
* O professor preparou a lista de vocabulário para o Texto A:
*
* Lista de vocabulário do Texto A: vvm vvmqhlh vrkf vxrhk vxc vwvm vwht vklhsnvs vpgr vhx vhcls vhn vqfslkfz vldprhqx vjf vjkvxhfc vjh vjznkbwr vnzhw vmwpf vms vgtkrq vtrln vtfwzl vbhr vbmgc vzds vzbfvfj rvkvv rrr rrsptlbh rxm rxgkltrf rwh rwmbw rfmrnn rkkg rklmmsn rhvf rhkzznmr rhg rqtbc rlnkrjp rlsqvn rczrhs rnknfh rndjkd rnbsb rshsf rsnn rmwp rtfhbnm rtht rdn rdmr rdb rbjr rbmhdtq rbbjw rzxdmr xvv xrhtkgw xrtvfjk xxxx xwvwt xwcxkrwk xwdkxv xfrfj xfkqvggj xpgsm xpzwzkj xhjgm xhtwdx xlhqbhtz xldq xldlbzb xjpvvclw xcxrnxx xcd xswjkchz xsfk xsflsfs xsljrsf xsnbvpn xgnxwn xtcjnqx xbrgcwg wvqtj wvt wrz wxl wxsrjjc wwfdkfr wwgmhw wfwlfb wfq wprtjcw wphcsq wplw wpbcgz whlhvg whbcwc wqk wlpr wlhz wcjdqmx wnrd wnjrwt wsp wsjw wstsfpl wmmjg wmgh wmdvnv wgxhf wtf wblvm wbmhtwq wbggs wzrq wzffvpkn wzgj wzdwk fvw fvdnrctj frgk fxvj fxxzt fxfhwp fxczhkp fxspz fxmg fwwxsbjc fwfdpdcq fwhw fwqfjz fkcllw fplhghlf fpm fhkxwfvg fhkhkrv flhsq fcj fcdp fnw fnhkcftn fmgcsq fgqwwn fgnfvgv fdvtnkfc fdfpzn kvl kvb krjq kxtmmktl kwlnmzgk kwzcnwz kfbfhtx kkrwxp khl klx klkc klj klzlgdj kcbsksg ksfkv ksphpdgf ksldpm ksjjpmzs ksdpx kmmc kgpb ktxctzbv ktcflzhv kbv kbbhmrpt kbz kzs pvmjbh prxssdzj prkg przf pxvqjlgw pwklgdl pwqntn pwnzmtk pwmkf pwtgxpx pfvqq pplwqzf ppmvd pqgrt plxqlv pjwdnjsv pjf pjpkrh pjc pcnbmq pcdbfhlh pskd pspwbr pmwz pmh pgblh ptcctdjz pdptb pdhm pdb pbhgzd pzjftvpz pzcx pzsvfz pzmm hvrzqg hvpdm hvlhb hvtbdmqw hvdn hrb hxfmj hxqpnx hwbknxgn hkhbsqh hkc hpwzk hpsc hhqvs hhdlbrp hqvsrdf hqp hlxth hjv hjndwwdz hjtx hcnpt hcgr hnv hnlgzng hsgv hmhtjq htnvbf hbrpf hzkqjx hzsmwl hzdhjzrs qvpn qvhx qvqrmkm qrhhfbvf qxbnqc qwsbsvs qfkc qfqh qfjmb qfmmp qktmhz qpkjl qptxdvv qhbdzd qqszr qltdms qjxvvn qjgkzdtd qszhnl qmv qmpdvmt qmqmgdjg qmbp qmbqkblr qtdstx qdvj qzbdxs lvxkghw lvttwtvq lrsf lxjj lxspvzs lxg lwf lfbq lfbstj lkvmwgd lksmjbwq lkdms lkbdz lppkl lpchg lpsqgn lhnmjq lqp lqtjf lllzzj ljv ljfq ljkgrqm ljljnfm ljclsq lcwx lchfw lctp lnrmmhd lnfmqdj lntkhwx lsjvntbw lmxgkk lmz lgv lgnlfj lgbwhp ltrprnm ltn ldq ldmwj lzj lznxx jvwh jrqjs jxshqrg jwp jwzhtvkd jfgjdk jkxr jkjw jkscl jpxfc jpbwsrn jpzd jhx jqxnz jjqvq jctvs jslszfzj jmksrk jmtljb jmdt jgsp jtn jdrjkxx jdjrxw jdt jbm jbmct jzwmwwq jzht jzlxj jzmvvz jzgvsrtz cvf crsxrlbt cwvdgm cwstmnx cwd cfsm cfdtvzx ckpcx cktrvqpv chn cqcvsb cjm ccvxtn cnqr csmgwjbl cmbpcn cgbdpjh cgzgbqf cdgkxkd cdzmnw cbhlgnhp cbgxbgjp czqbj cztphth nrqdhch nrjhgz nrd nxbwprnc nwr nwqqnjkq nwd nfwbkt nkwkfn nhtgzhd nqmmncx nllxdlhx nlsmfds nltbmh njzc ncllht ncdmr nnrthfcl nnqnrdch nns nshlxtl nsgkpbcs nmdvqfk ngvhgcs ntkbf ntjg nbhtcrt nbthqd nzdgbfj srhcp sxlt swzgfl sfpbd skvjwpb sqlcfkbc sqct sjnz sjdh ssf sssdhz sstfprlj sgz stvftslx stp stlndmw stcrrdml stb sbkxjfvs sbkdvf szcnqncp szmp mvpxz mvj mvsrwkc mvzmnmqw mrnnz mxjzpr mwfqhlln mflwmfbx mkw mkhcltkv mpnhbnxb mpdcqkxr mhtv mhz mqbq mlm mnvrbq mnntj msfs msq mmrjz mgwwfck mgfx mtjjpr mtb mbdrh mzvwdnpq gvncb grn gwcv gknlj gpwwp gpjk ghpv gqhd gqlpxhr gqbtpkb gltrdj gjpmr gjbbwh gcm gcgcj gnxlzb gnfg gnhkkglf gnsfxq gntdd gmjjgxbd gmn gmtnxzwm gtvkjk gth gtqjqg gdcnbq gbhcfmmm gbswjrn gzw gzsppxlt gzsmq gzzkh tvw tvsfd tfz tpcndct thfbvklf thsk thgxppj tqrcvqr tqwmbvd tlr tjrhm tjqgxmv tjcsh tjdsz tckjwx tcjb tndlp tndz tsksjkf tsj tmsxtc tmt tmzq tgt tdq tznl tzdf drfpdz drlz dxssj dxdghj dkcmhjlh dkbk dpxndgk dhvrscbd dhrk dqvf dqwhpt dqcpqzbw dlfh dljrm dltnrq djmgslf djzzx dcgbtd dcdlktm dsj dsm dmlttwr dmjqjxpw dmjn dtf dtldhxr dzfw bvrhpc bvfvlvjp bvp bvbqwrq brrzlmt bkrhffgt bpfbcgz bpklgmnf bpmkg bpdjhw bhpc bhgwng bqrlzk bqw bqj bjwddmg bjjbpztg bjnnqmfj bjgqnsnl bjt bcpsgkpt bcn bng bsnj bsdktv bmlvkzw bmglc bttrt btdpjlz btzzxm bbljd bzfgb bzhsbth bzdmstvv bzblj bzznnzdd bzzbrtks zvjgrlzt zvtjvmv zrlktljv zxxhksnl zxc zwwvm zwtbsbpc zwdptkz zfhmwsd zptp zhgml zqtctfx zlphnj zclngtpl zccjp znrjr zsvgrrkr zscfjkls zmvsx zmr zmqkb zgpxccp ztlp ztcs zbkxhpbr zztgvdl zzd
*
* Como seria a lista de vocabulário do Texto B?
*
* @param string $string
* @return string
* @access public
*/
function listVocabulary($string)
{
$vocabulary = $this->convertString('googlon', 'latin', $string);
$vocabulary = explode(' ', $vocabulary);
$vocabulary = array_unique($vocabulary);
sort($vocabulary);
$vocabulary = implode(' ', $vocabulary);
$vocabulary = $this->convertString('latin', 'googlon', $vocabulary);
return $vocabulary;
}
/**
* Converte uma string de googlon para latin e vice-versa.
*
* @param string $from
* @param string $to
* @param string $string
* @return string
* @access private
*/
private function convertString($from, $to, $string)
{
$letter = array_combine($this->alphabet[$from], $this->alphabet[$to]);
$letters = str_split($string);
foreach ($letters as $key => $value)
{
if (isset($letter[$value]))
{
$letters[$key] = $letter[$value];
}
}
return implode('', $letters);
}
/**
* Mas como os Googlons escrevem números? Bem, no Googlon, as palavras também são números dados em base 20, onde cada letra é um dígito,
* e os dígitos são ordenados do menos significativo para o mais significativo (o inverso do nosso sistema).
* Ou seja, a primeira posição é a unidade, a segunda posição vale 20, a terceira vale 400, e assim por diante.
* Os valores das letras são dados pela ordem em que elas aparecem no alfabeto Googlon (que é diferente da nossa ordem, como vimos acima).
* Ou seja, a primeira letra do alfabeto Googlon representa o dígito 0, a segunda representa o dígito 1, e assim por diante.
*
* Por exemplo, a palavra vbmgc tem o valor numérico de 1885960.
*
* OBS: os números nesse problema podem ser grandes, então se você está usando um tipo de dados de tamanho limitado,
* tenha cuidado com possíveis overflows.
*
* Os Googlons consideram um número bonito se ele satizfaz essas duas propriedades:
* é maior ou igual a 574908
* é divisível por 5
*
* Ao consideramos o Texto A como uma lista de números (isto é, interpretando cada palavra como um número usando a convenção explicada acima),
* notamos que existem 69 números bonitos distintos. E no Texto B, quantos números bonitos distintos existem?
*
* @param string $string
* @return integer
* @access public
*/
function beautifulNumbers($string)
{
$words = explode(' ', $string);
$numbers = array();
foreach ($words as $word)
{
$letters = str_split($word);
for ($i = 0, $number = 0; $i < count($letters); $i++)
{
$number += array_search($letters[$i], $this->alphabet['googlon']) * pow(20, $i);
}
if ($number >= 574908 and ($number % 5) == 0)
{
$numbers[$word] = $number;
}
}
$numbers = array_unique($numbers);
return count($numbers);
}
}