palin.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. /*
  30. Test suite.
  31. This program takes the palindrome below and checks if it's
  32. a palindrome or not. It will hopefully exhibit an interesting
  33. page fault pattern.
  34. The palindrome was taken from
  35. http://www.cs.brown.edu/people/nfp/palindrome.html
  36. This is not large enough to really stress the VM system, but
  37. might be useful for testing in the early stages of the VM
  38. assignment.
  39. */
  40. /*
  41. A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop,
  42. a pint, a catalpa, a gas, an oil, a bird, a yell, a vat, a caw, a pax,
  43. a wag, a tax, a nay, a ram, a cap, a yam, a gay, a tsar, a wall, a
  44. car, a luger, a ward, a bin, a woman, a vassal, a wolf, a tuna, a nit,
  45. a pall, a fret, a watt, a bay, a daub, a tan, a cab, a datum, a gall,
  46. a hat, a fag, a zap, a say, a jaw, a lay, a wet, a gallop, a tug, a
  47. trot, a trap, a tram, a torr, a caper, a top, a tonk, a toll, a ball,
  48. a fair, a sax, a minim, a tenor, a bass, a passer, a capital, a rut,
  49. an amen, a ted, a cabal, a tang, a sun, an ass, a maw, a sag, a jam,
  50. a dam, a sub, a salt, an axon, a sail, an ad, a wadi, a radian, a
  51. room, a rood, a rip, a tad, a pariah, a revel, a reel, a reed, a pool,
  52. a plug, a pin, a peek, a parabola, a dog, a pat, a cud, a nu, a fan,
  53. a pal, a rum, a nod, an eta, a lag, an eel, a batik, a mug, a mot, a
  54. nap, a maxim, a mood, a leek, a grub, a gob, a gel, a drab, a citadel,
  55. a total, a cedar, a tap, a gag, a rat, a manor, a bar, a gal, a cola,
  56. a pap, a yaw, a tab, a raj, a gab, a nag, a pagan, a bag, a jar, a
  57. bat, a way, a papa, a local, a gar, a baron, a mat, a rag, a gap, a
  58. tar, a decal, a tot, a led, a tic, a bard, a leg, a bog, a burg, a
  59. keel, a doom, a mix, a map, an atom, a gum, a kit, a baleen, a gala,
  60. a ten, a don, a mural, a pan, a faun, a ducat, a pagoda, a lob, a rap,
  61. a keep, a nip, a gulp, a loop, a deer, a leer, a lever, a hair, a pad,
  62. a tapir, a door, a moor, an aid, a raid, a wad, an alias, an ox, an
  63. atlas, a bus, a madam, a jag, a saw, a mass, an anus, a gnat, a lab,
  64. a cadet, an em, a natural, a tip, a caress, a pass, a baronet, a
  65. minimax, a sari, a fall, a ballot, a knot, a pot, a rep, a carrot,
  66. a mart, a part, a tort, a gut, a poll, a gateway, a law, a jay, a sap,
  67. a zag, a fat, a hall, a gamut, a dab, a can, a tabu, a day, a batt,
  68. a waterfall, a patina, a nut, a flow, a lass, a van, a mow, a nib,
  69. a draw, a regular, a call, a war, a stay, a gam, a yap, a cam, a ray,
  70. an ax, a tag, a wax, a paw, a cat, a valley, a drib, a lion, a saga,
  71. a plat, a catnip, a pooh, a rail, a calamus, a dairyman, a bater,
  72. a canal - Panama!
  73. */
  74. /* The palindrome below is a quadruple concatenation of the above */
  75. #include <stdio.h>
  76. #include <string.h>
  77. char palindrome[8000] =
  78. "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
  79. "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
  80. "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
  81. "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
  82. "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
  83. "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
  84. "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
  85. "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
  86. "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
  87. "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
  88. "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
  89. "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
  90. "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
  91. "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
  92. "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
  93. "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
  94. "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
  95. "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
  96. "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
  97. "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
  98. "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama"
  99. "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
  100. "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
  101. "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
  102. "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
  103. "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
  104. "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
  105. "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
  106. "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
  107. "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
  108. "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
  109. "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
  110. "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
  111. "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
  112. "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
  113. "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
  114. "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
  115. "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
  116. "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
  117. "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
  118. "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
  119. "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama"
  120. "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
  121. "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
  122. "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
  123. "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
  124. "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
  125. "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
  126. "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
  127. "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
  128. "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
  129. "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
  130. "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
  131. "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
  132. "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
  133. "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
  134. "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
  135. "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
  136. "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
  137. "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
  138. "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
  139. "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
  140. "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama"
  141. "amanaplanacaretabanamyriadasumalacaliarahoopapintacatalpaagasanoil"
  142. "abirdayellavatacawapaxawagataxanayaramacapayamagayatsarawalla"
  143. "caralugerawardabinawomanavassalawolfatunaanitapallafretawattabaya"
  144. "daubatanacabadatumagallahatafagazapasayajawalayawetagallopatuga"
  145. "trotatrapatramatorracaperatopatonkatollaballafairasaxaminimatenora"
  146. "bassapasseracapitalarutanamenatedacabalatangasunanassamawasaga"
  147. "jamadamasubasaltanaxonasailanadawadiaradianaroomaroodaripatada"
  148. "pariaharevelareelareedapoolaplugapinapeekaparabolaadogapatacudanua"
  149. "fanapalarumanodanetaalaganeelabatikamugamotanapamaximamooda"
  150. "leekagrubagobageladrabacitadelatotalacedaratapagagaratamanorabara"
  151. "galacolaapapayawatabarajagabanagapaganabagajarabatawayapapaa"
  152. "localagarabaronamataragagapataradecalatotaledaticabardalegaboga"
  153. "burgakeeladoomamixamapanatomagumakitabaleenagalaatenadonamurala"
  154. "panafaunaducatapagodaalobarapakeepanipagulpaloopadeeraleeralevera"
  155. "hairapadatapiradooramooranaidaraidawadanaliasanoxanatlasabusamadam"
  156. "ajagasawamassananusagnatalabacadetanemanaturalatipacaressapassa"
  157. "baronetaminimaxasariafallaballotaknotapotarepacarrotamartapartatorta"
  158. "gutapollagatewayalawajayasapazagafatahallagamutadabacanatabuaday"
  159. "abattawaterfallapatinaanutaflowalassavanamowanibadrawaregularacalla"
  160. "warastayagamayapacamarayanaxatagawaxapawacatavalleyadribaliona"
  161. "sagaaplatacatnipapooharailacalamusadairymanabateracanalpanama";
  162. int
  163. main()
  164. {
  165. char *start, *end;
  166. printf("Welcome to the palindrome tester!\n");
  167. printf("I will take a large palindrome and test it.\n");
  168. printf("Here it is:\n");
  169. printf("%s\n", palindrome);
  170. printf("Testing...");
  171. /* skip to end */
  172. end = palindrome+strlen(palindrome);
  173. end--;
  174. for (start = palindrome; start <= end; start++, end--) {
  175. putchar('.');
  176. if (*start != *end) {
  177. printf("NOT a palindrome\n");
  178. return 0;
  179. }
  180. }
  181. printf("IS a palindrome\n");
  182. return 0;
  183. }