Skip to content

Instantly share code, notes, and snippets.

View meta4's full-sized avatar

Peter Wilson meta4

  • Orange County, CA
View GitHub Profile

Keybase proof

I hereby claim:

  • I am meta4 on github.
  • I am petewilson (https://keybase.io/petewilson) on keybase.
  • I have a public key whose fingerprint is 2BAE C866 FF28 5F74 D6A7 86A1 3704 1200 986D 2199

To claim this, I am signing this object:

@meta4
meta4 / p24solver.py
Last active March 9, 2017 01:39
My 24-puzzle solver. Based on comments at http://blog.plover.com/math/24-puzzle.html.
# -*- coding: utf-8 -*-
"""Wed Mar 08, 2017 - 05:12 - Pete Wilson
Written after reading http://blog.plover.com/math/24-puzzle.html
Can be run from the command line with a string describing the puzzle.
Like so:
python p24solver.py "2 5 6 6 -> 17"

Easy XML production using Lazy Evaluation, Closures, Currying, operator overloading.

Introduction

This document explains a perl package I created to write XML the way CGI.pm writes HTML using nested functions. The functions in this package take a list of entity contents to enclose between XML tags. They also take an optional hash reference specifying arbitrary XML attributes. Some of the entity contents might be nested XML entities, which include their own tags, attributes, contents, sub-entities, etc. The resulting nesting of XML elements should correspond directly to nested function calls in the code creating the XML fragment.

Motivation

This article to explores lazy evaluation, closures, currying function arguments, with a splash of operator overloading for that last little bit of syntactic sugar. If you don't know what these things are, or you have never seen a demonstration of how powerful they can be, especially when combined, you might find the following interesting.