hw14.py (plain text)


# CS 61A HW 14
# Name:
# Login:
# TA:
# Section:

# Useful functions for lists.
fact equal_lists(<>, <>)
rule equal_lists(<?x | ?rest1>, <?x | ?rest2>):
    equal_lists(?rest1, ?rest2)
    
fact append(<>, ?z, ?z)
rule append(<?x | ?u>, ?v, <?x | ?w>):
    append(?u, ?v, ?w)
    
fact member(?first, <?first | ?rest>)
rule member(?first, <?other | ?rest>):
    member(?first, ?rest)
    
fact reverse(<>, <>)
rule reverse(<?x | ?rest>, ?rev):
    reverse(?rest, ?rest_rev)
    append(?rest_rev, <?x>, ?rev)
    
### Contest
# Replace the numbers below with your selected entry numbers.
fact featherweight_first_choice(0)
fact featherweight_second_choice(0)
fact heavyweight_first_choice(0)
fact heavyweight_second_choice(0)

### Core Questions
### Q1.
# Facts about the families of the fictional 'Harry Potter' universe.
fact married(arthur, molly)
fact married(molly, arthur)

fact father(arthur, bill)
fact father(arthur, charlie)
fact father(arthur, percy)
fact father(arthur, fred)
fact father(arthur, george)
fact father(arthur, ron)
fact father(arthur, ginny)

fact mother(molly, bill)
fact mother(molly, charlie)
fact mother(molly, percy)
fact mother(molly, fred)
fact mother(molly, george)
fact mother(molly, ron)
fact mother(molly, ginny)
    
fact father(james, harry)
fact mother(lily, harry)

fact married(harry, ginny)
fact married(ginny, harry)

fact father(harry, james_sirius)
fact father(harry, albus_severus)
fact father(harry, lily_luna)

fact mother(ginny, james_sirius)
fact mother(ginny, albus_severus)
fact mother(ginny, lily_luna)

fact married(ron, hermione)
fact married(hermione, ron)

fact father(ron, rose)
fact father(ron, hugo)

fact mother(hermione, rose)
fact mother(hermione, hugo)

fact married(bill, fleur)
fact married(fleur, bill)

fact father(bill, victoire)
fact father(bill, louis)
fact father(bill, dominique)

fact mother(fleur, victoire)
fact mother(fleur, louis)
fact mother(fleur, Dominique)

fact kills(snape, dumbledore)

rule parent(?who, ?child):
    father(?who, ?child)
    
rule parent(?who, ?child):
    mother(?who, ?child)
    
# (a) Below, write the query that will list all of Molly's children.

# Your query here.

# (b) Below, write the query that will list all the people who are
#     married and their spouses.

# Your query here.

# (c) Below, write the rules that determine if a person is a sibling
#     of another person. Two people are siblings if they have the
#     same parent.

# Your rules here.

# (d) Below, describe how and why the suggested rule to check if two
#     people are not married will not work as expected.

# rule married(?who, ?spouse):
#     married(?spouse, ?who)

# Your answer here.

### Q2.
fact complementary(t, a)
fact complementary(a, t)
fact complementary(c, g)
fact complementary(g, c)

# Your rules and facts for rev_comp_strand here.

### Q3.
# Your rules and facts for add_to_all here.

### Q4.
# Your rules and facts for sublists here.

### Reinforcement Questions
### Q5.
# Your rules and facts for unzip here.

### Q6.
# (a) Write the rules and facts to add two numbers in unary representation.
# Your rules and facts here.

# (b) Write the rules and facts to subtract two numbers
#     in unary representation.
# Your rules and facts here.

# (c) Write the rules and facts to multiply two numbers
#     in unary representation.
# Your rules and facts here.

# (d) Write the rules and facts to compare two numbers.
# Your rules and facts here.

# (e) Write the rules and facts to check the equality of two numbers.
# Your rules and facts here.

# (f) Write the rules and facts to divide two numbers
#     in unary representation.
# Your rules and facts here.

### Extra for Experts
# Your rules and facts here.