Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact

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

Background
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 ...
2016-10-29
(longer)
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 ...
2016-02-26
 
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 ...
2016-02-21
 
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 ...
2015-02-04
 
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 ...
2015-01-19
 
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 ...
2015-01-19
 
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 ...
2014-11-22
 
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 ...
2012-10-08
 
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 ...
2012-03-24
 
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" ...
2011-09-20
 
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 ...
2010-12-24
 
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 ...
2010-12-20
 
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 ...
2010-11-27
 
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 ...
2010-11-11
 
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 ...
2010-10-10
 
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 ...
2010-09-10
 
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 ...
2010-07-30
 
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 ... ...
2010-02-02
 
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?" ...
2010-01-20
 
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 ...
2009-11-21
 
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 ...
2009-06-29
 
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 ...
2009-05-19
 
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 ...
2008-12-17
 
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 ...
2008-10-14
 
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. ...
2008-08-30
 
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 ...
2008-05-16
 
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 ...
2007-06-23
 
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 ...
2007-05-14
 
642How similar are two words
Do you want to help your web site user find what he's looking for on your web site, even if he mis-spells a name or word in a search? PHP provides you with three facilities - soundex, metaphones and Levenshtein distance calculations - which let you compare two words and see how similar they are when ...
2006-06-05
 
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
Sorting.
Coverage.
Mean time between failure.
Halflife.
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., 2017: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/Q110.html • PAGE BUILT: Mon Feb 8 18:55:24 2016 • BUILD SYSTEM: WomanWithCat