From: Sandro Paganotti Date: 2008-05-19T07:40:48+09:00 Subject: Re: [QUIZ] [SOLUTION] Obfuscated Email (#163) ------=_Part_13508_24152618.1211150444614 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Really elegant ! On Sun, May 18, 2008 at 7:59 PM, Bill Kelly wrote: > > From: "Matthew Moss" > >> >> For your task this week, I ask that you make your own signature such that >> displays your email address when run through the Ruby interpreter. The >> signature must fit within four lines of no more than 80 characters per >> line. >> (If you still want to avoid outputting an email address, your script may >> produce something else: a phone number, a funny quote, vCard, a poem to >> your >> love, whatever...) >> > > Here's my solution... (longest line is 78 characters) > > > ## Machines take me by surprise with great frequency. -- Alan Turing > m=Hash[*"z_ymly_xolx_wclw_v.lv_uslu_ttlt_scls_r@lr_qklq_pllp_ollo_niln_mbl > ". > scan(/(..)(...)/).flatten];t=Hash.new("_");i,s=0,"z";loop{v=m[s+t[i]] or > break > s,t[i],d=v.split(//);i+=(d=="r")?1:-1};p t.keys.sort.map{|k|t[k]}.join > > > > As I missed last week's quiz, I decided to combine the two and implement a > Turing Machine which would execute a program to > write my email address to the tape, the print the tape contents. > > The Turing Machine program looks like this: > > # state, character_under_tape_head, new_state, char_to_write, > move_left_right > z_yml > y_xol > x_wcl > w_v.l > v_usl > u_ttl > t_scl > s_r@l > r_qkl > q_pll > p_oll > o_nil > n_mbl > > > A slightly less obfuscated version of the solution follows. (In the > signature, I omitted using temporary variables when reading and writing > the tape head t[i] .) > > ##-- > > m=Hash[*"z_ymly_xolx_wclw_v.lv_uslu_ttlt_scls_r@lr_qklq_pllp_ollo_niln_mbl > ".scan(/(..)(...)/).flatten] > > t=Hash.new("_") # the tape > > i=0 # tape index (negative index is OK) > > s="z" # current state register > > loop { > c = t[i] > v = m[s+c] or break > s,c,d = v.split(//) > t[i] = c > i += (d=="r")?1:-1 > } > > p t.keys.sort.map{|k|t[k]}.join > > ##-- > > > Regards, > > Bill > > > > -- Go outside! The graphics are amazing! ------=_Part_13508_24152618.1211150444614--