The view from the Tee:

  1. You have 2 integer values ($a, $b).
  2. Create function X that returns a value of made up of a mix of bits where each bit is selected from either $a or $b in a controlled way. eg if bit 4 of $a == 1 and bit 4 of $b == 0 and I want $a's bit 4 then X($a,$b,$c)'s return value should have bit 4 == 1.
  3. Function X may accept one and ONLY one parameter in addition to $a,$b.

There is an interesting solution to this hole that I will give and credit later. If you are an old fart assembler programmer and have played this course before, why not give the newer club members a crack at it first.

Four! or is it Fore!

mitd-Made in the Dark
'My favourite colour appears to be grey.'

Replies are listed 'Best First'.
(MeowChow) Re: 'Holy in one' another Golf Game!
by MeowChow (Vicar) on Jul 27, 2001 at 06:43 UTC
    Here's my despoiled contribution:
    22 chars...
    sub sel { $_[0]&~$_[2]|$_[1]&pop }
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      Maybe you could explain your interpretation of the problem, because it seems ambiguous to me. 18 characters, and it does some stuff:
      sub X { (1<<pop)&(pop|pop) }
      Here I'm presuming $a and $b are two values, and that a third parameter $c indicates which bit is required, such that if $c were 4, the 4th bit was extracted (24 or 16) and returned as is, with the 4th bit being either 1 or 0 as was in the input.

      Pop. Pop. Pop.

      Update:
      My reply fell of the edge of the world, so I've reproduced it here: 20 characters:
      sub X{ ($_=pop)&pop|~$_&pop }
        You have the right idea, but extrapolate it for all the bits of $a, $b, and $c. The $c is essentially a multichannel multiplexer for inputs $a and $b. It specifies whether to select the bit from $a or $b for each digit of the output.

        So with:

        my $a = 0b10101010; my $b = 0b11001100; my $c = 0b11110000; #result: 11001010
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print
Re: 'Holy in one' another Golf Game!
by mitd (Curate) on Jul 28, 2001 at 08:46 UTC
    'Holy Bare-naked Buddhas'

    Look at those monkers sitting in the Clubhouse with there Green jackets looking oooh soo smart.

    MeowChow led off with his amazing last chip(pop) shot into the cup.

    But then tadman blew us away by using his wedge all the way down the fairway.

    Now we finally come to the tourney sponsor, me and although my strokes rank last of the threesome. MeowChow has agreed to buy me a cocktail at the 19th hole for using the least number of clubs (operations)

    sub X { ($_[0]^$_[1])&$_[2]^$_[1] }

    If life was fair I should have got a precedence handicap

    You can read more about this little ditty here.

    It came to my attention back in the early 80's when I was programming games on Atari's. It (the algorithm) was used to create the cool dissolve effects in Donkey Kong.

    Special thanks to Chris Crawford for still having the 6502 code lying around.

    BTW, for you younger bucks who enjoy games like Startcraft, Alpha Centari and Homeworld, you really owe your hours of fun and frustration to Chris, the father of the genre.

    Happy putting.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'