Funny Programming in Delphi - Hares and Pheasants


An hunting event has been organized by local gamekeepers community. At the end of the event all hunters were interested in results, i.e. how many hares and pheasants were shot. Because gamekeepers were extremely tired, they weren't able to distinguish between hare and pheasant. A local teacher got an idea: "We count all shot animals and total figure of their legs. Based on these facts, we should be able to determine particular totals of hares and pheasants.".

Used variables

  • KS - real count of heads
  • NOHY - total count of legs
  • KUSY - calculated count of heads (changes by every loop pass, at the end it will have the same value as variable KS)
  • ZAJ - count of hares (changes by every loop pass, at the end it will have value of real count of hares)
  • BAZ - count of pheasants (changes by every loop pass, at the end it will have value of real count of pheasants)

procedure TForm2.Button1Click(Sender: TObject);
 var Nohy, Ks, Kusy, Baz, Zaj, Test:Integer;
   if NOHY <= 4*KS                   //No animal can have more than 4 legs
         if NOHY >= 2*KS             //No animal can have less than 2 legs
                  TEST := NOHY div (2);   //test of divisibility by 2
                  TEST := TEST*2;
                  if NOHY = TEST
                     then            //All the nonsense values are out of question,
                        begin        //we can calculate
                           ZAJ := 0;       //Initial settings - no hare,
                           BAZ := NOHY div (2);  //all pheasants
                           KUSY := ZAJ + BAZ;   //We'll try how many heads it would be

                           //While loop
                           while KUSY > KS do   //Until there are more test heads than real ones
                              ZAJ := ZAJ + 1;   //One hare is added
                              BAZ := BAZ - 2;   //Two pheasants are removed
                              KUSY := ZAJ + BAZ;  //Heads recalculated
                           ShowMessage('Hares '+IntToStr(ZAJ)+ ', Pheasants ' +IntToStr(BAZ));
                     else             //Odd count of legs
                        ShowMessage('Animals with odd count of legs are not accepted:-)');
               ShowMessage ('Each animal must have at least two legs! ')
         ShowMessage ('No animal can have more than four legs! ');


Our new series of articles focused on practical using of algorithms should show how to use some mathematical and statistical methods for solving real life tasks and issues.

Sample project regarding this topic can be downloaded from here.

About the Author

Ing. Jana Pšenčíková

More interesting links and pages

Visit to get the best casino value in Finland

If you are going to play online casino in Canada you better visit the Genie first


Casino Online Romania

Time Calculator

Wheel of Fortune Answers

Discover UK licensed casino sites at Casinopilot

Check out Valforex reviews

Efortuna Casino

Scrummaster and Agile trainings

Word Unscrambler

China Wholesale Suppliers Directory

Free Angram Solver

Syllable Word Counter

Printable Sudoku Puzzles

Download Instagram Stories

Word Search Puzzles

Try out new casino sites at

Percentage Calculator


Indian casinos are here to stay and Royal Panda is your top choice

Best online roulette Nederland CasinoHEX

Play blackjack at the best live dealer casino online in the UK

Online Casino


Our favorite online real-money casinos in Austria on is a great opportunity to enjoy all the benefits of playing for real money.