Skip to content

Instantly share code, notes, and snippets.

@sklivvz
Created October 20, 2022 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sklivvz/a611ee9bbb9a6093a73035493aaa81b0 to your computer and use it in GitHub Desktop.
Save sklivvz/a611ee9bbb9a6093a73035493aaa81b0 to your computer and use it in GitHub Desktop.
Efficient killer/sandwich sudoku calculator in one line of c#
void Main()
{
var x = new List<int>{1,2,3,4,5,6,7,8,9};
Killer(x,6).Dump();
}
public static List<List<int>> Killer(List<int> alphabet, int target) =>
alphabet.Where(x=> x <= target).SelectMany(letter=>
(letter == target) ?
new List<List<int>> { new List<int> { letter }} :
Killer(alphabet.Where(x => x > letter).ToList(), target - letter)
.Select(s => s.Prepend(letter).ToList())
).ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment