odd question
Larry Bates
lbates at swamisoft.com
Wed Jul 14 15:38:39 EDT 2004
Sure wish this group was around to help me
with my homework when I was taking CS 101
back 30 years ago <grin>.
Larry
"wes weston" <wweston at att.net> wrote in message
news:JSfJc.94489$OB3.3186 at bgtnsc05-news.ops.worldnet.att.net...
> Karl Pech wrote:
> > Hi,
> >
> > I'm currently working on the following exercise:
> > ---
> > You have given the following function:
> > def f2(i, j, k):
> > return ((i | j) & k) | (i & j)
> >
> > Find a useful utilization for this function.
> > ---
> >
> > Actually I couldn't figure out so far, what exactly is
> > a "useful utilization". Can anybody of you help me?
> >
> > Thanks!
> >
> > Regards
> > Karl
> >
> > [P.S. I have even written a small program, which should
> > show me, what this formula does with numbers, but I couldn't
> > find anything "interesting" or regular in the output-file.
> > This is the source of the program:
> > ---
> > import string
> >
> > def testit(i, j, k):
> > return ((i | j) & k) | (i & j)
> >
> > q = []
> > results = [[], [], [], [], [], [], [], [], [], []]
> >
> > fout = open("out.txt", "w")
> >
> > for x in range(10):
> > for y in range(10):
> > for z in range(10):
> > a = [x, y, z]
> > a.sort()
> > if a in q:
> > continue
> > else:
> > results[testit(x, y, z)].append([x, y, z])
> > q.append(a)
> >
> >
> > for x in range(len(results)):
> > for y in range(len(results[x])):
> > fout.write(string.strip(str(results[x][y]), "[]")+" : "+str(x)+'\n')
> > ---
> >
> > I guess I just have to construct some kind of situation there this
> > function could be useful but I don't have any ideas. :(
> >
>
> ((i | j) & k) | (i & j)
>
> i j k f
> - - - -
> 0 0 0
> 0 0 1
> 0 1 0
> 0 1 1 1 (i | j) & k
> 1 0 0
> 1 0 1 1
> 1 1 0 1 (i & j)
> 1 1 1 1 (i & j)
>
> Karl,
> Hum; could it be true where 2 or more of i,j,k are
> true?
> wes
>
More information about the Python-list
mailing list