3 Solved Problems on Programming Languages - Assignment 5 | CS 401, Assignments of Programming Languages

Material Type: Assignment; Class: Programming Languages; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Fall 2007;

Typology: Assignments

Pre 2010

Uploaded on 04/12/2010

koofers-user-ef6
koofers-user-ef6 ๐Ÿ‡บ๐Ÿ‡ธ

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 405/505 ASSIGNMENT #5
Due Thursday, October 18, 2007
1. Roman numerals use the following symbols:
I(one)
V(five)
X(ten)
L(fifty)
C(one hundred)
D(five hundred)
M(one thousand)
These are usually written in linear order (e.g., I,II,III) with smaller numerals always
following larger numerals except when they are to be subtracted (e.g., IV means 5 - 1).
Subtractions are used instead of writing four consecutive occurrences of the same symbol
(i.e., IV should be used instead of IIII,MCM instead of MDCCCC, etc.). Only symbols which are
powers of 10 may be used in subtractions (i.e., I,X,C, and M). Furthermore, subtraction rules
require that a symbol representing 10xmay not precede any symbol larger than 10x+1 (e.g.,
IC is not permitted to represent 99 but XC is 90). Write a LISP function (romanToDecimal
RomanNumeral) which takes a Roman numeral as a list of digits and returns the decimal
equivalent if the Roman numeral is well formed and error otherwise. Test your function as
follows:
(a) (romanToDecimal โ€™(C D V)) โ‡’405
(b) (romanToDecimal โ€™(M M V I I)) โ‡’2007
(c) (romanToDecimal โ€™(M M M C M X C I X)) โ‡’3999
(d) (romanToDecimal โ€™(M I M)) โ‡’error
2. DNA is a two-stranded molecule. Each strand is a polynucleotide composed of A (adenosine),
T (thymidine), C (cytidine), and G (guanosine) residues. The two strands of DNA run
antiparallel (i.e., at each nucleotide residue along the double-stranded DNA molecule, the
nucleotides are complementary). That is, A forms two hydrogen-bonds with T; C forms three
hydrogen bonds with G. In most cases the two-stranded, antiparallel, complementary DNA
molecule folds to form a helical structure, which resembles a spiral staircase. This is the reason
why DNA has been referred to as the โ€œDouble Helix.โ€ An example of two complementary
strands of DNA would be:
ATGGAATTCTCGCTC
TACCTTAAGAGCGAG
This genetic sequencing problem is to find complementary matching strands of DNA. Write a
LISP function (matchDNA strand1 strand2) that takes two strands as lists of nucleotides,
and returns: 1) the beginning part of the second strand which does not match, 2) the part
of the second strand which the first string matches, and 3) the remaining part of the second
strand which does not match. Note that if there is no match, the second and third components
will be null. If there are multiple matching strings, returning only the first match is sufficient.
Test your function as follows:
pf2

Partial preview of the text

Download 3 Solved Problems on Programming Languages - Assignment 5 | CS 401 and more Assignments Programming Languages in PDF only on Docsity!

CS 405/505 ASSIGNMENT

Due Thursday, October 18, 2007

  1. Roman numerals use the following symbols:

I (one) V (five) X (ten) L (fifty) C (one hundred) D (five hundred) M (one thousand) These are usually written in linear order (e.g., I, II, III) with smaller numerals always following larger numerals except when they are to be subtracted (e.g., IV means 5 - 1). Subtractions are used instead of writing four consecutive occurrences of the same symbol (i.e., IV should be used instead of IIII, MCM instead of MDCCCC, etc.). Only symbols which are powers of 10 may be used in subtractions (i.e., I, X, C, and M). Furthermore, subtraction rules require that a symbol representing 10x^ may not precede any symbol larger than 10x+1^ (e.g., IC is not permitted to represent 99 but XC is 90). Write a LISP function (romanToDecimal RomanNumeral) which takes a Roman numeral as a list of digits and returns the decimal equivalent if the Roman numeral is well formed and error otherwise. Test your function as follows:

(a) (romanToDecimal โ€™(C D V)) โ‡’ 405 (b) (romanToDecimal โ€™(M M V I I)) โ‡’ 2007 (c) (romanToDecimal โ€™(M M M C M X C I X)) โ‡’ 3999 (d) (romanToDecimal โ€™(M I M)) โ‡’ error

  1. DNA is a two-stranded molecule. Each strand is a polynucleotide composed of A (adenosine), T (thymidine), C (cytidine), and G (guanosine) residues. The two strands of DNA run antiparallel (i.e., at each nucleotide residue along the double-stranded DNA molecule, the nucleotides are complementary). That is, A forms two hydrogen-bonds with T; C forms three hydrogen bonds with G. In most cases the two-stranded, antiparallel, complementary DNA molecule folds to form a helical structure, which resembles a spiral staircase. This is the reason why DNA has been referred to as the โ€œDouble Helix.โ€ An example of two complementary strands of DNA would be: ATGGAATTCTCGCTC TACCTTAAGAGCGAG This genetic sequencing problem is to find complementary matching strands of DNA. Write a LISP function (matchDNA strand1 strand2) that takes two strands as lists of nucleotides, and returns: 1) the beginning part of the second strand which does not match, 2) the part of the second strand which the first string matches, and 3) the remaining part of the second strand which does not match. Note that if there is no match, the second and third components will be null. If there are multiple matching strings, returning only the first match is sufficient. Test your function as follows:

(a) (matchDNA โ€™(A T G C) โ€™(A T G C A T A C G A)) โ‡’ ((A T G C A) (T A C G) (A)) (b) (matchDNA โ€™(A) โ€™(A T G C A T)) โ‡’ ((A) (T) (G C A T)) (c) (matchDNA โ€™(C G) โ€™(A T G C)) โ‡’ ((A T) (G C) nil) (d) (matchDNA โ€™(G A A T T C) โ€™(T G G A A T T C T)) โ‡’ ((T G G A A T T C T) nil nil)

  1. Consider the Core program below:

input a; input b; k := 1; while (b > 0) loop b := b - 1; k := k * a; end loop; output k;

Assuming that the input file contains the integers 4 and 3 (i.e., the list <4, 3>), use the denotational semantics of Core to trace the interpretation of the program.