GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

GIGO: words unreadable aloud

  Thursday 31 October 2002
Luhn-acy in Haskell, Scala, and yet another Python version

Joey "Happiest Accordian Guyeek" de Villa has a couple of weblog entries about the Luhn Algorithm, used for a checksum on some credit card numbers. Joey has been getting some examples in several languages; I thought I'd contribute a Haskell version and a Scala version, and the recursive Python version that I did first.

Here's my Haskell one, tested (a little bit) on both hugs and GHC:

-- These five lines are the actual code:
luhn_sub 0 _ = 0
luhn_sub n m =
   (luhn_sub (n `div` 10) (3 - m)) + do_dig (m * (n `mod` 10))
   where do_dig n = if n <= 9 then n else n - 9
luhn str = (luhn_sub (read str) 1) `mod` 10 == 0

-- These five lines run a small pair of tests:
t9 base = (map (base ++) (map show [0..9]))
prTest = 
   let test_strs = concat $ map t9 ["234234", "5128960128"] in
   let results = map (\s -> (s ++ " -> " ++ show (luhn s))) 
test_strs in
   mapM_ putStrLn results


Thanks for blowing my whole damn day, Joey! :-D

Here's the Scala version: (see http://radio.weblogs.com/0100945/2002/07/04.html )

module Luhn with {
    def do_dig (dig: Long): Long = {
        if (dig <= 9) dig
        else dig-9;
    }
    def luhn_sub (nr:Long, mul:Long): Long = {
        if (nr == 0) { 0; }
        else {
            val d = mul * (nr % 10);
            luhn_sub(nr/10, 3-mul) + do_dig(d)
        }
    }
    // I guess the java.lang... call is the normal Scala way
    //  to convert a Scala string to a Long -- I can't figure out
    //  much from the Scala libraries.  Need Long instead of Int
    //  because them Credit Card numbers are big.
    def luhn (nrStr:String):Boolean = {
        val nr = java.lang.Long.parseLong(nrStr);
        val lsum = luhn_sub(nr, 1);
        lsum % 10 == 0
    }
    // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    //  Above is the Luhn algorithm code.  From here down, it's
    //   all just testing code.
    // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    def lrange (lo: Long, pastHi: Long): List[Long] = {
        if (lo >= pastHi) []
        else lo :: lrange(lo + 1, pastHi);
    }
    def test_tens () = {
        def tens (s:String) = {
            for( val dig <- lrange(0,10) ) yield {
                val sd = s + dig;
                System.out.println( "Luhn(" + sd + ") = " + luhn(sd) )
            }
        }
        tens( "234234" );
        tens( "5128960128" );
        nil
    }
}
Luhn.test_tens();


And, finally, here's the recursive Python version that preceded the other FP solutions:

def luhn( ccStr ):
    def do_dig ( d ):
        if d > 9: d -= 9
        return d
    def sub ( ccNr, mult ):
        if ccNr:
            return sub( ccNr/10, 3 - mult ) + 
                   do_dig( mult * (ccNr%10) )
        return 0
    return ( sub(long(ccStr),1) % 10) == 0

def test ( ):
    for tn in [ 234234, 5128960128 ]:
        for i in range(9):
            tnt = tn * 10 + int(i)
            print tnt, luhn(`tnt`)

if __name__ == '__main__':
    test()

12:43:32 AM   comment/     

  Wednesday 30 October 2002
Purse of the encavator

I started with "Grab Bag", as in "miscellaneous collection". It was the babelizer that turned it into the Purse of the Encavator.

Anyway, here are a few miscellaneous links I've encountered in the last few days ...

  • Weird mystery electrical equipment, from the "Mike's Electric Stuff" page ...

  • Coulrophobia is the official psychological term given to the irrational fear of clowns.

    I'll just add: it's not always irrational.

  • On his yellowtext weblog, Andy Inhatko sez:
    Something just occurred to me. The Beatles are missing one lead singer and one guitarist. The Who are now short a drummer and a bass player. Should these four guys at least take a meeting together or something?

    [ Andy calls his whole site "CWOB" — it seems only fitting for GIGO to have a link to "Collosal Waste Of Bandwidth", doesn't it? ]

  • Mac Net Journal had an entry a few days ago that talked about URL Manager Pro.

    There was also a pointer (from MNJ, I think) to a weblog about Applescript ...

    And it in turn had a link to X-Commands (at kanzu.com)

    "X-Commands contains nearly five dozen new commands for AppleScripters in Mac OS X. Some of the commands include:
    • Keyboard and mouse simulation
    • Autotype text (type key using command, etc)
    • System Info
    • Screen Info
    • Interface commands (display message, display progress)
    • String commands (hex to string, sort strings, etc.)
    Many example scripts are included.

12:32:03 AM   comment/     

  Tuesday 29 October 2002
Critique of Pure Riesling

Last month, I mentioned Bonny Doon vineyard and its eccentric but highly respected winemaker, Randall Grahm.

Oops, there are only three a's in Grahm's name.

I just got this season's email newsletter (PDF link), about Grahm's decision to lose the cork. There is a recent article here in a New Jersey paper.

Roughly ten years ago, Deb & I were spending a week in Austin. Visited a very nice restaurant (the City Grille?, on Town Lake) for dinner one night, and discovered that their wine special that month was ... the Ca' de Solo "Big House Red", from Bonny Doon Vineyards.

Way back when they used to use corks. :-)
1:41:23 AM   comment/     


  Monday 28 October 2002
Make Score, Not War

Mikel Reparaz says that President Bush's eagerness to invade Iraq is due to his lack of experince with video games. Hoping to channel Mr. Bush's violent tendencies into a less harmful outlet, Reparaz ran a campaign to "Buy Bush a PlayStation 2". It was an overwhelming success.

[via wannabe girl.]
9:35:45 PM   comment/     


  Sunday 27 October 2002
Just Say Know

Four months ago, I wrote this:

"... the DEA has no more interest in truly curing the problem than the drug lords do."

Daniel Forbes, at Alternet, has written an article about the lengths to which the feds are going in order to refuse to listen to the voice of the people on this issue.

Drug Warriors Crusade Against Reform Initiatives

[via wood s lot]
12:06:34 AM   comment/     


  Saturday 26 October 2002
Jorn Barger on blogging and self-discovery

Robot Wisdom was the first personal weblog I ever spent much time reading, and Jorn still has interesting links and writes some interesting essays. This week, he wrote an essay about weblog writing and self-discovery.

Food for thought.
9:18:02 AM   comment/     


  Friday 25 October 2002
LL2 -- Lightweight Languages Workshop 2002

The second Lightweight Languages Worshop is to be held just over two weeks from now.

Saturday 9 November 2002, at MIT

I won't be going (I'm hoping to be backpacking near Big Sur at the time), but the parts I'm most interested in seeing:

  • Concurrency Oriented Programming in Erlang (Joe Armstrong)

  • Safe Asynchronous Exceptions For Python (Stephen N. Freund and Mark P. Mitchell)

  • Disruptive Programming Language Technologies (Todd Proebsting)

  • The Needle Programming Language (Neel Krishnaswami)

  • The Laszlo application description language, LZX (Oliver Steele)

Best fragment of a talk title: "Why Bambi Snuggles with Godzilla"
8:24:47 AM   comment/     


  Thursday 24 October 2002
Lawn Order

A couple of days ago, I wrote:

onto US 50 East. Saw a gardener's pickup truck labeled Lawn Order before I got out of Sacto.

Here's the reason that this truck's logo made me grin: I sent the following message to my favorite humor email list, a year and a half and a lifetime ago:

Date: Mon, 25 Jun 2001 20:54:00 -0700
From: [Doug Landauer]
Subject: Re: Stab from the Past
To: [the bozos list]

> belts ... strong ... Fan ... Earth > narrowly missed having a Fan Belt.

Spider Robinson reported seeing a diagram for a commode to be used in zero gravity, on the space shuttle. He said, as far as he could tell from the diagram, the sh*t is *supposed* to hit the fan.


New TV show for the summer season: Steven Hill (Mr. Mower), Michael Moriarty (Eddie the Edger), Paul Sorvino (Bernie "Fertilizer" Bandini), and Jill Hennessy (Ms Miracle-Gro) star in this highly-rated drama about a (weird) family's obsession with keeping their yard neat ... it's called Lawn Order.

:-D


9:06:53 PM   comment/     

  Tuesday 22 October 2002
Tahoe Weekend

Saturday Morning: Left home at 7:00am, got a ticket on Hwy 17, skipped the Nimitz because I was in San Jose, took the Sig Sigmund (named for the same guy Sig-Alerts were named for) over the Sunol Grade to CA-84, through Livermore, found a Donut Wheel for breakfast, took the Arthur H Breed, Jr, past the wind farms over Altamont Pass, over the Edmund G. "Pat" Brown Aqueduct (and then the Delta Mendota Canal), Bright orange Aspen near Luther Pass to the Robert T Monagan Freeway, through California's Sunrise Seaport, passing by the Ort Lofthus Freeway, onto the Carleton E. Forbes, (saw a few egrets and one pair of great blue herons) through River City, and onto US 50 East. Saw a gardener's pickup truck labeled Lawn Order before I got out of Sacto.

Near Folsom, there are some metal cutout-style "statue"s on a hillside -- a few rabbits, chasing a wolf.

Ran into ten minutes of totally stop-and-go traffic (just like the weekend Highway 17 San Jose to Santa Cruz Beach traffic) due to the stoplights in Old Hangtown.

Just for scenic variety, I took off of US-50 onto the Mormon Emigrant Trail. Of the several trails and passes over the Sierra that are called "[Something] Emigrant Trail", this is the only one that I know of that led EAST. The Mormon battalions were released from military service and were headed back to Utah.

Pastoral Hope Valley Autumn scene It was they who named Hope Valley (just east of Carson Pass) and the nearby Faith Valley and Charity Valley. Near the Blue Lakes, it's all the upper basin of the West Fork of the Carson River. Beautiful country.

I stopped at Carson Pass (just over 8500' elevation) and took a short hike, one mile south on the PCT (just past Frog Lake), then turning off to head for Winnemucca Lake. Very nice.

But the big surprise for me was the outstanding yellow and orange colors of the Aspen trees in Hope Valley. Any SF Bay Area or Sacramento folks ought to consider going up there this week. I took more photos than these few.

Visited my folks, and did the short hike from Bayview Trailhead (above the southwest corner of Emerald Bay), over to Cascade Falls. Climbed a 500 or 700 foot high knob of granite south of Cascade Creek, and got a fantastic view of Cascade Lake with a strip of forest, and Tahoe and the east-side mountains beyond. Sorry, forgot my camera.

On the way home, one field south of Sac'to had about 10 egrets in it.
1:14:41 AM   comment/     

Radio Servers Outage

I posted-but-didn't-publish an entry a couple of hours ago, but Radio's servers were down. When I re-started Radio, that posting had vanished. Oh well.
1:04:07 AM   comment/     


  Friday 18 October 2002
Silly icons

One of the silly icons here (named "Winky", I gather) has a bit of a resemblance to my forty-year-old personal icon, "Peter Potatoe".. I suppose that means I ought to sue now.

[via Boing Boing ]
1:49:35 AM   comment/     


  Thursday 17 October 2002
Dougday Hooray

Not that I'm ever in the news, but I had to link to this site once Evan pointed it out.
12:50:39 AM   comment/     


  Wednesday 16 October 2002
Politics & Global Corporatization

<Caveat:> I've always steered away from politics — being a math major in college and a programmer for 32 years makes me far prefer questions that actually have answers. Any political posts that I make here tend to take a slightly naive, very idealistic, and moderately long-term view of the situations. </Caveat:>

Given my general distaste for political discussions, it's been odd for me to run across three different but somewhat interconnected items about Global Corporatization, the unipolar world, and a bit of US foreign policy history — the odd bit being that I found all three very interesting. It's refreshing to read some writing that makes ya think.

  • Arundhati Roy talk in Santa Fe, and conversation with Howard Zinn.
    I do not agree completely with what she says and how she says it — e.g, one-sided Israeli history that omits the Arab attacks that led directly to the 1967 expansion.
  • Fareed Zakaria Article from New Yorker Magazine that mentions the word Realpolitik three times.
  • "The Alarm!", a local Santa Cruz area free political paper. Might be described as somewhat leftist. Oooh, their website seems to be completely empty. HAVE THEY BEEN SILENCED? (Fodder for conspiracy buffs.)

My main point in the rest of this article:

Corporations are not democracies, and in fact the recent vast increases in corporate power undermine democratic rule, in part because of their effect of concentrating wealth.

My second point:

The "anti-globalization movement" should really do their damnedest to get that name changed. That's just exceptionally poor marketing.

I have always found absurdity in the silly protests against globalization. Globalization (in, yeah, yeah, yeah, Lennon's "imagine no country" terms) is IMHO utterly inevitable given a global communications system. It is a global economy. There remain artificial national boundaries, but given enough communication among peoples in different parts of the world, those people will eventually obliterate those boundaries.

I am refreshed to see Roy being careful to distinguish the problem as Corporate globalization. IMHO, that's not even actually an accurate way to put it. The problem is Global Corporatization.


"We" (the US public, as directed, cajoled, and exhorted by the corporate media) oversimplify our political views into ONE BIT. (LEFT or RIGHT. Liberal or Conservative.) See the "World's Smallest Political Quiz for a slightly less oversimplified view. (There's an omitted tangent here, on Libertarianism GONE TOO FAR).

"We" also oversimplify our views of governmental systems versus economic systems. E.g., Communism, in its "ideal" form (i.e., if there were a population that would "play nice"), is attractive as an economic system (though not workable in the real world), but it is not a system of government and the attempts to make it so have almost all failed economically.

Similarly, the public in the US are currently confused between democracy (a form of government) and Corporatization (an emphatically non-democratic form of economic system). We are told by the (corporate) media that the two must go hand-in-hand, and that the corporate form of the Free Market is the only form that can exist in a democracy. Bullshit.
10:09:01 AM   comment/     


  Tuesday 15 October 2002
Unintended Agenda

Dan Gilmor writes about the efforts of the entertainment cartel at the "Agenda 2003" conference ...

The entertainment cartel is winning where it counts in the short term: Congress, which the cartel all but owns.

He does not go on to say anything about the medium term or the longer term.

My opinion is that in these cases, the "short term" lasts at most a month before whatever crippled media distribution formats they choose are broken or copied out to the entire world. To the extent that they can buy votes in Congress for crippled semi-computers, and/or to make such copying illegal, those votes will just buy more civil disobedience, and even less respect for the rules of federal law. This is one of those unintended consequences of laws not thought through.
11:21:09 AM   comment/     


  Monday 14 October 2002
Lego Mobius Strips

It's pretty hard to believe what people have been making with Legos lately. In the last month or so, I've seen pointers to

I wish I had that kind of free time. That's not what I would do with the time, but I wish I had that much.
12:12:17 AM   comment/     


  Sunday 13 October 2002
It's all connected

Joey d.V. writes about burningbird's Programming Languages parable, about a Paul "Peekabooty" B. becoming a Python convert, and about part of the Vancouver geek scene. (Brief mention of Brad Templeton, whom I met probably around ten years ago.)

At work lately, I've been converting my Python program to C. Somewhat painful, but the conversion is close to complete. I'm sure glad I had the Python prototype to work out the details, get the hardware & doc folks to finish the documentation, and get the real story about how the hardware works. Would have been a major pain to have had to work that stuff out in C.
11:54:09 PM   comment/     


  Saturday 12 October 2002
Jimmy Carter wins the Nobel Peace Prize

Jimmy Carter certainly deserves this honor. For my money, he has been the greatest ex-President this country has ever had.

It's a pity that the awards committee so sullied the grand tradition of this prize in 1973 by awarding it to Henry Kissinger. As Tom Lehrer put it, this made political satire obsolete.
10:32:42 AM   comment/     


  Friday 11 October 2002
Programming Language Humor

Michael Vanier wrote an excellent update of the Programming Languages as Cars metaphors. I added a comment to the Lambda discussion about it.

And burningbird wrote a wonderful parable about Programming Languages that everyone has linked to by now.
12:45:39 AM   comment/     

Python 2.3 Plan Summary

Plans are starting to solidify, for the next version of Python, Python 2.3, scheduled to be released some time in late 2002 or early 2003.

The PEP (Python Enhancement Proposal) about the 2.3 plan is here: http://www.python.org/peps/pep-0283.html

(Jeffrey "Industrie Toulouse" Shell pointed out this PEP, at http://radio.weblogs.com/0106123/2002/10/08.html#a215 )

To turn this entry into my own mini-pointer about the PEPs, I'll add that http://www.python.org/peps/ is the URL for PEP 0, which is an index of all of the PEPs, and that http://www.python.org/doc/essays/pepparade.html is where Guido, the BDFL, comments about the ones that he has read. Seems like they somehow could have worked Sergeant PEPper into this, somewhere.

BTW, good turnout for this past Wednesday's BayPIGgies meeting. Wesley summarized some of the Python-related talks from the O'Reilly OSCon.
12:39:55 AM   comment/     

Nuking lit carbon yields plasmoids

Happened upon the page of microwave experiment suggestions a couple of days ago. I had to add this comment:

Nuke a LIT cigarette

I — er, um, an acquaintance — tried this in college many many years ago (around 1970). You get a free-floating plasmoid. It was the late 1990's before I finally found this explanation of the phonomenon (see http://jnaudin.free.fr/html/oa_plasmoid.htm for safer ways to do this experiment) but the details were unmistakable. The buzzing, the ball-lightning-like effect. Very cool. I — um, my acquantance — just used a plastic spoon, burned a hole in it (with the cigarette, of course) and then jammed the filter in so that the spoon helped the cigarette stand up vertically. You may want to be sure to use a microwave that doesn't spin the "food" around.

Hmm, I don't have a "science" category so I'll just have to call it "humor" :-)
12:26:24 AM   comment/     


  Thursday 10 October 2002
Layoff anniversary

One year ago today, I was laid off.

My life is better now.

Some of what I did during this past year is listed here. I hope it has helped some of the other people who have been laid off over the past couple of years.
11:33:19 PM   comment/     

Blognations

Several bloggers have been mentioning "Blogistan" for quite some time; and I recently came across a mention of the "University of Blogaria". So I went through Josh's fun list of the world's flags, given letter grades, and modified all of the names that seemed even remotely appropriate.

So, live from Blog Lomond, it's:

  • blogistan
  • bloghanistan
  • bloguilla
  • blogentina
  • azerblogjam
  • blogladesh
  • blogarus
  • bologia
  • blognia and herzeblogvina
  • blogswana
  • blogzil (didn't Brazil change its name to Brazilla lately, to protest the Toho vs Davezilla flap?)
  • blogaria
  • blogkina faso
  • camblogia
  • blogaroon
  • cubloga
  • djiblogi
  • blogland (Back when loglan was "popular", we ^H^H^H its fans used to refer to "logland". But when the community moved on to lojban, all they could come up with was "lojbania".)
  • blogemala
  • guinea-blogau
  • bloggary
  • liblogia
  • luxemblourg
  • morblocco
  • mozamblique
  • the bloggerlands
  • blogway
  • blogama
  • blogapore
  • blogakia
  • blogenia
  • tobloggo
  • trinidad and toblago
  • blogalu
  • bluganda
  • united blogdom
  • blugoslavia
  • zambloga
  • zimblogwe

I like Blogaria best.
11:09:34 PM   comment/     


  Wednesday 9 October 2002

  Tuesday 8 October 2002
City Nicknames, Take VI

Another update. I'm starting to get spontaneous emails about the list, suggesting cities and names to be added. I tend to check these with Google most of the time, especially if I think they're not unique enough.
11:58:02 PM   comment/     


  Monday 7 October 2002
Wetlands Restoration

On the way to Kings Canyon last week, I saw an area (just east of Los Banos, I think) where it looked like some kind of wetlands restoration was going on. Reeds, wet ground, a few spots of open water. I thought "How cool." Then, at the far (east) end of it, I noticed a shack with some camo equipment. Ah, a hunting club. Let's restore some wetlands so we can attract some waterfowl — so we can kill them.

Odd. Still, I suspect that it might be better for some of the rarer species than one of the most likely alternatives: paving the entire Central Valley.
10:31:29 AM   comment/     


  Sunday 6 October 2002
Beamish

In our two or three backpacking trips last year and the year before, Turly mentioned Beamish Stout more than a few times. It's brewed in his home town, Cork. I hadn't had the chance to try it.

But ... they had a keg of it at Highlands Park yesterday, where the Highlands Games were held. It's a creamy stout, not too bitter. Good enough that I had three of them over the course of the afternoon. Jim, Marina, and I walked home from the park, while Deb drove Mary & Marty home.
4:21:21 PM   comment/     


  Saturday 5 October 2002
Highland Games

Fun times at the Highland Games in Ben Lomond today. Forgot to bring my camera. We saw enough kilted folks talking on mobile phones that we decided that the Kell Phone must have been an ancient Celtic invention.
11:42:15 PM   comment/     


  Friday 4 October 2002
The Bear

Bear just north of CA-180 This bear said "Welcome to Kings Canyon. Now go home."

But I had to go to Reno, first.

Now I have to make up for missing a couple of days of work.

1:08:51 AM   comment/     


  Thursday 3 October 2002
Kings Canyon Sampler

I put a subset of the photos from this past weekend onto my mac.com account. It's still copying, and I still have to go back and edit the HTML to give better captions, but they are currently winging their way to http://homepage.mac.com/landauer/bi_KC/ . I have higher res versions of all of them, but haven't uploaded any of those yet. I'll put some of them onto the .Mac site, later. Likewise, the shots from Reno.
11:43:26 PM   comment/     


  Wednesday 2 October 2002
El Parque Nacional del Rio de los Reyes Santos

Busy weekend. Thursday after work, headed east for the (17th) annual camping trip to Kings Canyon National Park. (My fifth or sixth year there.) Saw some long-time friends and met some new friends. Hiked up to Mist Falls on Saturday. Returning to my car, I found a note to "Mr Lanchmar" about my mother having had to go to the hospital in Reno for heart surgery. So Sunday afternoon I drove through Yosemite, and up 395 to the Biggest Little City in the World. Despite the reason for it, it was good to see my parents, all three of my brothers, and (unexpectedly) a cousin who happened to be at a conference in that town that weekend. My mother is doing well (considering), and is on the road to recovery.

Tidbits seen along the way:

  • Fresno is being held hostage by an utterly incompetent construction company. The freeway east from CA-99 is CA-180, and the sign said "180 East Exit Closed. Use alternate route". Period. No alternate route was suggested, nor marked.
  • The Kings River is named for the Magi, the "We Three" kings, because it was discovered on Epiphany. Surprising to me how late — 1806 or so.
  • On the drive to Reno, I avoided Fresno because of the idiots who have its road system disassembled this month. Little roads cut across toward Millerton Lake, and it looked like some new money had flowed into the area. I figured that it was just expansion from L.A., but then I drove by an Indian casino. Aha, Mafia money.
  • Got to see Yosemite Valley in the twilight.
  • Stopped north of Walker, CA, on 395, to dig some dinner out of my ice chest. Except for the occasional truck passing by, it was quiet and DARK. No moon, bright bright milky way across the sky.
  • I actually found a pretty part of Reno. Southwest part of town, a nice little park on a hill ("Windy Hill") with some cool trails, a flume ("Last Chance Ditch"), and a corn maize maze.
  • Headed home on I-80, amidst threat of snow in South Lake Tahoe, and over Tioga Pass, where I had been just a day or two earlier.

I've seen a lot of misspellings of my name over the past 3 or 4 decades, but never "Lanchmar". I may choose to adopt the name — there are no Google matches at all for it, tonight.
11:28:30 PM   comment/     



Click here to visit the Radio UserLand website. Click to see the XML version of this web page. © Copyright 2007 Doug Landauer .
Last update: 07/2/6; 12:21:03 .
Click here to send an email to the editor of this weblog.