A challenge for coding monkeys

Non-fashion, non-skirt, non-gender discussions. If your post is related to fashion, skirts or gender, please choose one of the forums above for it.
Post Reply
FranTastic444
Member Extraordinaire
Posts: 569
Joined: Fri Jun 08, 2018 1:47 am
Location: Boston, MA

A challenge for coding monkeys

Post by FranTastic444 »

I was an active member of a car forum when I lived in the UK. From time to time we would get oddball requests for help from club members - here is one particular example. This post comes about as a result me going off-topic on other threads about my work in and love for the MUMPS programming language. It would be interesting to see how the coders amongst us would go about addressing this requirement.

"I want to create 80,000 "flyers" (a small handbill advertising an event or product.) Each piece of paper needs to contain a unique, random, fully populated (i.e. we cannot cheat and just use numerics from 1 to 80k with zero padding on the front) 14-digit code consisting of uppercase letters from the standard Roman alphabet (A-Z) and numbers (0-9) that the recipient of the flyer can type into a web page to see if they have won a prize. Various letters and numbers need to be excluded so as to prevent a mix up between the number zero and letter 'O' for example and to reduce the chance of spelling rude / socially unacceptable words (so, cutting out the letter 'U' takes care of many of these possibilities). Checking a dictionary of known "rude words" is out of scope.

The printers need a text file from me with one code per row."

I'll post my MUMPS solution at a later date. In the original post we had people offering solutions in Excel, and using PERL, PowerShell and UNIX command line. No prizes, but bragging rights aplenty for shortest speed of execution (when generating codes) and brevity of sourcecode
User avatar
crfriend
Master Barista
Posts: 14431
Joined: Fri Nov 19, 2004 9:52 pm
Location: New England (U.S.)
Contact:

Re: A challenge for coding monkeys

Post by crfriend »

What's the time-frame involved -- in other words, what sorts of technology do we have to work with? 1960s'? 1970s'? Today's?
Retrocomputing -- It's not just a job, it's an adventure!
FranTastic444
Member Extraordinaire
Posts: 569
Joined: Fri Jun 08, 2018 1:47 am
Location: Boston, MA

Re: A challenge for coding monkeys

Post by FranTastic444 »

No holds barred - any hardware, any OS, any programming language. Just as long as it can generate the unique codes to screen, to an ASCII file or to a database (that can later be used to generate a file).
FranTastic444
Member Extraordinaire
Posts: 569
Joined: Fri Jun 08, 2018 1:47 am
Location: Boston, MA

Re: A challenge for coding monkeys

Post by FranTastic444 »

My solution would work on a mid/late 1960's PDP-7 through to a modern-day laptop. I believe that all of the commands I've used are ANSI standard, so should work on any flavour of MUMPS.
FranTastic444
Member Extraordinaire
Posts: 569
Joined: Fri Jun 08, 2018 1:47 am
Location: Boston, MA

Re: A challenge for coding monkeys

Post by FranTastic444 »

Well, it looks like the current and former coders amongst us are too busy skirtin' and freestylin' to rise to my challenge. Here is the code that I wrote in MUMPS.

A SET ALLOWED="ACDEFGHJKMNPQRSTWXYZ23456789",ALEN=$LENGTH(ALLOWED),VOUCHMAX=80000,VOUCHLEN=14
FOR NUMCOUNT=1:1:VOUCHMAX DO
.SET OUTPUT="" FOR DIGCOUNT=1:1:VOUCHLEN DO
..SET POS=$RANDOM(ALEN)+1 ; ; get a random position number along the allowed string random goes from 0 to (X-1) so add 1
..SET CHAR=$EXTRACT(ALLOWED,POS)
..SET OUTPUT=OUTPUT_CHAR
.IF $DATA(^RESULT(OUTPUT)) WRITE "MATCH ",OUTPUT,! SET NUMCOUNT=NUMCOUNT-1 QUIT ; If we already have this code, go back and try again
.SET ^RESULT(OUTPUT)="" ; Write the value to a global

Running this on a small Caché instance sitting on a VM hosted by a bog standard laptop - 80k codes <1 second 160k codes 2 seconds 250k codes 4 seconds This is writing the results to the database rather than to memory or to a device. Nice advantage of the hierarchical database is that the output is automatically sorted into ascending alphanumeric sequence
User avatar
Sinned
Member Extraordinaire
Posts: 5804
Joined: Sun Aug 19, 2012 5:28 pm
Location: York, England

Re: A challenge for coding monkeys

Post by Sinned »

It's been over 15 years since I did any coding and, much as I would have one time relished the challenge and written the thing in shell script, Databasic, BASIC, SQL and one or two other other languages, today I must admit that I have been just too lazy to rise to the challenge. I thought that there would have been others that would have done so. This was the sort of thing that was bread and butter - reading a text file or generating random numbers and then performing some action. Sorry. :(
I believe in offering every assistance short of actual help but then mainly just want to be left to be myself in all my difference and uniqueness.
FranTastic444
Member Extraordinaire
Posts: 569
Joined: Fri Jun 08, 2018 1:47 am
Location: Boston, MA

Re: A challenge for coding monkeys

Post by FranTastic444 »

Sinned wrote:I must admit that I have been just too lazy to rise to the challenge. Sorry. :(
No worries :-)

The other forum where I posted this was, at the time, very active (it has since dwindled to just a trickle of posts / comments per day). A good percentage of the guys on the forum were in IT so it quickly escalated into all out war as to who could produce the fastest executing code whilst using the least number of commands / characters in the code. One guy got his son to do it in Excel, but his son misread the brief and produced 800k codes instead of 80k and wondered why it took nearly 24 hours to run :-) One guy did it in Perl and I think another one did it in Python. Execution times in both cases was minutes rather than seconds. It really was one of those challenges where it played to all of the MUMPS language strengths.
Post Reply