The wording on question 9 (the regex one) is a little unclear: both b[l].e and ([^b]b[^b]*){3} will match blabber but not babel. Presumably the intended meaning is that the entire string must be matched, but the question does not make this explicit.
private static Chunk GenerateChunk(short chunkX, short chunkZ, int seed, byte[] permutation)
{
var chunk = new Chunk(chunkX, chunkZ);
int worldMapSize = 256;
short maxHeight = (short)Math.Min(worldMapSize >> 2, Chunk.CHUNK_HEIGHT);
float[] worley = new float[2];
HermiteSpline continentCurve = new HermiteSpline(new[]
{
new HermitePoint(0f, 0f, 0f), new HermitePoint(0.07f, 0.03f, 1f), new HermitePoint(0.12f, 0.1f, 0.7f),
new HermitePoint(0.21f, 0.18f, 1f), new HermitePoint(0.24f, 0.2455f, 0f), new HermitePoint(0.26f, 0.26f, 1f), new HermitePoint(1f, 1f, 1f)
});
HermiteSpline continentMask = new HermiteSpline(new[]
{
new HermitePoint(0f, 0f, 0f), new HermitePoint(0.25f, 0f, 0f), new HermitePoint(0.4f, 1f, 0f), new HermitePoint(1f, 1f, 0f)
});
HermiteSpline plateMountainCurve = new HermiteSpline(new[]
{
new HermitePoint(0f, 0f, 0f), new HermitePoint(1f, 1f, 3.5f)
});
for (short x = 0; x < Chunk.CHUNK_SIZE; x++)
{
for (short z = 0; z < Chunk.CHUNK_SIZE; z++)
{
int globalX = (chunkX << Chunk.CHUNK_SIZE_LOG2) + x;
int globalZ = (chunkZ << Chunk.CHUNK_SIZE_LOG2) + z;
//Subdive the world into squares, each of which contains an independent world map
//The edges of each square are lowered so that each map is separated by oceans
float xSeparator = (float)Math.Sin((globalX & (worldMapSize - 1)) * MathHelper.Pi / worldMapSize);
float zSeparator = (float)Math.Sin((globalZ & (worldMapSize - 1)) * MathHelper.Pi / worldMapSize);
float rectSeparator = (float)Math.Min(1, 3 * Math.Min(xSeparator, zSeparator));
float circleSeparator = xSeparator * zSeparator;
float mapSeparator = rectSeparator * 0.375f + circleSeparator * 0.575f + 0.05f;
//Use turbulence noise to get the typical clumped shape of continents and add some simplex and ridged noise for the thinner shapes
float continentNoise1 = Noise.Turbulence(globalX, globalZ, 8, worldMapSize, permutation);
float continentNoise2 = Noise.Simplex(globalX, globalZ, 8, worldMapSize * 0.16f, permutation) * 0.5f + 0.5f;
float continentNoise3 = Noise.Ridged(globalX, globalZ, 8, worldMapSize * 0.5f, permutation);
continentNoise2 *= continentNoise2;
continentNoise3 *= continentNoise3;
float continentHeight = continentNoise1 * 0.5f + continentNoise2 * 0.25f + continentNoise3 * 0.125f;
float baseHeight = continentCurve.Map(continentHeight * mapSeparator);
//Add mountains caused by convergent continental plate boundaries
float continentMult = continentMask.Map(baseHeight);
float plateMountainNoise1 = Noise.Ridged(globalX, globalZ, 8, worldMapSize * 0.4f, permutation);
float plateMountainNoise2 = Noise.Simplex(globalX, globalZ, 8, worldMapSize * 0.2f, permutation) * 0.5f + 0.5f;
float plateMountainNoise = plateMountainNoise1 * 0.66f + plateMountainNoise2 * 0.33f;
float plateMountainHeight = plateMountainCurve.Map(plateMountainNoise) * continentMult;
//Apply the map separation
float finalHeight = baseHeight + plateMountainHeight;
//Convert the height from range [0,1] to range [1,255]
byte height = (byte)(finalHeight * (maxHeight - 1) + 1);
for (short y = 0; y < height; y++)
{
chunk[(short)x, y, z] = (byte)((y + 1) * 255 / (maxHeight + 1));
chunk.SetStack((short)x, z, new short[] { height, (short)(Chunk.CHUNK_HEIGHT - height) });
}
}
}
return chunk;
} pairs = (>>= \ ~(x:xs) -> map ((,) x) xs) . init . tails
EDIT: Or as a list comprehension: pairs xs = concat [map ((,) h) t | (h:t) <- tails xs] foldl (+) 0 [1..10]
would output 55, scanl (+) 0 [1..10]
would output [0,1,3,6,10,15,21,28,36,45,55]. fix f = f (fix f)
In any strict language this would ofcourse just result in an infinite loop, but fortunately Haskell has lazy evaluation. So if we evaluate the list, for example with take 5 fibs
the following happens: fibs = fix $ (1 :) . scanl (+) 1