The War of Languages

  1. Is you name on the test?
    1. Yes it is
    2. It is, yes.

  2. What does the following code print?   _____________________________

  3. if("twelve" == "ten plus two") {
            print "Yes";
    }
    else {
            print "No\n";
    }

  4. In WWII, who declared war on Germany first?
    1. U.S.
    2. Canada
    3. Mexico

  5. Write this is Lisp:  5 * 4 - 3 / (2 + 1)

  6.  

     

  7. (Yes/No) Can an assocative array in Perl hold as an element a normal array?  For example, can this program fragment work?

  8. $a[0] = 1;
    $a[1] = 12;
    $b{"array"} = @a;

  9. When was the last time Italy won a war?
    1. WWII
    2. WWI
    3. The last time they attacked Ethiopia
    4. Sometime during the late Roman Empire

  10. Consider an association list of length N.  What is the time needed to look up a key value from this list
    1. O(1)
    2. O(log(n))
    3. O(n)
    4. O(n * log(n))
    5. O(n * n)

  11. Consider an associative array with N elements.  What isthe time needed to look up a key value from this list?
    1. O(1)
    2. O(log(n))
    3. O(n)
    4. O(n * log (n))
    5. O(n * n)

  12. In your own words, what happens when you run this program?

  13. #!/usr/bin/perl -w
    $a = 3;
    while ($a > 2) {
        $a++;
    }

  14. In your own words, what happens when you run this program?

  15. (define (loop x)
         (if (> x 2)
              x
              (loop (+ 1 x))
         )
    )
    (loop 3)

  16. Which general lost more battles than he won?
    1. Napoleon Bonaparte
    2. G. Washington
    3. Attila the Hun
    4. Julius Caesar

  17. What does the code below mean in Lisp?

  18. (fred)
    1. The literal string "fred".
    2. The variable 'fred'
    3. Call the function 'fred'.
    4. Run the program 'fred'.

    5.  
  19. What does the code below mean in Perl?  Note that the quotes are backtics (`)  and not normal single quotes (').

  20. $a = `fred`;
    1. Assign to $a the literal string "fred".
    2. Assign to $a the contents of the variable 'fred'
    3. Assign to $a the return value of the function 'fred'.
    4. Assign to $a the output of the program 'fred'.

    5.  
  21. How man elements in the list? If I call length on this list, what will it say?  ____________
    '(fred (barney wilma) pebbles (bambam (stick stone)))

  22. Associate the tactic and the war

  23.     March toward the machine gun nest                                                    WWII
        Stab with the pike                                                                                       The hundred years war
        Stay in the castle.  Taunt.  Repeat                                                          The Pelipaniasian war
        Drop a bomb from 40,000 ft.                                                                     WWI
     
     
  24. (2 points)  Write me a program in Lisp that counts from 1 .. 10.
  25. (2 points) Write me a program in Perl that counts from 1 .. 10.
  26. (4 points) Write me a program in Lisp that takes as input a list.  Return '1' if the list is in order, 0 otherwise.  The null list should return '1'.  Examples:  (check '(2 4 8 10)) should return '1'.  (check '(1 4 7 2 9)) should return '0'.
  27. (4 points) Write me a Perl program that checks to see if a word is spelled correctly.  A word is spelled correctly if it's listed in /usr/dict/words, otherwise it's spelled wrong.