Created
March 11, 2017 23:42
-
-
Save bdrupieski/585f91fc6f98408424ca47385f3f585a to your computer and use it in GitHub Desktop.
Generate NATO alphabet Anki cards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using MoreLinq; | |
namespace App | |
{ | |
public static class GenerateNatoAlphabetAnkiCards | |
{ | |
private static readonly List<NatoAlphabetLetter> Letters = new List<NatoAlphabetLetter> | |
{ | |
new NatoAlphabetLetter {Letter = "A", Word = "Alpha"}, | |
new NatoAlphabetLetter {Letter = "B", Word = "Bravo"}, | |
new NatoAlphabetLetter {Letter = "C", Word = "Charlie"}, | |
new NatoAlphabetLetter {Letter = "D", Word = "Delta"}, | |
new NatoAlphabetLetter {Letter = "E", Word = "Echo"}, | |
new NatoAlphabetLetter {Letter = "F", Word = "Foxtrot"}, | |
new NatoAlphabetLetter {Letter = "G", Word = "Golf"}, | |
new NatoAlphabetLetter {Letter = "H", Word = "Hotel"}, | |
new NatoAlphabetLetter {Letter = "I", Word = "India"}, | |
new NatoAlphabetLetter {Letter = "J", Word = "Juliet"}, | |
new NatoAlphabetLetter {Letter = "K", Word = "Kilo"}, | |
new NatoAlphabetLetter {Letter = "L", Word = "Lima"}, | |
new NatoAlphabetLetter {Letter = "M", Word = "Mike"}, | |
new NatoAlphabetLetter {Letter = "N", Word = "November"}, | |
new NatoAlphabetLetter {Letter = "O", Word = "Oscar"}, | |
new NatoAlphabetLetter {Letter = "P", Word = "Papa"}, | |
new NatoAlphabetLetter {Letter = "Q", Word = "Quebec"}, | |
new NatoAlphabetLetter {Letter = "R", Word = "Romeo"}, | |
new NatoAlphabetLetter {Letter = "S", Word = "Sierra"}, | |
new NatoAlphabetLetter {Letter = "T", Word = "Tango"}, | |
new NatoAlphabetLetter {Letter = "U", Word = "Uniform"}, | |
new NatoAlphabetLetter {Letter = "V", Word = "Victor"}, | |
new NatoAlphabetLetter {Letter = "W", Word = "Whiskey"}, | |
new NatoAlphabetLetter {Letter = "X", Word = "X-Ray"}, | |
new NatoAlphabetLetter {Letter = "Y", Word = "Yankee"}, | |
new NatoAlphabetLetter {Letter = "Z", Word = "Zulu"}, | |
}; | |
public static void DoIt() | |
{ | |
for (int i = 3; i <= 5; i++) | |
{ | |
var lines = LettersWithWordsOnOtherSideOfCard(i, 3); | |
File.WriteAllLines($"NATO_Pairs_{i}.txt", lines); | |
Console.WriteLine(string.Join(Environment.NewLine, lines)); | |
} | |
var arguments = new[] | |
{ | |
new {NumberOfLetters = 3, NumberOfBlanks = 4, Repeat = 6}, | |
new {NumberOfLetters = 2, NumberOfBlanks = 4, Repeat = 5}, | |
new {NumberOfLetters = 1, NumberOfBlanks = 4, Repeat = 4}, | |
}; | |
foreach (var arg in arguments) | |
{ | |
var lines = LettersWithBlanksAfterThemAndAllLettersOnOtherSideOfCard(arg.NumberOfLetters, arg.NumberOfBlanks, arg.Repeat); | |
File.WriteAllLines($"NATO_Pairs_Blanks_{arg.NumberOfLetters}_{arg.NumberOfBlanks}.txt", lines); | |
Console.WriteLine(string.Join(Environment.NewLine, lines)); | |
} | |
} | |
private static List<string> LettersWithWordsOnOtherSideOfCard(int batchSize, int repeat) | |
{ | |
var batches = Letters.Repeat(repeat).Batch(batchSize); | |
var lines = new List<string>(); | |
foreach (var batch in batches.Where(x => x.Count() == batchSize)) | |
{ | |
var b = batch as IList<NatoAlphabetLetter> ?? batch.ToList(); | |
lines.Add($"{string.Join(" ", b.Select(x => x.Letter))} ~ {string.Join(" ", b.Select(x => x.Word))}"); | |
} | |
return lines; | |
} | |
private static List<string> LettersWithBlanksAfterThemAndAllLettersOnOtherSideOfCard(int numberOfShownLetters, int numberOfBlanks, int repeat) | |
{ | |
int totalNumberOfLetters = numberOfShownLetters + numberOfBlanks; | |
var batches = Letters.Repeat(repeat).Batch(totalNumberOfLetters); | |
var lines = new List<string>(); | |
foreach (var batch in batches.Where(x => x.Count() == totalNumberOfLetters)) | |
{ | |
var b = batch as IList<NatoAlphabetLetter> ?? batch.ToList(); | |
var lettersWithBlanks = b.Select(x => x.Letter) | |
.Take(numberOfShownLetters) | |
.Concat(Enumerable.Repeat("_", numberOfBlanks)); | |
var allLetters = b.Select(x => x.Letter) | |
.Take(numberOfShownLetters) | |
.Concat(b.Skip(numberOfShownLetters).Select(x => $"<u>{x.Letter}</u>")); | |
lines.Add($"{string.Join(" ", lettersWithBlanks)} ~ {string.Join(" ", allLetters)}"); | |
} | |
return lines; | |
} | |
} | |
public class NatoAlphabetLetter | |
{ | |
public string Letter { get; set; } | |
public string Word { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment