tag:blogger.com,1999:blog-32868892024-03-13T21:51:55.592-05:00Aging Nerd Notesrandom notes and thoughts, mostly about Haskell these days, of a rather past middle-aged programmerUnknownnoreply@blogger.comBlogger134125tag:blogger.com,1999:blog-3286889.post-8498122276143460352020-05-26T22:11:00.000-05:002020-05-26T22:13:56.693-05:00Riddler Classic, May 23, 2020—Holy Mackerel!Another one using Peter Norvig's word list.
It turns out that the word "mackerel" has a curious property: there is exactly one of the fifty states that it has no letters in common with. So we will call a word with that property "a mackerel". There are quite a few of them. (It doesn't matter which state name is the unique one disjoint from the word. The state for "mackerel" is Ohio, but for "Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-61256789074715795462020-02-10T17:32:00.000-06:002020-02-14T09:32:49.323-06:00Riddler Classic, Feb 7, 2020Sometimes I can figure out the solution to either the Riddler Express or Riddler Classic. This week is the first time I'm reasonably confident I have them both.
It helped that Riddler Express was really, really easy this time. Riddler Classic, though, takes some more thought.
It started with a math professor, James Propp, whose child asked about the vertical bars used in math notation for Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-42379381968153229232019-06-27T10:19:00.000-05:002019-06-27T10:19:45.414-05:00A flashback and analogyYou've probably heard about how the notion of sum types (e.g. Algol 68 unions, Rust enums, Haskell types) and product types (e.g. tuples or structs) generalizes, e.g. [a] can be thought of as ${a^0} + {a^1} + {a^2} + {a^3} + ...$ where the exponent corresponds to the length of the list.
This morning I had a flashback from that to my days in introductory numerical analysis and Taylor series, Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-48306624287221624072019-06-21T20:41:00.000-05:002019-06-21T20:46:57.875-05:00I wish I were a dogAs I've mentioned recently, I'm now in a Meetup for people in the Des Moines, IA area where we're seriously doing the problems and paying close attention to the text, so I noticed this function intended to map your dog's age in years to a corresponding age in people years, while also introducing the beginning Haskell programmer to guards:
dogYrs :: Integer -> Integer
dogYrs x
| xUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-75931402686038859562019-06-10T13:00:00.003-05:002019-06-10T13:00:45.391-05:00"Assignment" versus parameter passingIt's been a while. Still looking for work, but I'm happy to say that there is now a Des Moines area meetup for people learning Haskell, so that I'm going through Haskell Programming from First Principles more seriously this time and doing all the exercises.
Thanks to that, I realize that one can express the one well-behaved function of type a -> b -> a as curry fst, but I am confused by Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-72357815148988044332018-01-30T13:37:00.000-06:002018-01-30T13:37:06.581-06:00Trailing zeroesA week or so ago someone mentioned the following problem:
How many trailing zeroes does 1000! have [when written out in base ten, of course]?
Easy enough to find...
Prelude> length $ takeWhile (== '0') $ reverse (show (product [1..1000]))
249Prelude>
But is there a better way? Yes, there is. After reading that someone said he did it in his head, the way to do it in your head Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-50177385177344966572017-09-27T14:14:00.000-05:002017-09-27T16:10:02.565-05:00Sum of multiples problemOne of the exercism.io problems generalizes a Project Euler problem: what's the sum of multiples of 3 and 5 less than 1000? Seems simple enough:
sum [3, 6..999] + sum [5, 10..999]
but that's too big; it counts some values twice. With a little thought, though, you'll realize that the duplicates are the multiples of 15, so
sum [3, 6..999] + sum [5, 10..999] - sum[15, 30..999]
will do Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-16638026342558455042017-08-06T22:39:00.001-05:002017-08-07T09:58:23.965-05:00a longest path problemfivethirtyeight.com has a weekly column, "The Riddler". The Riddler poses two problems in each column. The first, "Riddler Express", is intended to be an easier problem that one can solve quickly, while the second, "Riddler Classic", is more difficult. Modulo vacations, it appears each Friday, and if you submit a solution by the end of the following Sunday (Eastern Time) , you will be among thoseUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-42291939971083032412017-06-15T19:49:00.002-05:002017-06-15T19:49:20.747-05:00Bikeshedding leap yearsDarn it, I fell into the trap. An early exercise in Python at exercism.io wants a function that in Haskell would have the type Int -> Bool and indicate whether a year is a leap year (under Gregorian rules, ignoring when various locales made the switch to keep it simple).
Some submissions are from people not yet comfortable with assigning/returning Booleans other than the constants Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-63082481468174408562017-06-06T05:07:00.000-05:002017-06-06T05:07:31.013-05:00Restaurants shooting themselves in the footIt's pet peeve time, and here it is: restaurants that display graphic images of their menu on the web. Sometimes it's a PDF made up of graphics, sometimes it's just graphics.
I wish I had a nickel for each restaurant I really like whose web site suffers from this problem... though perhaps I should shoot for more than that by offering my services to fix their web sites. A few examples:
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-39800026846637679012017-04-02T16:13:00.000-05:002017-04-02T16:14:21.069-05:00No tutorial, I swear...After grinding through much of the "20 Intermediate Exercises" and just about all of the Monad Challenges, Monads make much more sense to me.
Therefore, I will follow the excellent advice of Stephen Diehl, and will not write a monad-analogy tutorial. Instead, I will say: do the 20 Intermediate Exercises, and take the Monad Challenges. To paraphrase Euclid, there is no royal road to Monads; the Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-92124506056972836842017-03-24T10:41:00.000-05:002017-03-24T11:53:16.257-05:00Flipping outI came across the excellent Monad Challenges, a collection of exercises designed to take you through what have become some of the standard example monads and take you through the process that motivates monads as a way to handle these seemingly diverse data structures. Both the Monad Challenges and the 20 Intermediate Exercises are well worth your time. Doing them both is helping me a lot.
That Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-74299834044299874462017-03-03T16:21:00.000-06:002017-03-03T20:56:36.117-06:00Trust in SchönfinkelI'm working through the "20 Intermediate Exercises" that give Functors and Monads and such cute, non-threatening names and ask you to implement them. I've gotten most of the way through, with three or four that I'm stuck on--that's under the assumption that the inductive step from banana to banana2 will make the rest of the banana<n> obvious. (If you have sausage, it's easy to implement Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-11255755108864564342017-01-23T20:52:00.000-06:002017-01-23T20:52:05.795-06:00Careful with that infinite list, Eugene...Warning: this will give away one way to solve a certain low-numbered Project Euler problem.
Any Haskell book, blog, or tutorials you come across has a good chance of including the très élégant Haskell one-liner for an infinite list containing the Fibonacci sequence:
fibs = 0 : 1 : (zipWith (+) fibs (tail fibs))
Thanks to laziness, it will only evaluate out to the last term we actually request.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-62121900009954236892016-10-05T23:19:00.001-05:002016-10-05T23:19:49.637-05:00TMTOWTDI, Haskell StyleI assure you there will be no further allusions to Korean earworms. That said, on to the subject at hand...
Remember the exercise in the online Haskell course that had several tests to filter out weak passwords, all of which had to pass for the fictitious system to allow a String value to be used as a password? I wanted to make it easy to change, so I wanted to take a [String -> Bool] and getUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-42732224158141653762016-03-28T21:09:00.003-05:002016-03-28T21:09:37.355-05:00Haskell Tool Stack for Ubuntu 16.04I've upgraded to Ubuntu 16.04 beta 2, and so far, as I've read elsewhere, it's working very nicely.
(One warning: if you have apcupsd installed, turn it off before upgrading! During the upgrade, something happens that causes the UPS battery to look fully discharged, and apcupsd will obligingly shut your system down... in mid-upgrade. Others have seen this when upgrading to 15.10.)
Now I'm Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3286889.post-22528365544574653122016-01-10T13:42:00.000-06:002016-01-10T13:42:05.561-06:00A rather long blast from the past about recursion elimination and a bit of complexity theory
While going through
old papers, I found something I wrote as a follow-up to an article by
Aaron Banerjee in the February 1999 issue of the world
of 68’ micros (you
can find a somewhat mangled version online here).
Both concern recursion elimination, with the well-known “eight
queens” problem (place eight queens on a chess board so that none
attacks any other) as an example.
I don’t remember
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-78539297726988094702015-12-26T05:31:00.002-06:002015-12-26T05:31:28.259-06:00Advent of CodeI seem to always come in late on these things, but I hope this one will stay around for a while so I can get through it all.
The Advent of Code site features one problem a day from December 1 through December 25. (Actually two, but the problems for any given day are related, the second being a variation or extension of the first.) The problems have cute Santa-related back stories. You can use Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-57012003527256114382015-03-03T20:50:00.000-06:002015-03-03T20:50:21.284-06:00"I want my xfce...."Sorry, Mr. Knopfler, it doesn't scan--but it is the truth.
I am now the proud owner of two Raspberry Pi 2s, computers we would have killed for back in the 80s. I have "Raspbian" running on them. (It's a version that apparently will run on the 1 (an ARMv6) and on the 2 (a four-core ARMv7); I definitely want to build it targeting the ARMv7.)
Anyway--it comes up with LXDE for a windowing Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3286889.post-60807581798369111872014-07-20T04:41:00.003-05:002014-07-20T04:41:31.969-05:00Flashback, Part TwoLast time we found that our program to count ways to make change, while much better than the engineering class's brute force nested DO loops, isn't up to snuff.
There is a better way, it turns out. If you look at the Rosetta Code entry for this problem, which they call "Count the Coins", you'll find a number of approaches. For Haskell, there are two. The first "naive" program is essentially whatUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-20409633272092034222014-07-19T20:18:00.002-05:002014-07-19T20:18:27.993-05:00FlashbackBack in the Cretaceous era I worked at the University of Oklahoma as a student assistant at Remote 1. OU was a [shudder] IBM big iron shop at the time, and beginning students typically got a job class that limited CPU time to thirty seconds, lest a beginner submit a program with an endless loop and chew up serious resources. (And when the computer everyone's sharing is a 370 of mid-1970s vintage,Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-3286889.post-76035480173241266692014-07-14T22:28:00.000-05:002014-07-14T22:28:00.013-05:002010 Code Jam problem: "Store Credit"A fellow on the haskell-beginners mailing list asked for suggestions on how to improve code he'd written to solve a 2010 Code Jam qualifying problem, "Store Credit". Here's the problem statement:
"You receive a credit C at a local store and would like to buy two items. You first walk through the store and create a list L of all available items. From this list you would like to buy two items thatUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-47528994697941764972014-06-18T02:25:00.000-05:002014-06-19T03:58:06.647-05:00Look and say sequenceIf I don't already have the Haskell subreddit link over on the right, I'll add it ASAP.
This evening a Haskell beginner posted about some trouble he was having writing code to generate a particular sequence. I didn't catch on to the sequence he was going for, but I should have from a comment in his code:
enunBlock :: [Int] -> [Int] -- [2,2,2] -> [3,2] | [3] -> [1,3]
Someone didUnknownnoreply@blogger.com1tag:blogger.com,1999:blog-3286889.post-16370815226445749782014-04-13T04:39:00.001-05:002014-04-13T04:39:08.443-05:00Fun with pattern matchingI just noticed that I did something almost without thinking.
I'm still being lazy about dealing with inputs. I haven't gotten around to using one of the many elegant parser packages that Haskell makes possible, and the Code Jam problems I've tried so far haven't required much more than skipping the leading line--kids, ask your grandparents about the card decks they would feed to their FORTRAN Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3286889.post-27061582110022761292014-04-12T22:40:00.000-05:002014-04-18T07:11:32.595-05:00Well, drat... *spoiler alert*I didn't do well in the qualifying round of Code Jam this year, alas. Part of it I can thank the IRS for, in a way, because we paid our annual last-minute visit to H&R Block today. But really it's my fault; I didn't arrange to have the interval during which one could enter solutions clear to devote to it.
I didn't get my improved version of Cookie Clicker Alpha done in time to count, but Unknownnoreply@blogger.com0