Menu
Coddy logo textTech

Recap - Unique Guest List

Part of the Logic & Flow section of Coddy's Dart journey — lesson 25 of 65.

challenge icon

Challenge

Easy

Create a program that manages an event planning system by analyzing guest lists from two different invitation sources. Your program should:

  1. Read a string input representing the event name
  2. Read multiple string inputs representing guests from the first invitation list (the input will end when you receive "list1_done")
  3. Read multiple string inputs representing guests from the second invitation list (the input will end when you receive "list2_done")
  4. Convert both guest lists to Sets to automatically handle any duplicates within each list
  5. Use the union() method to find all unique guests invited to the event
  6. Use the intersection() method to find guests who appear on both invitation lists
  7. Use the difference() method to find guests who are only on the first invitation list
  8. 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 completed

If 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 completed

If 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 completed

Your 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