Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Object Orientation and General technical topics module Q110
Programming Algorithms
Exercises, examples and other material relating to training module Q110. This topic is presented on public course Learning to program in Perl

This section provide you with links to (and comments on) pieces of code to performs certain task - algorithms - that you can study if you need to roll your own, or lift from us if you like.
Related technical and longer articles
File Locking

Articles and tips on this subjectupdated
4707Some gems from an introduction to Python
This week, I ran a private Introduction to Python course - using Python 2.7 at customer request - and here are some of the code snippets I wrote in front of the class - little things I may not have blogged about in the past. Complete examples being emailed to the delegates!  # Using&nbs ...
4656Identifying the first and last records in a sequence
When programming to analyse event or log files, you'll often find it fairly easy to identify the initial or opening record of a linked series, but harder to spot the closing one until your program has gone well past it. Take this data, for example:   16:15:47 +00 INF: ===================Move ...
4652Testing new algorithms in PHP
During algorithm development, code testing, experiments and spike solutions often account for far more code than the final working code - a classic example of that today where I was writing / testing a loop for Lisa. Scenario - our booking database holds flags for each of our five hotel bedrooms for ...
4410A good example of recursion - a real use in Python
Recursion is where a named block of code calls itself. The "classic" demonstration is the code to generate a factorial number:   def factorial(n):     if n ...
4402Finding sum, minimum, maximum and average in Python (and Ruby)
A fresh example (in Python) from today's "learning to program in" course ... finding the number, sum, minimum and maximum of a series of numbers typed in. See [here]. We start off with zero for the count and sum to date, but we do not initialise the minimum or the maximum as we don't know what they ...
4401Selecting RECENT and POPULAR news and trends for your web site users
How do we give people recent news, or talk about recent trends or popular posts>? The obvious answer is to take data for the last "n" days or months and analyse that. But whilst that's the obvious answer, it's also obviously a fairly crude measure as it gives undue influence as it changes to what happened ...
4325Learning to program - what are algorithms and design patterns?
There are common themes for how programming statements are put together to give complete section of code to perform combined tasks. And typically these are putting together building blocks in a similar way to we would do things if we were working something out by hand. Looking for the maximum value ...
3620Finding the total, average, minimum and maximum in a program
There are a number of programming techniques which the experienced coder takes for granted, but which aren't necessarily intuitive for the newcomer. Call them "design techniques" or "design patterns" that need to be learned, if you want some fashionable buzzwords. • To produce the sum of a stream ...
3662Finding all the unique lines in a file, using Python or Perl
A question - how do I process all the unique lines from a file in Python? Asked by a delegate today, solved neatly and easily using a generator which means that there's no need to store all the data - unique values can be passed back and processed onwards as they're found. This is fantastic news if ...
3451Why would you want to use a Perl hash?
"What would I use one of THOSE for?" - a question often asked by newcomers to Perl when I first introduce hashes. Well - in writing a script to count up how many articles I've written about each subject we teach on, I came up with a perfect example. A hash is described as an "unordered collection" ...
3102AND and OR operators - what is the difference between logical and bitwise varieties?
Many modern programming languages have two operators for "or" and two for "and" - described as "bitwise" and "logical" operators. And you need to choose the right one in the right circumstances ... otherwise your code won't behave quite as you expect. Bitwise OR takes the internal bit pattern of the ...
3093How many toilet rolls - hotel inventory and useage
Running Well House Manor, we buy a lot of hotel supplies - ranging from sheets and towels when they are to be replaced, through guest soaps and toilet rolls, salt, sugar and jams which are ordered from time to time, to weekly or twice weekly orders such as fruit and fresh products and ultimately the ...
3072Finding elements common to many lists / arrays
"What do these lists have in common". That's a common question - but what does the person asking it actually mean? Is (s)he looking for items that occur in all of the lists, but perhaps at different positions? For items that occur in two or more of the lists? For items that occur at the same position ...
3042Least Common Ancestor - what is it, and a Least Common Ancestor algorithm implemented in Perl
Imagine you have a tree - a series of leaves which join together as you head towards the root into bigger and bigger branches. The "Least Common Ancestor" is the point at which the branches from two leaves you have chosen come together. In computing, such a tree structure is very common - files and ...
2993Arrays v Lists - what is the difference, why use one or the other
If you want a program to run quickly through a data set (that's the sort of thing you'll be doing in heavy scientific work), you'll want the data loaded into successive memory locations - but that means that you have to know how much space to allocate before you set the data up. Otherwise, you'll find ...
2951Lots of way of converting 3 letter month abbreviations to numbers
There are certain programming tasks that sound simple but end up fascinating ... they sound straightforward (and probably are), but it turns out there are lots of ways of doing them and you could spend a lot of time working out which was is best. One of those is converting three letter abbreviations ...
2894Sorting people by their names
Please sort into order: Tom Pearce Bill Brewer Peter Gurney Peter Davy Daniel Whiddon Harry Hawk Uncle Tom Cobbley What would you do? Bill Brewer Uncle Tom Cobbley Peter Davy Peter Gurney Harry Hawk Tom Pearce Daniel Whiddon That's not a standard sort order for strings of text ... and if you've got ...
2617Comparing floating point numbers - a word of caution and a solution
"Think of a number between 5 and 15. Double it. Add fourteen. Halve it. Take away the number you first thought of. Is the result 7?" We all played games like that as children, thinking of the number 0 ourselves so that we could do an easy calculation and impress our friends. And the result was 7 ... ...
2586And and Or illustrated by locks
Lisa and I came across this impressive array of locks on what we have since learned is probably the back gate to the National Grid's Lacock Switching Station, about 3 miles North of Melksham. [picture/details] Our first reaction was "wow - that must be REALLY secure - what are they doing in there?" ...
2509A life lesson from the accuracy of numbers in Excel and Lua
Floating point numbers aren't held EXACTLY in a computer's memory - they're held to a certain accuracy (number of significant figures or binary digits to be more accurante) after which they are truncated or rounded. And this means that at time 1.0 / 3.0 * 3.0 doesn't go full circle and come back to ...
2259Grouping rows for a summary report - MySQL and PHP
It's quite quick and easy to write a loop that goes through a mysql result set and displays the content on an HTML page (but remember security of data, size of resulting HTML page, and the need to consider special characters such as <). But what if you want a shorter report, grouping records together ...
2189Matching disparate referencing systems (MediaWiki, PHP, also Tcl)
Yes, we are Well House CONSULTANTS and do a bit of specialist coding ... I have a requirement on my plate at present to write a piece of code for a customer that recognises cross reference codes within a document and turns them into links. And what makes the task quite difficult is that the references ...
1949Nuclear Physics comes to our web site
One of the major projects that we'll be undertaking in the near future is aimed at improving the findability of information on our site - you shouldn't need to know that you need a blog article dated 2nd Feb 2007 to find about the difference between a comparator and comparable in Java, nor to look up ...
1840Validating Credit Card Numbers
It's standard practise for on line bookings these days to take credit or debit card details as a booking security, and we're no exception at Well House Manor - our hotel for business visitors to Melksham, Wiltshire. There are very many security issues involved, and I am not going to describe what we ...
1391Ordnance Survey Grid Reference to Latitude / Longitude
I've already written about conversion of postal addresses to latitude and longitude using Google's interface - but what is I want to convert the Ordinance Survey's grid references into latitude and longitude? Google's interface doesn't support the OS units - and in any case it's "just" a a calculation. ...
227Bellringing and Programming and Objects and Perl
For the second time this year (and it's only the second month), I find that I have a keen bell-ringer on my programming course ... he's off each evening to meet up with fellow bell-ringers in church towers in Wiltshire, and having a really good time outside course hours as well as during the day. I understand ...
1157Speed Networking - a great evening and how we arranged it
What an excellent evening! Our Speed Networking evening, organised on behalf of the Federation of Small Businesses, drew in around a dozen inividual and a coupe of pairs with a disparate range of products to sell, and a wide variety of requirements to meet - some by using other's products and services. Seated ...
1187Updating a page strictly every minute (PHP, Perl)
For the Clock exercise that I mentioned in my last entry, I need to update the page once a minute. Exactly once a minute. At the start of the minute. I'm using client pull, where the browser asks for the next page - so my basic request is: <meta http-equiv="refresh" content="60; url=/clock/now.php"> but ...
202Searching for numbers
If I'm searching for a 50kg bag of cement, and the online store only offers 48kg bags, will their search engine find this product and say "is this what you want"? Our own site searches do clever things with alphabetic searches but we're rarely had to do a "near number" hunt on our own behalf ... but ...
Examples from our training material
algorithms   Some common algorithms applied to a file of data
amm   Program to read in numbers and return some analysis (Python)
d2.8   finding extreme values from a collection
d2.9   summing a collection
fodder_stats   Minimum, maximum, total, average, count (Ruby)
lca   Least Common Ancestor
lif.py   Counting the number of times something occurs
scat   Getting multiple results from a single data traversal
uni2.pl   Handling unique lines from a file - Perl (generator)
universe.pl   Handling unique lines from a file - Perl (list)
universe.py   Handling unique lines from a file - Python
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from [here].
Topics covered in this module
Mean time between failure.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/Q110.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb