Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Te hago la tarea, pero con estilo

Pa­sa siem­pre, co­mo en to­das las lis­tas de pro­gra­ma­ció­n, que de vez en cuan­do al­guien pos­tea en la lis­ta de Py­thon Ar­gen­ti­na al­go que es ob­via­men­te su ta­rea pa­ra el ho­ga­r. Pa­ra ma­ne­jar­lo hay dos es­cue­las de pen­sa­mien­to:

  1. Mo­s­­tra­r­­le co­­­mo se ha­­ce es de­­ci­r­­le co­­­mo ha­­cer tra­m­­pa.

  2. Mo­s­­tra­r­­le co­­­mo se ha­­ce es en­se­­ña­r­­le.

Yo me in­clino más por 1) pe­ro creo ha­ber en­contra­do un ca­mino in­ter­me­dio:

1.5) Dar­le una so­lu­ción más com­pli­ca­da que el pro­ble­ma.

De esa ma­ne­ra, si en­tien­de la so­lu­ció­n, ya hi­zo el tra­ba­jo. Y si no la en­tien­de, va a ser tan ob­vio que no la en­tien­de, que el pro­fe­sor nun­ca le va a acep­tar la res­pues­ta.

Co­mo ejem­plo, es­te es el pro­ble­ma que pre­sen­ta­ron en PyA­r:

La lis­ta vie­ne de­sor­de­na­da y con dos ca­rac­te­res (uno en mi­nús­cu­la y otro en ma­yús­cu­la), por ejem­plo:

['eD', 'fC', 'hC', 'iC', 'jD', 'bD', 'fH', 'mS', 'aS', 'mD']

Pa­ra or­de­nar­la de­bo se­guir es­tas pau­ta­s:

  1. Ar­mar su­b­con­jun­tos de acuer­do a la ma­yús­cu­la y lue­go or­de­nar esos su­b­con­jun­tos por la canti­dad de miem­bros (en or­den as­cen­den­te), la lis­ta que­da de la si­guien­te for­ma:

    ['fH', 'mS', 'aS', 'fC', 'hC', 'iC', 'jD', 'bD', 'eD', 'mD']
  2. Aho­ra ca­da su­b­con­jun­to de­be es­tar or­de­na­do de ma­ne­ra as­cen­den­te y de acuer­do a la mi­nús­cu­la, con lo que la lis­ta que­da or­de­na­da así:

    ['fH', 'aS', 'mS', 'fC', 'hC', 'iC', 'bD', 'eD', 'jD', 'mD']

Ig­no­ran­do que el plan­teo es am­bi­guo (hay por lo me­nos dos ma­ne­ras de leer­lo, ca­paz que má­s), yo pro­pu­se es­ta so­lu­ció­n, que re­quie­re py­thon 3:

from collections import defaultdict
d1 = defaultdict(list)
[d1[i[1]].append(i) for i in  ['eD', 'fC', 'hC', 'iC', 'jD', 'bD', 'fH', 'mS', 'aS', 'mD']]
{i: d1[i].sort() for i in d1}
d2 = {len(d1[i]): d1[i] for i in d1}
print([item for sublist in [d2[i] for i in sorted(d2.keys())] for item in sublist])

Produce el resultado deseado: ['fH', 'aS', 'mS', 'fC', 'hC', 'iC', 'bD', 'eD', 'jD', 'mD'] pero de una manera que para entenderlo, el alumno necesita saber mas de lo que requiere el problema original, incluyendo tres o cuatro cosas que no creo que le hayan enseñado.

A Django Le Saltó La Cadena

Ayer fuí (mu­cho más tar­de de lo que hu­bie­ra que­ri­do) a ver Djan­go Un­chai­ne­d. Avi­so: Hay spoi­ler­s. Si no la vis­te, no si­gas le­yen­do. Tra­to de lle­var­los al fi­nal del pos­t, pe­ro no te quie­ro ca­gar la pe­lícu­la. Ok?

Leer más…

A Few Problems with A Song Of Ice and Fire

I read all of it, one book after the othe­r, and en­ded a mon­th ago. And sin­ce then, I ha­ve had a cou­ple of things about it bo­the­ring me. Le­t's see if they make so­me sen­se. Mind you, I am going to read vo­lu­mes six and se­ven, be­cau­se the­se books are addic­ti­ve as cra­ck in ebook-­for­m.

Bu­t, just like cra­ck, they ha­ve so­me wo­rri­so­me fea­tu­res.

There May Be No Plan

We are fi­ve books (and a cou­ple of chap­ter­s) in­to it. It's su­ppo­sed to be a se­ven book se­rie­s. And no­thing has ha­ppe­ne­d. You may say a lot has, like "this cha­rac­ter got ki­lle­d" and "that other cha­rac­ter got ki­lle­d" (and a hun­dred other cha­rac­ters got ki­lle­d), yeah.

But what has chan­ged in the fi­ve kin­g­do­ms?

It's star­ting to fee­l, the­se many pa­ges la­te­r, as if ... we­ll, who ca­res what ha­ppen­s? The fi­ve kin­g­do­ms wi­ll ha­ve a kin­g, or ano­the­r. The­re wi­ll be dra­gons (whi­ch wi­ll su­pport a king or ano­the­r), the­re is war and eve­r­yo­ne is ha­ving a cra­ppy ti­me, but he­y, all that ha­ppe­ned fi­ve ti­mes in the last hun­dred years or so al­read­y.

The hand of the king was ki­lle­d? We­ll, so we­re fi­ve of the last se­ven han­d­s.

A Tar­ga­r­yen may co­me, lay was­te to all the ar­mies of the realm and be cro­w­ne­d? We­ll, that al­ready ha­ppe­ned in the field of fi­re, and they had Tar­ga­r­yens for a whi­le, un­til they ran out of dra­gon­s.

The Iron­men may con­quer the nor­th? We­ll, they al­ready had con­que­red it a cou­ple cen­tu­ries ago, and then they lost it.

And so on: any of the pa­yo­ffs of the book se­ries has al­ready ha­ppe­ne­d, so­me of it mo­re than on­ce. So, wha­t's spe­cial about this ti­me aroun­d?

Does the au­thor ha­ve a plan, so­me­thing up his slee­ve tha­t's going to be a sho­ck? I do­n't kno­w, but the tri­cks are star­ting to get re­pe­ti­ti­ve.

What would ha­ppen if, after se­ven books, it turns out that the­re's no­thing spe­cia­l?

It's Too Earth-Like

The fi­ve kin­g­do­ms. Sco­tlan­d, En­glan­d, Wa­le­s, Ire­land and whi­ch one? Is­le of Man? Be­cau­se, co­me on. The­re's the­se peo­ple who are al­most exac­tly Mon­gol­s, ex­cept they ha­ve be­lls in their hai­r. The­re's the pseu­do­-­vikin­g, the pseu­do­-s­co­ts, the er­satz-i­ris­h, the fake-i­ta­lian­s, the I-­can'­t-­be­lie­ve-i­t's-­no­t-­chi­ne­se and so on.

The­re are kni­gh­ts, who­se ar­mour is exac­tly me­die­val ar­mou­r. The­re's the sea­fa­ring rai­der­s, on their longs­hip­s. Etce­te­ra, etce­te­ra, et-­freakin­g-­ce­te­ra. It's like whe­ne­ver the au­thor nee­ds to add an "exo­ti­c" cha­rac­te­r, he just th­ro­ws a dart at the ma­p, then ano­the­r, crea­tes a mix 80% one, 20% the othe­r, makes up so­me si­lly or­to­gra­phy ru­le for na­me­s, and tha­t's it.

The Magic is Lazy

So, dra­gon­s. And of cour­se, dra­gons crea­te ma­gic (you can see how lo­ts of ma­gi­cal giz­mos start wo­rking sin­ce the dra­gons ca­me).

So, le­t's make ma­gic eve­r­y­thin­g. Want to ha­ve le­gen­da­ry swor­d­s? Then they are ma­de of Va­l­y­rian stee­l. Tha­t's ma­gi­cal stee­l, whi­ch is why it see­ms to ne­ver need shar­pen­in­g. Tha­t's why you can ha­ve fa­mi­ly heir­loom swor­d­s. Be­cau­se they are ma­gi­cal.

And the­re's a ma­gi­cal door, ma­de of ma­gi­cal wood. The ma­gi­cal wood co­me­s, of cour­se, from ma­gi­cal trees.

And the­re's fake ma­gi­cal swor­d­s, ma­de by real eas­tern ma­gi­c. And the­re's ma­gi­cal assas­sin­s. And ma­gi­cal coin­s, ma­gi­cal cand­le­s. And so on, and so for­th. You can't paint your­self in­to cor­ners when you can count on the­re being a ma­gi­cal pain­tbrush that la­ys do­wn paint that does­n't stain the ma­gi­cal shoes of the pain­ters of the ma­gi­cal land of Pain­the­ria, who­se na­mes alwa­ys ha­ve a dou­ble la­r­yn­geal con­so­nant in the mi­dd­le.

More is More is More is Less

The first book ma­na­ges to te­ll rou­gh­ly a (ear­th) year of sto­r­y. The four­th and fi­fth, to­ge­ther be­cau­se they ha­ppen si­mul­ta­neous­l­y, co­ver perhaps th­ree mon­ths. And the­re are cha­rac­ters we ha­ve not seen sin­ce book th­ree, when they we­re just about to say so­me­thin­g. We are cu­rren­tly en­te­ring the third book wai­ting to know what the mai­den of Tar­th said at that mo­men­t.

The­re are books that are about one cha­rac­te­r, the­re are tho­se that are about a do­zen, the­re are tho­se that are about one hun­dre­d. No­ne of the la­tter is any good. The sto­ry keeps ex­pan­ding and slo­wing do­wn. At this ste­p, all of book se­ven is going to be about a sin­gle day in the li­fes of 50 firs­t-­per­son cha­rac­ter­s, and ea­ch one wi­ll des­cri­be their break­fas­t, be­fo­re we unex­pec­ted­ly get pro­mi­s­ed (ve­ry soon no­w) an eight book whi­ch wi­ll co­ver their pos­t-­break­fast craps and clear eve­ry ques­tion we may ha­ve had about the sub­jec­t.

Fan Service

You, who know what was in the pies ser­ved in the feast at Win­ter­fe­ll in vo­lu­me 5, you are being spoon­fed that kind of thing to make you feel smart and kno­w­le­dgea­ble. If you do­n't know what was in that pie... we­ll, YOU MISS­ED IT.

And how is it a good idea to wri­te th­ree pa­ges that (if you ha­ve a good me­mo­r­y) shout what was in that pie, when it's a sto­ry about a thir­d-­li­ne and four­th-­li­ne cha­rac­ters who­se na­mes noone wi­ll re­mem­be­r?

We­ll, it's a good idea be­cau­se it's fan ser­vi­ce, and fans lo­ve being ser­ve­d. But it's a cy­ni­ca­l, cal­cu­la­ting mo­ve. You are being ser­ved bad pie the­re, fan­s.

So, Are the Books Good?

They are awe­so­me. I can't wait for the six­th vo­lu­me. Geor­ge RR Mar­ti­n, he­re's my mo­ne­y. Te­ll me a sto­r­y.

Twitter Off

La se­ma­na pa­sa­da to­mé una de­ci­sión que no me es­pe­ra­ba. Ce­rré los co­men­ta­rios en es­te blog a me­nos que el post sea al­go téc­ni­co. Lo hi­ce por­que no aguan­ta­ba al­gu­nos de los co­men­ta­rio­s. Y di­je "se van los co­men­ta­rios por un me­s, y des­pués ve­mos si los ex­tra­ño­."

Bue­no, si­go sin ex­tra­ñar­lo­s, co­mo se da­rán cuen­ta por­que es­te mis­mo post no tie­ne co­men­ta­rio­s.

Hoy cie­rro los co­men­ta­rios de la vi­da. Sus­pen­dí mi cuen­ta de twi­tte­r. Si­guen salien­do al­gu­nas co­sas que se pos­tean au­to­má­ti­ca­men­te, pe­ro no lo leo, y no re­ci­bo no­ti­fi­ca­cio­nes de na­da.

Tam­bién es "twi­tter off por un me­s, des­pués ve­mos si lo ex­tra­ño­".

Oja­lá que no.


Contents © 2000-2024 Roberto Alsina