Created
July 28, 2016 15:54
-
-
Save BillWagner/b638cb3d7e2f77c8ae3e371eda1b6b04 to your computer and use it in GitHub Desktop.
Any and All Puzzle
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 static System.Console; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace AnyAndAll | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var sequence = GetSpecialSequence(); | |
// Prints "True" | |
WriteLine(sequence.All(b => b == true)); | |
// Prints "False" | |
WriteLine(sequence.Any(b => b == true)); | |
} | |
private static IEnumerable<bool> GetSpecialSequence() | |
{ | |
// Puzzle: What should this implementation be? | |
return null; | |
} | |
} | |
} |
pavel-yermalovich
commented
Jul 28, 2016
•
My buddy once said: 'All of my purses are coach purses.' His statement was vacuously true because he owns no purses at all (or at least that's what he wants me to believe.)
var ownedPurses = Enumerable.Empty<Purse>();
Func<Purse, bool> isCoachPurse = purse => purse is CoachPurse;
Console.WriteLine(ownedPurses.All(isCoachPurse)); // all of the purses ARE coach purses
Console.WriteLine(!ownedPurses.Any(purse => !isCoachPurse(purse))); // none of the purses are NOT coach purses
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment