๐
This file contains hidden or 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
| void main() { | |
| print(getIndex('Red')); | |
| } | |
| // a function that returns the index of a particular resistor color | |
| // taking the color as argument | |
| int getIndex(color) { | |
| var dict = { | |
| 'Black': 0, | |
| 'Brown': 1, |
This file contains hidden or 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
| void main() { | |
| print(reverse('30days of code')); // should pass | |
| print(reverse('30daysofcode')); // should pass | |
| } | |
| // a function that prints out the reverse of a string | |
| // here we split the string, reverse the array and join | |
| // we should also remove white spaces. | |
| String reverse(word) { | |
| String newString = word.replaceAll(" ", "").split('').reversed.join(); |
This file contains hidden or 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
| void main() { | |
| print(isleapyear(1996)); // a true leap year | |
| print(isleapyear(2000)); // a true leap year | |
| print(isleapyear(1900)); // a false leap year | |
| } | |
| bool isleapyear(int year) => | |
| (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); |
This file contains hidden or 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
| void main() { | |
| print(isIsogram('')); // should return true | |
| print(isIsogram('30days - of code')); // should return false | |
| print(isIsogram('as -d f- gh')); // should return true as hyphen and spaces are allowed multiple times | |
| print(isIsogram('a')); // single letter should return true | |
| print(isIsogram('36797')); // single number should return false | |
| } | |
| // String letters = 'abcdefghijklmnopqrstuvwxyz'; |
This file contains hidden or 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
| void main() { | |
| print(countWords( "That's the password: PASSWORD 123!, cried the Special Agent.\nSo I fled.")); // should do a proper count | |
| print(countWords("You you YOU")); // should return you:3 as it is case insensitive | |
| print(countWords("3,3,3")); // should return 3:3 as stated in the problem | |
| print(countWords("333")); // should return 333:1 as stated in the problem | |
| } | |
| // Hold the input in a map for key value pairs | |
| // Using RegExp to ensure it matches the format in the prob statement |
This file contains hidden or 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
| import 'dart:math'; | |
| void main() { | |
| // uncomment below for list n difference of squares with i < n+1 | |
| // for (int i = 0; i < 11; i++) { // for a list of difference from 0 to 10 | |
| // print(differenceOfSquares(i)); | |
| // } | |
| print(differenceOfSquares(10)); // returns 3025 - 385 = 2640. | |
| } |
This file contains hidden or 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
| void main() { | |
| num number = 60; | |
| print('prime factors of $number: ${primeFactors(number)}'); | |
| } | |
| primeFactors(number) { | |
| var factors = [], i = 2; | |
| while (number > 1) { | |
| if (number % i == 0) { | |
| factors.add(i); number /= i; i = 2; |
This file contains hidden or 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
| // pascal triangle | |
| void main() { | |
| print(pascalTriangle(5)); // [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]] | |
| print("--------------------------"); | |
| print(pascalTriangle(1)); // should return 1 | |
| print("--------------------------"); | |
| print(pascalTriangle(0)); // should return empty [] | |
| print("--------------------------"); | |
| print(pascalTriangle(-6)); // should return -1 |
This file contains hidden or 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
| void main() { | |
| Triangle firstTriangle = Triangle(10, 10, 15); | |
| Triangle secondTriangle = Triangle(10, 15, 20); | |
| Triangle thirdTriangle = Triangle(10, 10, 10); | |
| print(firstTriangle.triangleType); | |
| print(secondTriangle.triangleType); | |
| print(thirdTriangle.triangleType); | |
| } | |
| class Triangle { |
This file contains hidden or 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
| void main() { | |
| String s = 'The quick brown fox jumps over the lazy dog'; | |
| print(isPanagram(s)); | |
| } | |
| bool isPanagram(String phrase) { | |
| List<String> alphas = 'abcdefghijklmnopqrstuvwxyz'.split(''); // all alphabets | |
| var newPhrase = phrase | |
| .replaceAll(' ', '') | |
| .toLowerCase(); // remove spaces and take to lower case |
OlderNewer