The string “ABC” occurs in “ABBC” twice, if you remove any characters you wish from “ABBC”.
The following algorithm finds such occurences in O(n) time given any two strings.
One assumption worth noting for the O(n) time bound is that the size of the alphabet is limited to some constant size.
Nested loops in this algorithm scream O(n^2)!! [...]
I wrote some python code that extracts the longest non-decreasing subsequence from any given sequence.
This runs in O(n log n) time, and uses O(n) memory.
”’ An item in the final sequence, used to form a linked list. ”’
class SeqItem():
val = 0 # This item’s value.
[...]
Time and again I have seen code like this used in XNA tutorials.
effectDrawBlock.Begin();
foreach (EffectPass pass in effectDrawBlock.CurrentTechnique.Passes)
{
pass.Begin();
gd.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 35, 0, 70);
pass.End();
}
effectDrawBlock.End();
When you use a foreach over an array of ints, you will not create garbage, and it’s fast, so that’s [...]
I profiled my XNA game project today using the XNA Framework Remote Perf Monitor and discovered that I was generating about 8000 more manage objects per second than I was expecting to.
It turns out that this code was generating 7400 managed objects per second:
[...]
I noticed that at least two terrain engine examples in XNA are reading heightmap images into 4 channel textures instead of single channel textures.
To create a custom content processor that will permit you to convert any Texture2D compatible input format into an Alpha8 format texture, do the following:
Right click your game solution -> add new [...]
As promised, here is an implementation of the Cohen-Daubechies-Feauveau 9 tap / 7 tap wavelet transform on a 2D signal in Python. This is the same transform used in the JPEG2000 codec.
This is a first step in a larger task of compressing a certain type of vertex data, which can be decompressed entirely by a GPU via an [...]