Code cleanup + comments

rx
Inga 🏳‍🌈 8 years ago
parent 957d53fa97
commit ed9967e51c
  1. 2
      WhiteRabbit/PrecomputedPermutationsGenerator.cs
  2. 2
      WhiteRabbit/Program.cs
  3. 4
      WhiteRabbit/StringsProcessor.cs
  4. 13
      WhiteRabbit/VectorsProcessor.cs

@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Linq;
internal class PrecomputedPermutationsGenerator
internal static class PrecomputedPermutationsGenerator
{
private static PermutationsGenerator.Permutation[] Permutations1 { get; } = PermutationsGenerator.HamiltonianPermutations(1).ToArray();

@ -31,7 +31,7 @@
{
if (expectedHashesAsVectors.Contains(result.Item2))
{
Console.WriteLine("Found phrase: " + result.Item1);
Console.WriteLine($"Found phrase: {result.Item1}");
}
}
}

@ -37,7 +37,7 @@
// converting sequences of vectors to the sequences of words...
var anagramsWords = sums
.Select(sum => ImmutableStack.Create(sum.Select(vector => formattedWords[vector]).ToArray()))
.SelectMany(Flatten)
.SelectMany(this.Flatten)
.Select(stack => stack.ToArray());
return anagramsWords.Select(list => string.Join(" ", list));
@ -53,7 +53,7 @@
T[] wordVariants;
var newStack = phrase.Pop(out wordVariants);
return Flatten(newStack).SelectMany(remainder => wordVariants.Select(word => remainder.Push(word)));
return this.Flatten(newStack).SelectMany(remainder => wordVariants.Select(word => remainder.Push(word)));
}
}
}

@ -32,14 +32,13 @@
private long Iterations { get; set; } = 0;
// Produces all sequences of vectors with the target sum
public IEnumerable<Vector<byte>[]> GenerateSequences(IEnumerable<Vector<byte>> vectors)
{
var filteredVectors = FilterVectors(vectors);
var filteredVectors = this.FilterVectors(vectors);
var dictionary = ImmutableStack.Create(filteredVectors.ToArray());
var unorderedSequences = GenerateUnorderedSequences(this.Target, ImmutableStack.Create<Vector<byte>>(), dictionary);
var allSequences = unorderedSequences.SelectMany(GeneratePermutations);
var unorderedSequences = this.GenerateUnorderedSequences(this.Target, ImmutableStack.Create<Vector<byte>>(), dictionary);
var allSequences = unorderedSequences.SelectMany(this.GeneratePermutations);
return allSequences;
}
@ -75,7 +74,7 @@
Vector<byte> currentVector;
var nextDictionaryTail = dictionaryTail.Pop(out currentVector);
DebugState(partialSumStack, currentVector);
this.DebugState(partialSumStack, currentVector);
var newRemainder = remainder - currentVector;
if (newRemainder == Vector<byte>.Zero)
@ -84,7 +83,7 @@
}
else if ((newRemainder & Negative) == Vector<byte>.Zero)
{
foreach (var result in GenerateUnorderedSequences(newRemainder, partialSumStack.Push(currentVector), dictionaryTail))
foreach (var result in this.GenerateUnorderedSequences(newRemainder, partialSumStack.Push(currentVector), dictionaryTail))
{
yield return result;
}
@ -101,7 +100,7 @@
Vector<byte> currentVector;
dictionaryTail = dictionaryTail.Pop(out currentVector);
DebugState(partialSumStack, currentVector);
this.DebugState(partialSumStack, currentVector);
var newRemainder = remainder - currentVector;
if (newRemainder == Vector<byte>.Zero)

Loading…
Cancel
Save