Flutter Dev’s Post

Flutter is ready for the big stage. 🎸 We're officially 1 week away from #FlutterInProduction. → https://goo.gle/FiP Let's celebrate with a coding challenge: Write Dart code to generate all 3-note combinations in the A to G scale. Bonus: only include ascending combos (e.g., 'ABC', not 'CBA'). Can you code the perfect harmony? Share below! 🎶

Fathi Wehba

Muslim | 🚀 Mobile App Developer | AI, Cloud & Cross-Platform Solutions | Scalable Apps, Blockchain, Web3 | Clean Architecture | Innovator in Generative AI & Digital Transformation | Sustainability Advocate

4d

List<String> generateMusicalCombinations() {  // Define the musical scale from A to G  final scale = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];     // List to store our ascending 3-note combinations  final combinations = <String>[];     // Triple nested loop to generate all ascending combinations  for (int i = 0; i < scale.length - 2; i++) {   for (int j = i + 1; j < scale.length - 1; j++) {    for (int k = j + 1; k < scale.length; k++) {     combinations.add('${scale[i]}${scale[j]}${scale[k]}');    }   }  }     return combinations; } void main() {  final musicCombos = generateMusicalCombinations();     // Print out all the combinations  print('Total Combinations: ${musicCombos.length}');  print('Combinations: $musicCombos'); }

Like
Reply
MOHAMMAD RAZIQ JASMI

Mobile Application Developer (Flutter)

3d

void main() { List<String> items = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; List<String> result = []; for (int i = 0; i <= items.length - 3; i++) { result.add(items.sublist(i, i + 3).join()); } print(result); }

Andras Lengyel

App Designer/Developer and Founder at CalluxNet AB

3d

We do have semitones in the scale. My solution to this: enum Note { a, aSharp, b, c, cSharp, d, dSharp, e, f, fSharp, g, gSharp; @override String toString() => name.replaceAll("Sharp", "#").toUpperCase(); } List<String> generateThreeNoteCombinations() { List<String> combinations = []; for(int note1=Note.a.index; note1 <= Note.f.index; note1++) for(int note2=note1+1; note2 <= Note.fSharp.index; note2++) for(int note3=note2+1; note3 <= Note.g.index; note3++) combinations.add('${Note.values[note1]}${Note.values[note2]}${Note.values[note3]}'); return combinations; } main() { final combinations = generateThreeNoteCombinations(); print(combinations); }

Like
Reply
Muhammad Varriel Avenazh Nizar

Flutter Developer at PT InKanteen Technology Solutions | Computer Science Graduate from STIMIK ESQ | Ex-Intern at WorkLifeAndBeyond | Content Creator

3d

void main() { // Define the musical scale const scale = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; // Generate all ascending 3-note combinations final combinations = <String>[]; for (int i = 0; i < scale.length; i++) { for (int j = i + 1; j < scale.length; j++) { for (int k = j + 1; k < scale.length; k++) { combinations.add('${scale[i]}${scale[j]}${scale[k]}'); } } } // Print the combinations print('All ascending 3-note combinations:'); combinations.forEach(print); }

Like
Reply
Muhammad Shuhaib M M

Team Lead | Senior Flutter Developer

3d

void main() { List<String> notes = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; List<String> combinations = [ for (int i = 0; i <= notes.length - 3; i++) notes.sublist(i, i + 3).join() ]; print(combinations); }

Like
Reply
See more comments

To view or add a comment, sign in

Explore topics