True story: A coach attended one of our weekly EduCALC HP 48
Programming Classes (long, long ago, just down the street). He told
us that he had been given the daunting task of creating a game
schedule for his league. "It's too complicated!" he said. "I'm having
nightmares over it!"
Here's the scoop: The league was made up of N teams. The entire game
schedule for the league was to cover exactly N days (not necessarily
contiguous, but call them Day 1 through Day N for simplicity's sake).
Every team (call them Team 1 through Team N) had to play every other
team exactly once. Multiple games can happen on any one day, but each
team cannot play more than one game on any one day. Every team had to
have at least one day (a "bye day") on which they played no game.
During the following week, I wrote a program that input the number of
teams in the league (N), and the numbers of any two teams, and output
the day of those teams' game. For example, an input of 8, 3, and 5 (8
teams in the league, Team 3 and Team 5), might output that their game
is on Day 2. If the same team number was used for both teams, then
the day number returned was that team's bye day. For example, if
teams 3 and 3 are input, it might output day 6, meaning that team 3's
bye day is Day 6. I eagerly anticipated his reaction to my brilliant
program at the next class.
He didn't come back. I was totally bummed. I never saw him again. I
hope that he solved his own nightmare, which turned out to be quite
simple. In any case, my program is still in my HP 48, for old times'
sake.
Your programming mini-challenge, if you choose to accept it, is to
write a program that solves The Coach's Nightmare. Shortest program
wins the usual MC virtual prize. Beat my program (27.5 bytes) for a
real prize. Unhint: Renaming the teams or days to 0 through N-1 is
not allowed.
Happy Programming!
-Joe-
I think I _may_ have a solution, but so as to not kill the contest,
I'll just post the INFO for now and send the program to Joe.
size: 22.5 bytes
crc: # 5247h
-wes
What fun. Here's my cut after a blind alley through list-land. This
is my first attempt at any
MC.
<< + SWAP MOD 1 + >>
Thanks for the MC's.
I got 22 as the size in filer, but doing the BYTES command gave me
32 bytes
# 5247h
I'm new to this, so I'm not sure what is the official measure.
> I got 22 as the size in filer, but doing the BYTES command gave me
> 32 bytes
> # 5247h
> I'm new to this, so I'm not sure what is the official measure.
> << + SWAP MOD 1 + >>
Put the program itself (not its name) on the stack and then execute
the BYTES command. Since << >> is always 10 bytes, and the other
commands in your program are 2.5 bytes each, it looks like it should
return 22.5 bytes, same as Wes above in this thread.
-Joe-
Thanks, Joe.
Yes, Wes submitted the same program as ddoherty03 (but earlier),
namely << + SWAP MOD 1 + >>. Wes also wrote that the output becomes
"more logical" by making the progam two commands longer: << + 2 - SWAP
MOD 1 + >> and that's exactly the program that I had in mind when
posting the mini-challenge.
Here's a tougher challenge: If System RPL is allowed, this mini-
challenge can be solved in SIX BYTES! Go for it; you have nothing
else to do. ;-)
-Joe-
Oops, not true. The flash pointer that I had in mind doesn't add the
1 at the end, thus violating the rule that the first day number can't
be zero. Sorry. The flash pointer is ^QAddMod, which is essentially
<< UNROT + SWAP MOD >>. Input: team, team, size of league (all as
integers!); output: game day or bye day (base zero).
-Joe-
Almost as small using reals
::
%+SWAP
%MOD
%1+
;
-wes