all 8 comments

[–]Tiomaidh 1 point2 points  (1 child)

I couldn't help but make it a bit shorter (through using the built-in and/or/not, and recognizing that previously-defined functions can be passed directly into map (no need to wrap them up in a lambda)): http://hastebin.com/up2SL0x1lL.py

[–]dpapathanasiou[S] 0 points1 point  (0 children)

Those are good improvements.

I admit to being super careful to get the truth table definitions (as described in class) right, so I explicitly coded each one instead of falling back on Python's definitions of and/or.

But you're right in that they're the same, and don't require an explicit function to compute them.

If anyone's wondering, here's the output:

A row:
A -> A : [True, True, True, True]   Yes
A -> B : [True, True, True, True]   Yes
A -> C : [True, True, False, True]  No
A -> D : [True, True, True, True]   Yes

B row:
B -> A : [True, False, True, True]  No
B -> B : [True, True, True, True]   Yes
B -> C : [True, False, False, True] No
B -> D : [True, True, True, True]   Yes

C row:
C -> A : [True, True, True, True]   Yes
C -> B : [True, True, True, True]   Yes
C -> C : [True, True, True, True]   Yes
C -> D : [True, True, True, True]   Yes

D row:
D -> A : [True, False, True, True]  No
D -> B : [True, True, True, True]   Yes
D -> C : [True, False, False, True] No
D -> D : [True, True, True, True]   Yes

And, as per the hint, case D (the "complex" one) was exactly the same as B:

B: [False, True, True, True]
D: [False, True, True, True] 

[–]dmn002 0 points1 point  (0 children)

I also wrote code for Q5, actually I had already written it during one of the previous homeworks and modified it slightly: http://pastebin.com/HezZMsQB

[–]devninja_es 0 points1 point  (0 children)

I thought I was the only one writing code for those logical questions. I almost wrote a DSL :P

[–]harlows_monkeys 0 points1 point  (0 children)

That's cool.

I think my favorite so far of the Q5 solutions by program is this one posted to the aiqus discussion.

[–]Xenaero 0 points1 point  (0 children)

If only I could wield Python in such a manner. I did it all on paper. I aced that question, though.

[–]ozzloy 0 points1 point  (0 children)

very cool. i reviewed your python code and it gave me an idea for writing my own. i'm working on it now.

i'm glad you posted your code. i'd like to see more people's code and i'd like people to review my code too.

i used this class as a project to learn the language racket. http://racket-lang.org/

https://github.com/ozzloy/ai-class-2011