Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

My first time

I just found here the an­nounce­ment of the first free soft­ware I pub­lished (at least, that I re­cal­l), from may 13, 1996. So, It's go­ing to be 10 years in 5 month­s!

Killer quote:

Requires:
Python 1.3 (Maybe 1.2 would work too)
XForms 0.80 (NOT 0.75)

Ok, here is how you write the shortest one

About http://www.py­con­test.net... here's how it's done.

Sad­ly, it's pret­ty much im­pos­si­ble to put the code on the web be­cause it has some re­al­ly non-ascii stuff in it ;-)

Here's the key tricks (thanks to Re­mi and the oth­er­s):

One of the key tricks is writ­ing a short ver­sion of a very long oc­tal num­ber (or three­).

I tried us­ing base36 and in­t('­gob­ledy­gook',36).

You could use 0x­hex­a­code­here.

But here's the most space-­ef­fi­cient one: use base 256!

For each byte you wan­t, cre­ate a char us­ing chr(byte). Then paste them all to­geth­er. Then put it in your code as a string. If you are lucky you will have no quotes or new­lines in it, and the python in­ter­preter will eat it.

You can lat­er get the byte num­ber x us­ing or­d('h!als­d­f'[x]), and each byte by some di­vid­ing and mod­u­lo op­er­a­tion.

An­oth­er im­por­tant piece is en­cod­ing 7 3-char­ac­ter strings as com­pact­ly as pos­si­ble, and split­ting them by off­sets (which are en­cod­ed in the pre­vio­su­ly men­tioned big num­ber in base 8 ;-)

One ex­tra squeeze is find­ing the short­est way to con­cate­nate strings.

It's ''.join(), but if you are us­ing it twice (or more), you save space by do­ing j=''.join and us­ing j lat­er.

Last one: In­stead of defin­ing a func­tion, do a lamb­da:

def sev­en_seg(x): re­turn .....

sev­en_seg=lamb­da x:

6 chars less!

And here is the short­est code I got so far (121 char­ac­ter­s, re­quires python 2.4. On 2.2, it has to be 124).

In the con­test, some guys are at 120. I don't know how. I can't even guess how ;-)

Up­date: it turns out I did know how to do it check it out I think it's the first pub­lic 120 :-)

BTW: you can't write that us­ing kwrite. Vim work­s, though.

Python Contest

There is a python con­test at http://www.py­con­test.net/

The task is writ­ing the short­est pro­gram to drive a sev­en-seg­ment LCD thingy.

I have no hope of win­ning, but here's a help­ful hin­t:

If your code is any longer than this (191 chars), it will not win ;-)

a=' _ '
b='|_|'
c='   '
d='  |'
e=' _|'
f='|_ '
g='| |'
v='agbcddaefaeecbdafeafbaddabbabe'
def seven_seg(x):
        return '\n'.join([eval('+'.join([v[int(l)*3+i]for l in x]))for i in 0,1,2])+'\n'

Note: I edit­ed this item way too many times al­ready ;-)

And yes, I can save two char­ac­ters mov­ing the re­turn up.

A much uglier, yet much short­er (151) ver­sion:

def seven_seg(x):return''.join([''.join(['|    ||__  __ || |  |'[int('a302ho6nqyp9vxvpeow',36)/10**(int(l)*3+u)%10::7]for l in x])+'\n'for u in 0,1,2])

And yes, that pret­ty much proves you can write ug­ly python. And I am giv­ing up. A short­er ver­sion prob­a­bly in­volves a dif­fer­ent al­go­rith­m, and I can't find any.

I am par­tic­u­lar­ly proud of sav­ing one char­ac­ter by writ­ing 104004334054154302114514332064 as in­t('a302ho6n­qyp9vxvpe­ow',36).

Al­so in­ter­est­ing is that the num­ber I was us­ing there orig­i­nal­ly start­ed with 4 and was ex­act­ly the same length writ­ten both ways ;-)

Since that num­ber is pret­ty ar­bi­trary (it's an in­dex ta­ble in­to the "graph­ic­s" ar­ray), I just shuf­fled the 1 and the 4. The 0 would have been bet­ter but then it did­n't work, of course :-)

Teaching and money

I have been teach­ing for al­most my whole adult life.

My first re­al job was teach­ing as­sis­tan­t. I worked in a uni­ver­si­ty for 10 years.

Then I start­ed teach­ing Lin­ux train­ning cour­ses for di­verse com­pa­nies (think LPI kin­da stuff).

Then I stopped. Why? Be­cause it makes no sense eco­nom­i­cal­ly to teach in most cas­es.

The fol­low­ing is writ­ten in pe­sos, but the idea is prob­a­bly about the same for oth­er coun­tries.

There are no mon­ey signs beause chee­tah tem­plates hate them ;-)

A train­er is paid about 35 per hour. If he's pret­ty good, he gets 50.

A course is about 24 hours, so he gets about 1200 (I am go­ing for the best case sce­nario here).

Usu­al­ly he has be­tween 6 and 12 stu­dents, which are charged about 900 + tax­es, so the gross is av­er­age 5500.

Of that, half (or a lit­tle less) goes to the class­room ren­t, leav­ing about 3000 for the train­ing com­pa­ny.

Pay the teacher, and you have a rather pa­thet­ic amount for the train­ing com­pa­ny that pays over­head, sales­peo­ple, tax­es and what­ev­er.

So, who makes any mon­ey out of this? The class­room renters :-P

So, if youa re go­ing to work on train­ing, please don't rent class­room­s, it makes no sense.

Now sup­pose you have a con­sult­ing firm and you can do on­site train­ing (at your clients), and just pock­et the mon­ey.

If you have just three stu­dents, you need no fa­cil­i­ties, you can charge slight­ly high­er, be­cause its on­site.

It's the same ef­fort for the train­er, be­cause you just change where you com­mute to (train­ing cen­ter vs clien­t).

Since you can make more mon­ey with small­er class­es, you can still charge a lit­tle high­er (more per­son­al­ized at­ten­tion).

Since the stu­dents are all from one com­pa­ny they have more in com­mon and you can struc­ture the teach­ing bet­ter, which makes it way less bor­ing.

So, if you want to make a liv­ing teach­ing, here's how.

  • Mar­ket di­rec­t­­ly to com­­pa­nies, for on­site train­ing.

  • Have your own ma­te­ri­al­s.

  • Be flex­i­ble.

  • Buy your own class­­room if you have to.

And most of al­l, don't wor­ry. It's pret­ty much im­pos­si­ble to lose mon­ey train­ing, un­less you open a ex­clu­sive­ly train­ing com­pa­ny.


Contents © 2000-2022 Roberto Alsina