Skip to content

Instantly share code, notes, and snippets.

@ThinkDigitalSoftware
Last active October 25, 2020 21:04
Show Gist options
  • Save ThinkDigitalSoftware/4557d1ccddf9a9ef9194ec493c88f395 to your computer and use it in GitHub Desktop.
Save ThinkDigitalSoftware/4557d1ccddf9a9ef9194ec493c88f395 to your computer and use it in GitHub Desktop.
void main() {
final map = {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]};
var listOfItems = [1, 2, 3, 4, 5, 6, 7 ,8, 9]..shuffle();
final mappedItems = {};
int iterations = 0;
for(final key in map.keys){
final listOfItemsCopy = List<int>.from(listOfItems);
final validItems = [];
for(final item in listOfItems){
if(map[key].contains(item)){
validItems.add(item);
listOfItemsCopy.remove(item);
}
iterations++;
}
mappedItems[key] = validItems;
listOfItems = listOfItemsCopy;
iterations++;
}
print(mappedItems);
print('Total iterations: $iterations');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment