<?xml version="1.0" encoding="windows-1252"?>
<node id="89649" title="Re: Pig Latin" created="2001-06-19 14:41:04" updated="2005-07-29 12:48:26">
<type id="11">
note</type>
<author id="79000">
davisagli</author>
<data>
<field name="doctext">
&lt;p&gt;I had some fun with this. My shortest fully-functional attempt is this 60-character
  regexp:
  &lt;blockquote&gt;&lt;code&gt;s/\b(qu|y(?=[^t])|[^\W\daeiouy]*)([a-z']+)/$2.($1||w).ay/eg;&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;with these features:&lt;br&gt;
&lt;ul&gt;&lt;li&gt;Handles multiple consonants at start of word (and handles 'qu' correctly)
&lt;li&gt;Correctly handles y-related idiosyncrasies: yummy becomes ummyyay, but yttrium
  becomes yttriumway and rhythm becomes ythmrhay
&lt;li&gt;Handles numbers correctly (42 doesn't become 42ay)
&lt;li&gt;Counts apostrophe as part of word, so &amp;quot;don't&amp;quot; becomes &amp;quot;on'tday&amp;quot;
  (and handles other punctuation correctly)&lt;/ul&gt;
&lt;p&gt; Note that if we ignore two words (yttrium and ytterbium), we can safely bring it
  down to 52 chars:
  &lt;blockquote&gt;&lt;code&gt;s/\b(qu|y|[^\W\daeiouy]*)([a-z']+)/$2.($1||w).ay/eg;&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;And if we decide to switch to the dialect of pig latin that doesn't add 'w' on
  vowel-words, it's down to 44:
  &lt;blockquote&gt;&lt;code&gt;s/\b(qu|y|[^\W\daeiouy]*)([a-z']+)/$2$1ay/g;&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;If I combine that with [perlmonkey]'s attempt (losing a bit of functionality 
  in the process, although it still works pretty well) I can reach 36:
  &lt;blockquote&gt;&lt;code&gt;s/(qu|y|[^aeiouy\s]*)(\w+)/$2$1ay/g;&lt;/code&gt;&lt;/blockquote&gt;
&lt;p&gt;Also note that my (un-golfed) attempt at a pig latin converter in Visual 
  Basic took up almost 3500 characters (!) without handling nearly all of the 
  exceptions mentioned here. This is (one of the many reasons) why I love Perl!&lt;/p&gt;
&lt;p&gt;Thanks to everyone for their previous attempts, which helped me quite a bit.  Comments are welcome.&lt;/p&gt;

&lt;p&gt;-[davisagli]&lt;/p&gt;</field>
<field name="root_node">
3586</field>
<field name="parent_node">
3586</field>
</data>
</node>
