With deepest apologies to all involved... On Tue, 26 Sep 2017 at 08:42 Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote:
> Ben Bacarisse wrote: > > Think functional! This is 257 characters: > > 250 chars, 17 shorter than the text it produces: > > a=[];o=[];n=[];A=list.append > for b in range(3,-1,-1): > x=bool(b>>1);y=bool(b&1);A(a,"%s and %s is %s"%(x,y,x and y));A(o,"%s or > %s is > %s"%(x,y,x or y)) > if x:A(n,"not %s is %s"%(y,not y)) > print(" Boolean Operators\n"+"-"*24+"\n"+"\n".join(a+o+n)) > Cutting the same (quite reasonable) corners as you, I've got it down 212 characters: t,f,a,o,n='True','False','and','or','not' l=[" Boolean Operators\n"+"-"*24] for x in [(l,p,r)for p in(a,o)for l in(t,f)for r in(t,f)]+[(n,t),(n,f)]:x=' '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] for i in 12,9,5,0:l.insert(i,'') print('\n'.join(l)) Reproducing the original string exactly the best I've managed is 260: t,f,a,o,n='True','False','and','or','not' l=[" Boolean Operators\n"+"-"*24] for x in [(l,p,r)for p in(a,o)for l in(t,f)for r in(t,f)]+[(n,t),(n,f)]:x=' '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] for i in 12,9,5,0:l.insert(i,'') print('\n'.join(l)) -- -- Matt Wheeler http://funkyh.at -- https://mail.python.org/mailman/listinfo/python-list