Search | Synergex.com | Contact Us | Resource Center Login | Home|
News

What is the output of the following program?

 

import System.Collections

main
record
      players     ,@ArrayList
      lover       ,string
      beloved     ,string
      spin        ,int

literal
      max         ,int, 4
      valentines  ,[max]a12, "Customers", "Synergy/DE", "Applications", "Synergex"
      February    ,int, 2

.define is_plural(a)    (a(trim(a):1) == 's')

proc
      open(1,o,"TT:")
      players = new ArrayList()
      for spin from 1 thru max
        begin
          lover = valentines[spin]
          if (is_plural(lover)) then
            players.insert(0, (string)atrim(lover))
          else
            players.add((string)atrim(lover))
        end

      spin = February & 14 & 2012
      lover = (string)players[spin]
      if (spin < 2) then
        beloved = (string)players[spin + 2]
      else
        beloved = (string)players[spin - 2]
     
      if (is_plural(lover)) then
        writes(1, lover + " love " + beloved)
      else
        writes(1, lover + " loves " + beloved)
end

a. "Customers love Synergex"
b. "Synergex loves Customers"
c. "Synergy/DE loves Applications"
d. "Applications love Synergy/DE"
e. "Customers love Synergy/DE"

In celebration of Valentine's Day, today's quiz hosts an imaginary game of "Spin the Bottle" between Customers, Synergy/DE, Applications, and Synergex.

The first order of business in this game is to determine seating. The 'for' loop sorts the plural players (those ending with 's') to the top of the 'players' ArrayList, with the singular participants added to the end.
This results in the order: "Applications", "Customers", "Synergy/DE", "Synergex". Because plural items are inserted at the beginning, their order is reversed, while the singular items keep the same order at the end.

Next, we're ready to pick someone. Since 'February' is the name of a literal with a value of 2, the value of the expression 'February & 14 & 2012' is the same as '^x(0002) .band. ^x(000E) .band. ^x(07DC)', which is 0 (because 2 is a single bit, and 2012 doesn't have that bit set). The 0th element of players is "Applications". Remember that System.Collections.ArrayList uses a zero-based index. If we had used Synergex.SynergyDE.Collections.ArrayList instead, this would cause a subscript error.

Now, to pick the other partner, we'll take a shortcut and choose the party opposite to them. Since our index was 0 (which is less than 2), we add 2 and choose "Synergy/DE" (as we always should).

Thus, (d) is the correct answer. But as we all know, all of the above answers are true.