<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Snipplr</title>
    <description>Recent snippets posted on Snipplr.com</description>
    <link>https://snipplr.com/</link>
    <lastBuildDate>Sat, 13 Jun 2026 15:31:44 +0000</lastBuildDate>
    <item>
      <title>(Haskell) Linked List in C - rtperson</title>
      <link>https://snipplr.com/view/68865/linked-list-in-c</link>
      <description>&lt;p&gt;I bit of overkill for USACO's "Milk2" algorithm training problem. This problem would be better suited to an interval tree, but here it is.&lt;/p&gt;</description>
      <pubDate>Sun, 02 Dec 2012 12:32:20 UTC</pubDate>
      <guid>https://snipplr.com/view/68865/linked-list-in-c</guid>
    </item>
    <item>
      <title>(Haskell) Binary Search in Haskell - rtperson</title>
      <link>https://snipplr.com/view/68840/binary-search-in-haskell</link>
      <description>&lt;p&gt;Improved version, using lenses instead of the dangerous (!!) operator for list access.&lt;/p&gt;</description>
      <pubDate>Fri, 30 Nov 2012 14:16:50 UTC</pubDate>
      <guid>https://snipplr.com/view/68840/binary-search-in-haskell</guid>
    </item>
    <item>
      <title>(Haskell) Haskell 99 Problems - Problem 23 - rtperson</title>
      <link>https://snipplr.com/view/58582/haskell-99-problems--problem-23</link>
      <description>&lt;p&gt;problem 23, Extract a given number of randomly selected elements from a list. &#13;
    Example:&#13;
&#13;
    Prelude System.Random&gt;rnd_select "abcdefgh" 3 &gt;&gt;= putStrLn&#13;
&#13;
        "eda"&#13;
        &#13;
    Two problems: 1) How to return a list, and 2) how to sample without duplication&lt;/p&gt;</description>
      <pubDate>Sat, 10 Sep 2011 07:27:49 UTC</pubDate>
      <guid>https://snipplr.com/view/58582/haskell-99-problems--problem-23</guid>
    </item>
    <item>
      <title>(Haskell) Haskell 99 Problems, numbers 1 through 9 - rtperson</title>
      <link>https://snipplr.com/view/58509/haskell-99-problems-numbers-1-through-9</link>
      <description>&lt;p&gt;I had originally started these problems from #10 (Run-length encoding). I went back and did 1-8 for completeness.&lt;/p&gt;</description>
      <pubDate>Thu, 08 Sep 2011 00:23:54 UTC</pubDate>
      <guid>https://snipplr.com/view/58509/haskell-99-problems-numbers-1-through-9</guid>
    </item>
    <item>
      <title>(Haskell) Haskell 99 Problems - Number 20,  Arrowed! - rtperson</title>
      <link>https://snipplr.com/view/58144/haskell-99-problems--number-20--arrowed</link>
      <description>&lt;p&gt;problem 20, (*) Remove the K'th element from a list&#13;
&#13;
    *Main&gt; removeAt 1 "abcd"&#13;
        "acd"&#13;
&#13;
Trivial using a pure function. A bit more challenging if you use this problem to work up your Arrow-fu.&lt;/p&gt;</description>
      <pubDate>Thu, 25 Aug 2011 01:54:30 UTC</pubDate>
      <guid>https://snipplr.com/view/58144/haskell-99-problems--number-20--arrowed</guid>
    </item>
    <item>
      <title>(Haskell) Haskell 99 Problems - Number 17 - rtperson</title>
      <link>https://snipplr.com/view/57981/haskell-99-problems--number-17</link>
      <description>&lt;p&gt;problem 17, Split a list into two parts; the length of the first part is given. &#13;
    Do not use any predefined predicates. (Meaning no splitAt or take or drop)&#13;
    *Main&gt; split "abcdefghik" 3&#13;
            ("abc", "defghik")&lt;/p&gt;</description>
      <pubDate>Thu, 18 Aug 2011 06:50:09 UTC</pubDate>
      <guid>https://snipplr.com/view/57981/haskell-99-problems--number-17</guid>
    </item>
    <item>
      <title>(Haskell) Haskell 99 Problems - Numbers 15 and 16 - rtperson</title>
      <link>https://snipplr.com/view/57971/haskell-99-problems--numbers-15-and-16</link>
      <description>&lt;p&gt;problem 15, Replicate the elements of a list a given number of times. &#13;
    &gt; repli "abc" 3&#13;
        "aaabbbccc"&#13;
&#13;
    problem 16, Drop every N'th element from a list. &#13;
    *Main&gt; dropEvery "abcdefghik" 3&#13;
        "abdeghk"&lt;/p&gt;</description>
      <pubDate>Thu, 18 Aug 2011 03:59:30 UTC</pubDate>
      <guid>https://snipplr.com/view/57971/haskell-99-problems--numbers-15-and-16</guid>
    </item>
    <item>
      <title>(Haskell) Haskell 99 Problems - Number 14 - rtperson</title>
      <link>https://snipplr.com/view/57921/haskell-99-problems--number-14</link>
      <description>&lt;p&gt;problem 14, Duplicate the elements of a list&#13;
    &gt; dupli [1, 2, 3]&#13;
        [1,1,2,2,3,3]&lt;/p&gt;</description>
      <pubDate>Thu, 18 Aug 2011 01:04:04 UTC</pubDate>
      <guid>https://snipplr.com/view/57921/haskell-99-problems--number-14</guid>
    </item>
    <item>
      <title>(Haskell) Haskell 99 Problems - Solutions to 11 and 12 - rtperson</title>
      <link>https://snipplr.com/view/57309/haskell-99-problems--solutions-to-11-and-12</link>
      <description>&lt;p&gt;problem 11, modified run-length encoding&#13;
========================================&#13;
If an element has no duplicates, mark it as such. &#13;
&#13;
Example:&#13;
&#13;
    encodeModified "aaaabccaadeeee"&#13;
&#13;
    [Multiple 4 'a',Single 'b',Multiple 2 'c',&#13;
        Multiple 2 'a',Single 'd',Multiple 4 'e']&#13;
&#13;
problem 12, Decode a run-length encoded list. &#13;
=============================================&#13;
Given a run-length code list generated as specified in problem 11. Construct its uncompressed version. &#13;
&#13;
Example:&#13;
&#13;
    decodeModified &#13;
       [Multiple 4 'a',Single 'b',Multiple 2 'c',&#13;
        Multiple 2 'a',Single 'd',Multiple 4 'e']&#13;
&#13;
    "aaaabccaadeeee"&lt;/p&gt;</description>
      <pubDate>Fri, 29 Jul 2011 08:03:55 UTC</pubDate>
      <guid>https://snipplr.com/view/57309/haskell-99-problems--solutions-to-11-and-12</guid>
    </item>
    <item>
      <title>(Haskell) Run-Length Encoding in Haskell - rtperson</title>
      <link>https://snipplr.com/view/57300/runlength-encoding-in-haskell</link>
      <description>&lt;p&gt;Problem 10 of the famous 99 Problems. I got 99 problems, but a Lisp ain't one.&lt;/p&gt;</description>
      <pubDate>Fri, 29 Jul 2011 06:08:49 UTC</pubDate>
      <guid>https://snipplr.com/view/57300/runlength-encoding-in-haskell</guid>
    </item>
    <item>
      <title>(Haskell) Towers of Hanoi by Bit Twiddling - rtperson</title>
      <link>https://snipplr.com/view/56194/towers-of-hanoi-by-bit-twiddling</link>
      <description>&lt;p&gt;Credit where it's due: I got this from udpn over at codereview.stackexchange.com. I'm just putting it here for further study.&lt;/p&gt;</description>
      <pubDate>Thu, 07 Jul 2011 01:45:07 UTC</pubDate>
      <guid>https://snipplr.com/view/56194/towers-of-hanoi-by-bit-twiddling</guid>
    </item>
    <item>
      <title>(Haskell) Towers of Hanoi in Haskell - rtperson</title>
      <link>https://snipplr.com/view/56191/towers-of-hanoi-in-haskell</link>
      <description>&lt;p&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 07 Jul 2011 01:05:06 UTC</pubDate>
      <guid>https://snipplr.com/view/56191/towers-of-hanoi-in-haskell</guid>
    </item>
    <item>
      <title>(Haskell) Real World Haskell Exercise - Ch 4 - rtperson</title>
      <link>https://snipplr.com/view/54660/real-world-haskell-exercise--ch-4</link>
      <description>&lt;p&gt;The first fold exercise from RWH, Chapter 4&lt;/p&gt;</description>
      <pubDate>Wed, 01 Jun 2011 01:00:47 UTC</pubDate>
      <guid>https://snipplr.com/view/54660/real-world-haskell-exercise--ch-4</guid>
    </item>
    <item>
      <title>(Haskell) Real World Haskell Exercise - Ch 4, Ex 2-4 - rtperson</title>
      <link>https://snipplr.com/view/54659/real-world-haskell-exercise--ch-4-ex-24</link>
      <description>&lt;p&gt;I'm posting the rest of these, mostly because I'm still patting myself on the back for my point-free implementation of exercise 3, and because I give myself about two months before I entirely forget how I did it...&lt;/p&gt;</description>
      <pubDate>Wed, 01 Jun 2011 00:59:27 UTC</pubDate>
      <guid>https://snipplr.com/view/54659/real-world-haskell-exercise--ch-4-ex-24</guid>
    </item>
    <item>
      <title>(Haskell) Fibonacci List One-Liner in Haskell - rtperson</title>
      <link>https://snipplr.com/view/54657/fibonacci-list-oneliner-in-haskell</link>
      <description>&lt;p&gt;I didn't invent this, but it's too cool a snippet not to capture. Here's a one-liner that will generate a list of Fibonacci numbers in linear time.&#13;
&#13;
EXPLANATION: the colon operator is used to add elements to a list, so it starts out adding on the two base cases, zero and one. After you have these two, you can mathematically generate the rest of the list. The zipWith function takes two lists and combines them using a function (in this case, addition). The two lists in question are fiblist (that is, the list you're currently generating) and "tail fiblist" (that is, every element of the list after the first element). &#13;
&#13;
The only reason this works is because Haskell's laziness gives it the ability to define infinite lists. Haskell will never even attempt to calculate the nth Fibonacci number until it is asked to do so.&lt;/p&gt;</description>
      <pubDate>Wed, 01 Jun 2011 00:44:37 UTC</pubDate>
      <guid>https://snipplr.com/view/54657/fibonacci-list-oneliner-in-haskell</guid>
    </item>
    <item>
      <title>(Haskell) Haskell Radix Conversion using ByteStrings - rtperson</title>
      <link>https://snipplr.com/view/54655/haskell-radix-conversion-using-bytestrings</link>
      <description>&lt;p&gt;Another radix conversion, when you need to zippy greatness of Haskell's ByteString.(Haskell strings are slooooow!)&#13;
&#13;
TODO: rewrite this using overloaded strings.&lt;/p&gt;</description>
      <pubDate>Wed, 01 Jun 2011 00:30:19 UTC</pubDate>
      <guid>https://snipplr.com/view/54655/haskell-radix-conversion-using-bytestrings</guid>
    </item>
    <item>
      <title>(Haskell) Haskell Radix Conversion - rtperson</title>
      <link>https://snipplr.com/view/54654/haskell-radix-conversion</link>
      <description>&lt;p&gt;Converts an integer from base 10 to a string of base x (where 0 &gt; x &gt;= 20). The only thing I'd improve is getting rid of all the calls to error. Perhaps hand back a Maybe String that simply hands back Nothing if unable to convert the number.&lt;/p&gt;</description>
      <pubDate>Wed, 01 Jun 2011 00:26:01 UTC</pubDate>
      <guid>https://snipplr.com/view/54654/haskell-radix-conversion</guid>
    </item>
    <item>
      <title>(Haskell) FizzBuzz in Haskell - rtperson</title>
      <link>https://snipplr.com/view/54653/fizzbuzz-in-haskell</link>
      <description>&lt;p&gt;The dread FizzBuzz question -- really, a test if your average programmer knows his or her FOR loops. The spec is that you're counting from 1 to 100. Your program should print out "fizz" if the index is divisible by three, and "buzz" if it's divisible by five, and "fizzbuzz" if it's divisible by both.&#13;
&#13;
I have a couple different versions in this code: first, a few functions just fizzing or buzzing. Second, a generalization which allows any standard message against any divisor. Third, a purely functional version that zips two lists together (giving us free concatenation for "fizzbuzz"). Fourth, a list comprehension and lastly, a monadic version that calls a pure function that uses guards.&lt;/p&gt;</description>
      <pubDate>Wed, 01 Jun 2011 00:14:43 UTC</pubDate>
      <guid>https://snipplr.com/view/54653/fizzbuzz-in-haskell</guid>
    </item>
  </channel>
</rss>
