Recap - Unique Guest List
Part of the Logic & Flow section of Coddy's Dart journey — lesson 25 of 65.
Challenge
EasyCreate a program that manages an event planning system by analyzing guest lists from two different invitation sources. Your program should:
- Read a string input representing the event name
- Read multiple string inputs representing guests from the first invitation list (the input will end when you receive
"list1_done") - Read multiple string inputs representing guests from the second invitation list (the input will end when you receive
"list2_done") - Convert both guest lists to Sets to automatically handle any duplicates within each list
- Use the
union()method to find all unique guests invited to the event - Use the
intersection()method to find guests who appear on both invitation lists - Use the
difference()method to find guests who are only on the first invitation list - Print the guest list analysis in the exact format shown below
For example, if the event name is "Birthday Party", the first list contains "Alice", "Bob", "Charlie", "Diana", and the second list contains "Bob", "Diana", "Eve", "Frank", your program should output:
Event: Birthday Party
First invitation list: {Alice, Bob, Charlie, Diana}
Second invitation list: {Bob, Diana, Eve, Frank}
All unique guests: {Alice, Bob, Charlie, Diana, Eve, Frank}
Guests on both lists: {Bob, Diana}
Guests only on first list: {Alice, Charlie}
Total unique guests: 6
Duplicate invitations: 2
First list only: 2
Status: Guest list analysis completedIf the event name is "Wedding Reception", the first list contains "John", "Mary", "Sarah", and the second list contains "Tom", "Lisa", "Mike", your program should output:
Event: Wedding Reception
First invitation list: {John, Mary, Sarah}
Second invitation list: {Tom, Lisa, Mike}
All unique guests: {John, Mary, Sarah, Tom, Lisa, Mike}
Guests on both lists: {}
Guests only on first list: {John, Mary, Sarah}
Total unique guests: 6
Duplicate invitations: 0
First list only: 3
Status: Guest list analysis completedIf the event name is "Company Meeting", the first list contains "Alex", "Jordan", "Taylor", "Morgan", "Alex", and the second list contains "Jordan", "Taylor", "Casey", "Jordan", your program should output:
Event: Company Meeting
First invitation list: {Alex, Jordan, Taylor, Morgan}
Second invitation list: {Jordan, Taylor, Casey}
All unique guests: {Alex, Jordan, Taylor, Morgan, Casey}
Guests on both lists: {Jordan, Taylor}
Guests only on first list: {Alex, Morgan}
Total unique guests: 5
Duplicate invitations: 2
First list only: 2
Status: Guest list analysis completedYour program must demonstrate all three set operations: union() to combine all guests, intersection() to find guests appearing on both lists, and difference() to find guests exclusive to the first list. Convert the input lists to Sets first to handle any duplicates within individual lists, then perform the set operations to analyze the guest distribution.
Try it yourself
import 'dart:io';
void main() {
// Read event name
String? eventName = stdin.readLineSync();
// Read first invitation list
List<String> firstList = [];
String? input;
while ((input = stdin.readLineSync()) != "list1_done") {
if (input != null) {
firstList.add(input);
}
}
// Read second invitation list
List<String> secondList = [];
while ((input = stdin.readLineSync()) != "list2_done") {
if (input != null) {
secondList.add(input);
}
}
// Convert lists to sets
Set<String> firstSet = firstList.toSet();
Set<String> secondSet = secondList.toSet();
// TODO: Write your code below
// Use union(), intersection(), and difference() methods to analyze the guest lists
// Calculate all unique guests, guests on both lists, and guests only on first list
// Print the results in the required format
print("Event: $eventName");
print("First invitation list: $firstSet");
print("Second invitation list: $secondSet");
// Add remaining output statements here
}All lessons in Logic & Flow
1Advanced List Manipulation
List Properties: first & lastList State: isEmpty & isNotEmpReversing a ListAdding to a List: insertList Removal: removeWhereFinding in a List: indexOfSorting a ListShuffling a ListRecap - List Organizer4Advanced Map Manipulation
Iterating Over a MapChecking for Keys and ValuesMap Properties: keys & valuesConditional Add: putIfAbsentRemoving Entries from a MapNested MapsRecap - Inventory Update2Functional List Operations
Transforming with 'map'Filtering with 'where'Using '.toList()'Checking Conditions with 'any'Conditions with 'every'Finding with 'firstWhere'Recap - Data Filtering5Project: Shopping Cart Calc
Project SetupAdding Items to the Cart3Sets
What is a Set?Creating a SetAdding and Removing from SetsChecking for Elements in a SetConverting a List to a SetSet UnionSet IntersectionSet DifferenceRecap - Unique Guest List