Posts

Showing posts from 2012

Java Lazy Evaluation

Lazy evaluation. This is where a piece of code is written which evaluates a value (usually requiring a relatively large amount of processing), but the code isn't executed until the moment it is needed (if ever). For example, class A calls a method in class B. It passes some values (which take a long time to compute). If the values are passed lazily then class B can decide when and if to compute them. It is up to class A to implement the code for how to evaluate the value. So maybe there are 3 lazy values passed and class B decides it doesn't need to use value 1 but it does use values 2 and 3 (perhaps invoking each evaluation in separate threads, to maximise performance). The code to evaluate value 1 is never called, the code to evaluate values 2 and 3 will be called once and only once. Subsequent retrievals of a lazily evaluated value will return a cached copy of the value (unless the lazy evaluator is reset... see the code below). Here is the class: public abstract cla...

Half-sort

Half-sort is a sorting algorithm. A copy of it can be found here: https://www.box.com/s/p0pn15736599bv8rb8rx It has the following features: It is an in-place sort. (No extra data space needed.) It works by "divide and conquer" recursion. (It is quite like Quick-sort and Merge-sort.) It is not stable. (i.e. It does NOT keep the original order of identically valued items in the list.) Here is some pseudo-code that explains how the Half-sort algorithm works: Calculate M to be a value that is half way between the smallest item and the biggest item in the collection. You may have to scan the entire collection to find this value, but it may already be known or can be easily calculated. L begins by pointing to the start of the collection and moves forwards until an item bigger than M has been found. R begins by pointing to the end of the collection and moves backwards until an item smaller than M is found. Swap the items at L and R. Carry on doing ...

Landscape Chess

Image
I had a weekend of chess. Saturday, a couple of friends came over and we played some games. Next day my sister's family came, my nephew wanted to play chess too. So we had a few games. Then our young daughter wanted to play and we had a good mess around, laughing our heads off as we came up with crazy ideas for new rules and ways that the pieces can move. Then out of the chaos some order arose and we found a fun new way to play chess. Originally it had another name, but after doing some research we found another chess variant had that name. So to make this variant unique we decided on naming it Landscape Chess. At first we were somewhat disheartened to find somebody had already created a chess variant using a diagonal board, although we initially guessed someone probably would have. However, the other variants all seemed to muddy the beauty of chess. We think this variant complements chess, and even more so it actually brings something new to explore. How to play Landscape Ch...

Random name generator

This is a random name generator written in Javascript. It includes a swear filter. I wrote the source code myself and have made it public domain. That is, anyone can use the code for any reason and edit it however they like. Generated name:   You can download the source code here: Random Name Generator.7z This code is completely free to use by anybody. It is held under the Do What You Want To Public License: http://tinyurl.com/DWYWTPL

Do Whatever You Want To Public License

DWYWTPL - DO WHATEVER YOU WANT TO PUBLIC LICENSE When free means  completely  free! The  Do Whatever You Want To Public License  (DWYWTPL) is a free software license. When analysing whether a license is free or not, you usually check that it allows free usage, modification and redistribution. Then you check that the additional restrictions do not impair fundamental freedoms. The DWYWTPL renders this task trivial: it allows everything and has no additional restrictions. How could life be easier? You just DO WHATEVER YOU WANT TO. The license text DO WHATEVER YOU WANT TO PUBLIC LICENSE Version 1, July 2012 Copyright (C) 2012 Chris Nash <cndefend-license@yahoo.co.uk> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHATEVER YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AN...