diff --git a/.github/workflows/dart_test_analyze_format.yml b/.github/workflows/dart_test_analyze_format.yml index ce138056..a0911f2e 100644 --- a/.github/workflows/dart_test_analyze_format.yml +++ b/.github/workflows/dart_test_analyze_format.yml @@ -4,12 +4,12 @@ jobs: dart_test_analyze_format: runs-on: ubuntu-latest container: - image: google/dart + image: dart:stable steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # - run: (echo 'deb http://deb.debian.org/debian buster main contrib non-free') > /etc/apt/sources.list.d/buster.list - run: dart pub get - run: dart format --set-exit-if-changed . - run: dart test --coverage . - - run: dart pub run coverage:format_coverage -i . -l > coverage.lcov + - run: dart run coverage:format_coverage -i . -l > coverage.lcov - run: dart analyze diff --git a/array/car_pool.dart b/array/car_pool.dart index 7c8d7e79..b5cbb401 100644 --- a/array/car_pool.dart +++ b/array/car_pool.dart @@ -33,24 +33,24 @@ bool carPooling(List> trips, int capacity) { void main() { List> trips = [ [2, 1, 5], - [3, 3, 7] + [3, 3, 7], ]; List> trips1 = [ [2, 1, 5], - [3, 5, 7] + [3, 5, 7], ]; List> trips2 = [ [2, 2, 6], [2, 4, 7], - [8, 6, 7] + [8, 6, 7], ]; List> trips3 = [ [7, 5, 6], [6, 7, 8], - [10, 1, 6] + [10, 1, 6], ]; test('test case 1', () => expect(carPooling(trips, 4), false)); diff --git a/array/sorted_squared_array.dart b/array/sorted_squared_array.dart index cc0c0407..791474fc 100644 --- a/array/sorted_squared_array.dart +++ b/array/sorted_squared_array.dart @@ -30,12 +30,26 @@ void main() { }); test('test case 2', () { - expect(sortedSquaredArray([-7, -6, -5, -4, -3, -2, -1]), - [1, 4, 9, 16, 25, 36, 49]); + expect(sortedSquaredArray([-7, -6, -5, -4, -3, -2, -1]), [ + 1, + 4, + 9, + 16, + 25, + 36, + 49, + ]); }); test('test case 4', () { - expect( - sortedSquaredArray([1, 2, 3, 4, 5, 6, 7]), [1, 4, 9, 16, 25, 36, 49]); + expect(sortedSquaredArray([1, 2, 3, 4, 5, 6, 7]), [ + 1, + 4, + 9, + 16, + 25, + 36, + 49, + ]); }); } diff --git a/backtracking/open_knight_tour.dart b/backtracking/open_knight_tour.dart index 9f74c601..6825fe80 100644 --- a/backtracking/open_knight_tour.dart +++ b/backtracking/open_knight_tour.dart @@ -94,70 +94,77 @@ void printBoard(List> board) { void main() { test(('getValidPos: testCase #1'), () { expect( - getValidPos([1, 3], 4), - equals([ - [2, 1], - [0, 1], - [3, 2] - ])); + getValidPos([1, 3], 4), + equals([ + [2, 1], + [0, 1], + [3, 2], + ]), + ); }); test(('getValidPos: testCase #3'), () { expect( - getValidPos([1, 2], 5), - equals([ - [2, 4], - [0, 4], - [2, 0], - [0, 0], - [3, 3], - [3, 1] - ])); + getValidPos([1, 2], 5), + equals([ + [2, 4], + [0, 4], + [2, 0], + [0, 0], + [3, 3], + [3, 1], + ]), + ); }); test(('isComplete: testCase #1'), () { expect( - isComplete([ - [1] - ]), - equals(true)); + isComplete([ + [1], + ]), + equals(true), + ); }); test(('isComplete: testCase #2'), () { expect( - isComplete([ - [1, 2], - [3, 0] - ]), - equals(false)); + isComplete([ + [1, 2], + [3, 0], + ]), + equals(false), + ); }); test(('openKnightTour: testCase #1'), () { expect( - openKnightTour(1), - equals([ - [1] - ])); + openKnightTour(1), + equals([ + [1], + ]), + ); }); test(('openKnightTour: testCase #2'), () { expect( - openKnightTour(2), - equals([ - [0, 0], - [0, 0] - ])); + openKnightTour(2), + equals([ + [0, 0], + [0, 0], + ]), + ); }); test(('openKnightTour: testCase #3'), () { expect( - openKnightTour(5), - equals([ - [1, 14, 19, 8, 25], - [6, 9, 2, 13, 18], - [15, 20, 7, 24, 3], - [10, 5, 22, 17, 12], - [21, 16, 11, 4, 23] - ])); + openKnightTour(5), + equals([ + [1, 14, 19, 8, 25], + [6, 9, 2, 13, 18], + [15, 20, 7, 24, 3], + [10, 5, 22, 17, 12], + [21, 16, 11, 4, 23], + ]), + ); }); } diff --git a/conversions/Decimal_To_Any.dart b/conversions/Decimal_To_Any.dart index d9f6c3e8..4dfdaed7 100644 --- a/conversions/Decimal_To_Any.dart +++ b/conversions/Decimal_To_Any.dart @@ -31,7 +31,7 @@ String decimalToAny(int value, int base) { 32: 'W', 33: 'X', 34: 'Y', - 35: 'Z' + 35: 'Z', }; if (value == 0) return "0"; @@ -48,7 +48,8 @@ String decimalToAny(int value, int base) { while (value > 0) { int remainder = value % base; value = value ~/ base; - output = (remainder < 10 + output = + (remainder < 10 ? remainder.toString() : ALPHABET_VALUES[remainder] ?? '0') + output; diff --git a/conversions/Integer_To_Roman.dart b/conversions/Integer_To_Roman.dart index 29f4a7fd..f15d37ff 100644 --- a/conversions/Integer_To_Roman.dart +++ b/conversions/Integer_To_Roman.dart @@ -20,7 +20,7 @@ List ArabianRomanNumbers = [ 9, 5, 4, - 1 + 1, ]; List RomanNumbers = [ @@ -36,7 +36,7 @@ List RomanNumbers = [ "IX", "V", "IV", - "I" + "I", ]; List integer_to_roman(int num) { diff --git a/conversions/binary_to_decimal.dart b/conversions/binary_to_decimal.dart index 963275d2..e39bcaf9 100644 --- a/conversions/binary_to_decimal.dart +++ b/conversions/binary_to_decimal.dart @@ -14,7 +14,8 @@ int binaryToDecimal(String binaryString) { if ("01".contains(binaryString[i]) == false) { throw FormatException("Non-binary value was passed to the function"); } else { - decimalValue += (pow(2, binaryString.length - i - 1).toInt() * + decimalValue += + (pow(2, binaryString.length - i - 1).toInt() * (int.tryParse(binaryString[i]) ?? 0)); } } diff --git a/conversions/hexadecimal_to_decimal.dart b/conversions/hexadecimal_to_decimal.dart index 1049b20b..416a8585 100644 --- a/conversions/hexadecimal_to_decimal.dart +++ b/conversions/hexadecimal_to_decimal.dart @@ -32,7 +32,8 @@ int hexadecimal_to_decimal(String hex_string) { hex_table.containsKey(hex_string[i]) == false) { throw Exception("Non-hex value was passed to the function"); } else { - decimal_val += pow(16, hex_string.length - i - 1).toInt() * + decimal_val += + pow(16, hex_string.length - i - 1).toInt() * (int.tryParse(hex_string[i]) ?? hex_table[hex_string[i]] ?? 0); } } diff --git a/conversions/hexadecimal_to_octal.dart b/conversions/hexadecimal_to_octal.dart index 44294606..c72e29c2 100644 --- a/conversions/hexadecimal_to_octal.dart +++ b/conversions/hexadecimal_to_octal.dart @@ -64,7 +64,8 @@ String hexadecimal_to_octal(String hex_val) { break; default: throw new FormatException( - "An invalid value was passed to the function"); + "An invalid value was passed to the function", + ); } } diff --git a/conversions/roman_to_integer.dart b/conversions/roman_to_integer.dart index 27f8df7a..95d21b86 100644 --- a/conversions/roman_to_integer.dart +++ b/conversions/roman_to_integer.dart @@ -32,7 +32,8 @@ int value(var r) { return 100; else if (r == 'D') return 500; - else if (r == 'M') return 1000; + else if (r == 'M') + return 1000; return 0; } diff --git a/data_structures/Heap/Binary_Heap/Max_heap.dart b/data_structures/Heap/Binary_Heap/Max_heap.dart index 37457b7c..752d399a 100644 --- a/data_structures/Heap/Binary_Heap/Max_heap.dart +++ b/data_structures/Heap/Binary_Heap/Max_heap.dart @@ -28,8 +28,8 @@ class MaxHeap { void _siftUp(int currentIndex) { int parentIndex = (currentIndex - 1) ~/ 2; - while ( - parentIndex >= 0 && this.heap[parentIndex] < this.heap[currentIndex]) { + while (parentIndex >= 0 && + this.heap[parentIndex] < this.heap[currentIndex]) { _swap(parentIndex, currentIndex, this.heap); currentIndex = parentIndex; parentIndex = (currentIndex - 1) ~/ 2; @@ -41,8 +41,9 @@ class MaxHeap { int childTwoIndex; while (childOneIndex <= endIndex) { - childTwoIndex = - 2 * currentIndex + 2 <= endIndex ? 2 * currentIndex + 2 : -1; + childTwoIndex = 2 * currentIndex + 2 <= endIndex + ? 2 * currentIndex + 2 + : -1; int indexToSwap; if (childTwoIndex != -1 && heap[childTwoIndex] > heap[childOneIndex]) { indexToSwap = childTwoIndex; diff --git a/data_structures/Heap/Binary_Heap/min_heap_two.dart b/data_structures/Heap/Binary_Heap/min_heap_two.dart index 5672cccd..6627b3c1 100644 --- a/data_structures/Heap/Binary_Heap/min_heap_two.dart +++ b/data_structures/Heap/Binary_Heap/min_heap_two.dart @@ -28,8 +28,8 @@ class MinHeap { void _siftUp(int currentIndex) { int parentIndex = (currentIndex - 1) ~/ 2; - while ( - parentIndex >= 0 && this.heap[parentIndex] > this.heap[currentIndex]) { + while (parentIndex >= 0 && + this.heap[parentIndex] > this.heap[currentIndex]) { _swap(parentIndex, currentIndex, this.heap); currentIndex = parentIndex; parentIndex = (currentIndex - 1) ~/ 2; @@ -41,8 +41,9 @@ class MinHeap { int childTwoIndex; while (childOneIndex <= endIndex) { - childTwoIndex = - 2 * currentIndex + 2 <= endIndex ? 2 * currentIndex + 2 : -1; + childTwoIndex = 2 * currentIndex + 2 <= endIndex + ? 2 * currentIndex + 2 + : -1; int indexToSwap; if (childTwoIndex != -1 && heap[childTwoIndex] < heap[childOneIndex]) { indexToSwap = childTwoIndex; diff --git a/data_structures/Stack/balanced_brackets.dart b/data_structures/Stack/balanced_brackets.dart index b10abba9..f32fb303 100644 --- a/data_structures/Stack/balanced_brackets.dart +++ b/data_structures/Stack/balanced_brackets.dart @@ -46,8 +46,10 @@ void main() { test(('Balanced Bracket'), () { expect( - isBalancedBrackets( - '(((((([[[[[[{{{{{{{{{{{{()}}}}}}}}}}}}]]]]]]))))))((([])({})[])[])[]([]){}(())'), - isTrue); + isBalancedBrackets( + '(((((([[[[[[{{{{{{{{{{{{()}}}}}}}}}}}}]]]]]]))))))((([])({})[])[])[]([]){}(())', + ), + isTrue, + ); }); } diff --git a/data_structures/linked_list/linked_list.dart b/data_structures/linked_list/linked_list.dart index 54a7b504..a0eda717 100644 --- a/data_structures/linked_list/linked_list.dart +++ b/data_structures/linked_list/linked_list.dart @@ -8,7 +8,7 @@ class Node { Node.before(this.next, this.value); } -class LinkedListIterator extends Iterator { +class LinkedListIterator implements Iterator { Node? _current; @override diff --git a/data_structures/linked_list/merge_sorted_list.dart b/data_structures/linked_list/merge_sorted_list.dart index 575667f9..c31c26c7 100644 --- a/data_structures/linked_list/merge_sorted_list.dart +++ b/data_structures/linked_list/merge_sorted_list.dart @@ -69,18 +69,26 @@ ListNode? mergeTwoLists(ListNode? list1, ListNode? list2) { void main() { test('test case 1', () { - ListNode head1 = - ListNode(val: 1, next: ListNode(val: 2, next: ListNode(val: 4))); - ListNode head2 = - ListNode(val: 1, next: ListNode(val: 3, next: ListNode(val: 4))); + ListNode head1 = ListNode( + val: 1, + next: ListNode(val: 2, next: ListNode(val: 4)), + ); + ListNode head2 = ListNode( + val: 1, + next: ListNode(val: 3, next: ListNode(val: 4)), + ); expect(mergeTwoLists(head1, head2).listValues(), [1, 1, 2, 3, 4, 4]); }); test('test case 2', () { - ListNode head1 = - ListNode(val: 1, next: ListNode(val: 2, next: ListNode(val: 3))); - ListNode head2 = - ListNode(val: 4, next: ListNode(val: 5, next: ListNode(val: 6))); + ListNode head1 = ListNode( + val: 1, + next: ListNode(val: 2, next: ListNode(val: 3)), + ); + ListNode head2 = ListNode( + val: 4, + next: ListNode(val: 5, next: ListNode(val: 6)), + ); expect(mergeTwoLists(head1, head2).listValues(), [1, 2, 3, 4, 5, 6]); }); } diff --git a/dynamic_programming/01knapsack_recursive.dart b/dynamic_programming/01knapsack_recursive.dart index 7a9c28c7..55924098 100644 --- a/dynamic_programming/01knapsack_recursive.dart +++ b/dynamic_programming/01knapsack_recursive.dart @@ -1,8 +1,12 @@ import 'dart:math'; import 'package:test/test.dart'; -int knapSackProblem(int capacity, List values, List weights, - [int? numberOfItems]) { +int knapSackProblem( + int capacity, + List values, + List weights, [ + int? numberOfItems, +]) { numberOfItems ??= values.length; if (numberOfItems == 0 || capacity == 0) { return 0; @@ -12,10 +16,15 @@ int knapSackProblem(int capacity, List values, List weights, if (weights[numberOfItems - 1] <= capacity) { return max( - currentValue + - knapSackProblem( - capacity - currentWeight, values, weights, numberOfItems - 1), - knapSackProblem(capacity, values, weights, numberOfItems - 1)); + currentValue + + knapSackProblem( + capacity - currentWeight, + values, + weights, + numberOfItems - 1, + ), + knapSackProblem(capacity, values, weights, numberOfItems - 1), + ); } else { return knapSackProblem(capacity, values, weights, numberOfItems - 1); } @@ -34,6 +43,8 @@ void main() { test('TC: 2', () { expect( - knapSackProblem(100, [2, 70, 30, 69, 100], [1, 70, 30, 69, 100]), 101); + knapSackProblem(100, [2, 70, 30, 69, 100], [1, 70, 30, 69, 100]), + 101, + ); }); } diff --git a/dynamic_programming/coin_change.dart b/dynamic_programming/coin_change.dart index 4f3367be..f03c64f9 100644 --- a/dynamic_programming/coin_change.dart +++ b/dynamic_programming/coin_change.dart @@ -8,8 +8,10 @@ import 'package:test/test.dart'; /// time complexity O(targetAmount * coinDenoms) /// space complexity O(targetAmount) int minNumberOfCoins(int targetAmount, List coinDenoms) { - List amounts = - new List.generate(targetAmount + 1, (int index) => 1000000000000); + List amounts = new List.generate( + targetAmount + 1, + (int index) => 1000000000000, + ); amounts[0] = 0; diff --git a/dynamic_programming/longest_common_substring.dart b/dynamic_programming/longest_common_substring.dart index 3662c60d..46918727 100644 --- a/dynamic_programming/longest_common_substring.dart +++ b/dynamic_programming/longest_common_substring.dart @@ -53,8 +53,11 @@ void main() { }); test(('testCase #10'), () { expect( - longestCommonSubstring( - "OldSite:GeeksforGeeks.org", "NewSite:GeeksQuiz.com"), - equals(10)); + longestCommonSubstring( + "OldSite:GeeksforGeeks.org", + "NewSite:GeeksQuiz.com", + ), + equals(10), + ); }); } diff --git a/graphs/area_of_island.dart b/graphs/area_of_island.dart index 1cac46a0..688dc037 100644 --- a/graphs/area_of_island.dart +++ b/graphs/area_of_island.dart @@ -19,14 +19,16 @@ const List> deltas = [ [-1, 0], // top neighbour [0, 1], // right neighbour [1, 0], // bottom neighbour - [0, -1] // left neighbour. + [0, -1], // left neighbour. ]; int maxAreaOfIsland(List> grid) { int numRows = grid.length; int numCols = grid[0].length; - List> visited = - List.generate(numRows, (int index) => List.filled(numCols, false)); + List> visited = List.generate( + numRows, + (int index) => List.filled(numCols, false), + ); List areas = []; for (int i = 0; i < numRows; ++i) { @@ -43,7 +45,11 @@ bool isInvalidIndex(int i, int j, int rowCount, int colCount) { } List> adjacentNodes( - List> grid, List> visited, int x, int y) { + List> grid, + List> visited, + int x, + int y, +) { List> nodes = []; for (int i = 0; i < deltas.length; ++i) { int dx = x + deltas[i][0]; @@ -57,11 +63,16 @@ List> adjacentNodes( return nodes; } -void traverseNode(int i, int j, List> grid, List> visited, - List areas) { +void traverseNode( + int i, + int j, + List> grid, + List> visited, + List areas, +) { int area = 0; List> nodesToExplore = [ - [i, j] + [i, j], ]; while (nodesToExplore.isNotEmpty) { List node = nodesToExplore.removeLast(); @@ -91,7 +102,7 @@ void main() { [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0] + [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0], ]; expect(maxAreaOfIsland(island), 6); }); diff --git a/graphs/breadth_first_search.dart b/graphs/breadth_first_search.dart index 4a7406f7..ff504d0d 100644 --- a/graphs/breadth_first_search.dart +++ b/graphs/breadth_first_search.dart @@ -61,7 +61,7 @@ void main() { List> edges = [ [0, 1], - [0, 2] + [0, 2], ]; Graph graph = Graph(nodes); @@ -71,8 +71,11 @@ void main() { graph.addEdges(start, end); } int startNode = 0; - List answer = - breadthFirstSearch(graph, graph.numberOfNodesInGraph, startNode); + List answer = breadthFirstSearch( + graph, + graph.numberOfNodesInGraph, + startNode, + ); expect(answer, equals([0, 1, 2])); }); @@ -84,7 +87,7 @@ void main() { [0, 1], [0, 2], [0, 3], - [2, 4] + [2, 4], ]; Graph graph = Graph(nodes); @@ -94,8 +97,11 @@ void main() { graph.addEdges(start, end); } int startNode = 0; - List answer = - breadthFirstSearch(graph, graph.numberOfNodesInGraph, startNode); + List answer = breadthFirstSearch( + graph, + graph.numberOfNodesInGraph, + startNode, + ); expect(answer, equals([0, 1, 2, 3, 4])); }); } diff --git a/graphs/depth_first_search.dart b/graphs/depth_first_search.dart index ac85cffd..4903e584 100644 --- a/graphs/depth_first_search.dart +++ b/graphs/depth_first_search.dart @@ -56,8 +56,10 @@ void depthFirstSearchHelper(graph, visitedNodes, node, answer) { } List depthFirstSearch(Graph graph, int numberOfNodes, int startNode) { - List visitedNodes = - new List.generate(numberOfNodes, (index) => false); + List visitedNodes = new List.generate( + numberOfNodes, + (index) => false, + ); List answer = []; depthFirstSearchHelper(graph.graph, visitedNodes, startNode, answer); @@ -72,7 +74,7 @@ void main() { List> edges = [ [0, 1], [1, 2], - [0, 3] + [0, 3], ]; Graph graph = Graph(nodes); @@ -82,8 +84,11 @@ void main() { graph.addEdges(start, end); } int startNode = 0; - List answer = - depthFirstSearch(graph, graph.numberOfNodesInGraph, startNode); + List answer = depthFirstSearch( + graph, + graph.numberOfNodesInGraph, + startNode, + ); expect(answer, equals([0, 1, 2, 3])); }); @@ -95,7 +100,7 @@ void main() { [0, 1], [0, 2], [0, 3], - [2, 4] + [2, 4], ]; Graph graph = Graph(nodes); @@ -105,8 +110,11 @@ void main() { graph.addEdges(start, end); } int startNode = 0; - List answer = - depthFirstSearch(graph, graph.numberOfNodesInGraph, startNode); + List answer = depthFirstSearch( + graph, + graph.numberOfNodesInGraph, + startNode, + ); expect(answer, equals([0, 1, 2, 4, 3])); }); } diff --git a/graphs/nearest_neighbour_algorithm.dart b/graphs/nearest_neighbour_algorithm.dart index 3a72664d..50dc2dcd 100644 --- a/graphs/nearest_neighbour_algorithm.dart +++ b/graphs/nearest_neighbour_algorithm.dart @@ -71,19 +71,16 @@ Graph fromPoints(List points) { } void main() { - Graph graph = Graph([ - "A", - "B", - "C", - "D", - "E" - ], [ - [0, 12, 4, 54, 100], - [3, 0, 5, 1, 1], - [300, 20, 0, 433, 123], - [32, 31, 54, 0, 3], - [2, 65, 12, 32, 0] - ]); + Graph graph = Graph( + ["A", "B", "C", "D", "E"], + [ + [0, 12, 4, 54, 100], + [3, 0, 5, 1, 1], + [300, 20, 0, 433, 123], + [32, 31, 54, 0, 3], + [2, 65, 12, 32, 0], + ], + ); print(nearestNeighbourSearch(graph)); @@ -94,7 +91,7 @@ void main() { new Point(3.33, 8.11), new Point(12, 11), new Point(-1, 1), - new Point(-2, 2) + new Point(-2, 2), ]; print(nearestNeighbourSearch(fromPoints(points))); diff --git a/maths/Ugly_numbers.dart b/maths/Ugly_numbers.dart index d09dc210..03f17ab8 100644 --- a/maths/Ugly_numbers.dart +++ b/maths/Ugly_numbers.dart @@ -23,7 +23,7 @@ int getNthUglyNo(int n) { int i = 1; int count = 1; /* ugly number count */ -/*Check for all integers untill ugly count + /*Check for all integers untill ugly count becomes n*/ while (n > count) { i++; diff --git a/maths/factors.dart b/maths/factors.dart index 8f624505..5538449d 100644 --- a/maths/factors.dart +++ b/maths/factors.dart @@ -2,8 +2,9 @@ void main() { print("factors: ${factorsOf(12)}"); //factors: [1, 2, 3, 4, 6, 12] try { - print(factorsOf(-1) - .toString()); //Unhandled exception: Exception: A non-positive value was passed to the function + print( + factorsOf(-1).toString(), + ); //Unhandled exception: Exception: A non-positive value was passed to the function } catch (ex) { print(ex); } diff --git a/maths/fermats_little_theorem.dart b/maths/fermats_little_theorem.dart index 56073fe7..4d3847eb 100644 --- a/maths/fermats_little_theorem.dart +++ b/maths/fermats_little_theorem.dart @@ -1,5 +1,4 @@ @Skip('currently failing (see issue #86)') - import 'package:test/test.dart'; /* diff --git a/maths/find_max_recursion.dart b/maths/find_max_recursion.dart index d9565953..5a20f6e0 100644 --- a/maths/find_max_recursion.dart +++ b/maths/find_max_recursion.dart @@ -12,9 +12,15 @@ int find_max_recursion(List numbers, int low, int high) { return numbers[low]; // or numbers[high] } int mid = (low + high) >> 1; - int leftMax = - find_max_recursion(numbers, low, mid); /* max in range [low mid] */ + int leftMax = find_max_recursion( + numbers, + low, + mid, + ); /* max in range [low mid] */ int rightMax = find_max_recursion( - numbers, mid + 1, high); /* max in range [mid + 1, high] */ + numbers, + mid + 1, + high, + ); /* max in range [mid + 1, high] */ return leftMax >= rightMax ? leftMax : rightMax; } diff --git a/maths/find_min_recursion.dart b/maths/find_min_recursion.dart index b53ca13e..0c4b7be1 100644 --- a/maths/find_min_recursion.dart +++ b/maths/find_min_recursion.dart @@ -12,9 +12,15 @@ int find_min_recursion(List numbers, int low, int high) { return numbers[low]; // or numbers[high] } int mid = (low + high) >> 1; - int leftMin = - find_min_recursion(numbers, low, mid); /* min in range [low mid] */ + int leftMin = find_min_recursion( + numbers, + low, + mid, + ); /* min in range [low mid] */ int rightMin = find_min_recursion( - numbers, mid + 1, high); /* min in range [mid + 1, high] */ + numbers, + mid + 1, + high, + ); /* min in range [mid + 1, high] */ return leftMin <= rightMin ? leftMin : rightMin; } diff --git a/maths/lu_decomposition.dart b/maths/lu_decomposition.dart index 7980fcd5..d0350a7e 100644 --- a/maths/lu_decomposition.dart +++ b/maths/lu_decomposition.dart @@ -280,11 +280,13 @@ double f(double x, double y) { } void main() { - Matrix a = new Matrix(values: [ - [3, 2, -1], - [2, -2, 4], - [-1, 0.5, -1] - ]); + Matrix a = new Matrix( + values: [ + [3, 2, -1], + [2, -2, 4], + [-1, 0.5, -1], + ], + ); List b = [1, -2, 0]; List solution = solve(a, b); diff --git a/maths/newton_method.dart b/maths/newton_method.dart index 49d6418d..4862181a 100644 --- a/maths/newton_method.dart +++ b/maths/newton_method.dart @@ -6,8 +6,12 @@ double derivative(double Function(double) f, double x, [double h = 1e-10]) { } /// Find root of given [f] (x where [f(x)] == 0) -double findRoot(double Function(double) f, - [double initialValue = 0, int iterations = 10, double h = 1e-10]) { +double findRoot( + double Function(double) f, [ + double initialValue = 0, + int iterations = 10, + double h = 1e-10, +]) { double currentValue = initialValue; for (int i = 0; i < iterations; i++) { currentValue -= f(currentValue) / derivative(f, currentValue); diff --git a/maths/sigmoid.dart b/maths/sigmoid.dart index c0ba4e8d..c2235164 100644 --- a/maths/sigmoid.dart +++ b/maths/sigmoid.dart @@ -1,7 +1,9 @@ import 'dart:math'; double sigmoid( - double x, double a) //x is the function variable and a is the gain + double x, + double a, +) //x is the function variable and a is the gain { double p = exp(-a * x); return 1 / (1 + p); diff --git a/maths/symmetric_derivative.dart b/maths/symmetric_derivative.dart index b192f4c8..d14c0e8d 100644 --- a/maths/symmetric_derivative.dart +++ b/maths/symmetric_derivative.dart @@ -8,6 +8,7 @@ double derivative(double Function(double) f, double x, [double h = 1e-10]) { void main() { print("derivative(sin, pi) = ${derivative(sin, pi)}, cos(pi) = ${cos(pi)}"); print( - "derivative(sin, 2 * pi) = ${derivative(sin, 2 * pi)}, cos(2 * pi) = ${cos(2 * pi)}"); + "derivative(sin, 2 * pi) = ${derivative(sin, 2 * pi)}, cos(2 * pi) = ${cos(2 * pi)}", + ); print("derivative(exp, 3) = ${derivative(exp, 3)}, exp(3) = ${exp(3)}"); } diff --git a/other/LCM.dart b/other/LCM.dart index cdb005ab..3eefc880 100644 --- a/other/LCM.dart +++ b/other/LCM.dart @@ -30,20 +30,24 @@ void main() { a = 15; b = 20; //print the result - print("LCM of " + - a.toString() + - " and " + - b.toString() + - " is " + - lcm(a, b).toString()); + print( + "LCM of " + + a.toString() + + " and " + + b.toString() + + " is " + + lcm(a, b).toString(), + ); //Test case2: a = 12; b = 18; //print the result - print("LCM of " + - a.toString() + - " and " + - b.toString() + - " is " + - lcm(a, b).toString()); + print( + "LCM of " + + a.toString() + + " and " + + b.toString() + + " is " + + lcm(a, b).toString(), + ); } diff --git a/other/haversine_formula.dart b/other/haversine_formula.dart index 8be48ca8..caee0b3b 100644 --- a/other/haversine_formula.dart +++ b/other/haversine_formula.dart @@ -26,7 +26,8 @@ double distance(Coordinates p1, Coordinates p2) { double latitude2 = radians(p2.latitude); double longitudeChange = radians(p2.longitude - p1.longitude); - double a = haversine(latitudeChange) + + double a = + haversine(latitudeChange) + cos(latitude1) * cos(latitude2) * haversine(longitudeChange); double c = 2 * atan2(sqrt(a), sqrt(1 - a)); diff --git a/project_euler/problem_17/sol17.dart b/project_euler/problem_17/sol17.dart index d212e1ea..6a5eb24d 100644 --- a/project_euler/problem_17/sol17.dart +++ b/project_euler/problem_17/sol17.dart @@ -23,7 +23,7 @@ const ONES = [ 'Seven', 'Eight', 'Nine', - 'Ten' + 'Ten', ]; const TEN_TWENTY = [ @@ -35,7 +35,7 @@ const TEN_TWENTY = [ 'Sixteen', 'Seventeen', 'Eighteen', - 'Nineteen' + 'Nineteen', ]; const TENS = [ @@ -47,7 +47,7 @@ const TENS = [ 'Sixty', 'Seventy', 'Eighty', - 'Ninety' + 'Ninety', ]; const HUNDRED = 'Hundred'; diff --git a/project_euler/problem_8/sol8.dart b/project_euler/problem_8/sol8.dart index 49ce87ce..4a1449e6 100644 --- a/project_euler/problem_8/sol8.dart +++ b/project_euler/problem_8/sol8.dart @@ -32,7 +32,8 @@ */ void main() { - String series = "73167176531330624919225119674426574742355349194934" + String series = + "73167176531330624919225119674426574742355349194934" "96983520312774506326239578318016984801869478851843" "85861560789112949495459501737958331952853208805511" "12540698747158523863050715693290963295227443043557" diff --git a/pubspec.yaml b/pubspec.yaml index ddc6d722..5f2cab02 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,4 +10,4 @@ dev_dependencies: stack: ^0.2.1 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ^3.11.0 diff --git a/search/binary_search_recursion.dart b/search/binary_search_recursion.dart index 3ee40a68..359449f6 100644 --- a/search/binary_search_recursion.dart +++ b/search/binary_search_recursion.dart @@ -22,9 +22,17 @@ int binarySearch(List list, int low, int high, int key) { return mid; /* found */ } else if (key > list[mid]) { return binarySearch( - list, mid + 1, high, key); /* search in range[mid + 1, high] */ + list, + mid + 1, + high, + key, + ); /* search in range[mid + 1, high] */ } else { return binarySearch( - list, low, mid - 1, key); /* search in range[low, mid - 1] */ + list, + low, + mid - 1, + key, + ); /* search in range[low, mid - 1] */ } } diff --git a/search/fibonacci_Search.dart b/search/fibonacci_Search.dart index eba8fb04..ea7069e5 100644 --- a/search/fibonacci_Search.dart +++ b/search/fibonacci_Search.dart @@ -42,7 +42,6 @@ int fibMaonaccianSearch(List arr, int x, int n) { fibMMm2 = fibM - fibMMm1; offset = i; } - /* If x is greater than the value at index fibMmm2 * cut the subarray array after i + 1. */ @@ -51,7 +50,6 @@ int fibMaonaccianSearch(List arr, int x, int n) { fibMMm1 = fibMMm1 - fibMMm2; fibMMm2 = fibM - fibMMm1; } - //elwment found.Return index else { return i; diff --git a/search/interpolation_Search.dart b/search/interpolation_Search.dart index 594dcc1c..5e45089c 100644 --- a/search/interpolation_Search.dart +++ b/search/interpolation_Search.dart @@ -16,7 +16,8 @@ int interpolationSearch(List arr, int n, int key) { int low = 0, high = n - 1; while (low <= high && key >= arr[low] && key <= arr[high]) { /* Calculate the nearest possible position of key */ - int pos = low + + int pos = + low + (((key - arr[low]) * (high - low)) / (arr[high] - arr[low])).round(); if (key > arr[pos]) low = pos + 1; diff --git a/sort/bubble_Sort.dart b/sort/bubble_Sort.dart index 3dd5010c..a2e56f04 100644 --- a/sort/bubble_Sort.dart +++ b/sort/bubble_Sort.dart @@ -3,8 +3,11 @@ import 'dart:math' show Random; //main function,the program start void main() { final seed = 100, rnd = Random(), length = 100; - var list = - List.generate(length, (i) => rnd.nextInt(seed), growable: false); + var list = List.generate( + length, + (i) => rnd.nextInt(seed), + growable: false, + ); print('before sorting:'); print(list); print('---------------------------------------------'); diff --git a/sort/count_sort.dart b/sort/count_sort.dart index 38575c87..6ead83eb 100644 --- a/sort/count_sort.dart +++ b/sort/count_sort.dart @@ -61,8 +61,10 @@ int main() { expect(countSort(lst), equals(lst)); }); test("count sort", () { - expect(countSort([34, -2, 122, 24435, 23, 434, 232, 1323]), - equals([-2, 23, 34, 122, 232, 434, 1323, 24435])); + expect( + countSort([34, -2, 122, 24435, 23, 434, 232, 1323]), + equals([-2, 23, 34, 122, 232, 434, 1323, 24435]), + ); }); print(countSort([-10, -4, 1, 5, 2, -2])); diff --git a/sort/insert_Sort.dart b/sort/insert_Sort.dart index 0dfec3ef..3ca0bec3 100644 --- a/sort/insert_Sort.dart +++ b/sort/insert_Sort.dart @@ -2,8 +2,11 @@ import 'dart:math' show Random; void main() { final seed = 100, rnd = Random(), length = 100; - var list = - List.generate(length, (i) => rnd.nextInt(seed), growable: false); + var list = List.generate( + length, + (i) => rnd.nextInt(seed), + growable: false, + ); print('before sorting:'); print(list); print('----------------------------------------------'); diff --git a/sort/merge_sort.dart b/sort/merge_sort.dart index 5bd9355f..522e2c9b 100644 --- a/sort/merge_sort.dart +++ b/sort/merge_sort.dart @@ -51,25 +51,35 @@ List mergeSort(List list, int lIndex, int rIndex) { void main() { List list = [5, 4, 3, 2, 1]; - test('test case 1', - () => expect(mergeSort(list, 0, list.length - 1), [1, 2, 3, 4, 5])); + test( + 'test case 1', + () => expect(mergeSort(list, 0, list.length - 1), [1, 2, 3, 4, 5]), + ); List list1 = []; test('test case 2', () => expect(mergeSort(list1, 0, list1.length - 1), [])); List list2 = [1, 1, 1, 1, 1]; - test('test case 3', - () => expect(mergeSort(list2, 0, list2.length - 1), [1, 1, 1, 1, 1])); + test( + 'test case 3', + () => expect(mergeSort(list2, 0, list2.length - 1), [1, 1, 1, 1, 1]), + ); List list3 = [-1, -11, -1221, -123121, -1111111]; test( - 'test case 4', - () => expect(mergeSort(list3, 0, list3.length - 1), - [-1111111, -123121, -1221, -11, -1])); + 'test case 4', + () => expect(mergeSort(list3, 0, list3.length - 1), [ + -1111111, + -123121, + -1221, + -11, + -1, + ]), + ); List list4 = [11, 1, 1200, -1, 5]; test( - 'test case 1', - () => - expect(mergeSort(list4, 0, list4.length - 1), [-1, 1, 5, 11, 1200])); + 'test case 1', + () => expect(mergeSort(list4, 0, list4.length - 1), [-1, 1, 5, 11, 1200]), + ); } diff --git a/sort/radix_sort.dart b/sort/radix_sort.dart index 4dc393e1..52d55d45 100644 --- a/sort/radix_sort.dart +++ b/sort/radix_sort.dart @@ -25,13 +25,18 @@ main() { expect(radixSort(lst), equals(lst)); }); test("radix sort", () { - expect(radixSort([34, -2, 122, 24435, 23, 434, 232, 1323]), - equals([-2, 23, 34, 122, 232, 434, 1323, 24435])); + expect( + radixSort([34, -2, 122, 24435, 23, 434, 232, 1323]), + equals([-2, 23, 34, 122, 232, 434, 1323, 24435]), + ); }); final seed = 10, rnd = Random(), length = 10; - var list = - List.generate(length, (i) => rnd.nextInt(seed), growable: false); + var list = List.generate( + length, + (i) => rnd.nextInt(seed), + growable: false, + ); print('before sorting:'); print(list); print('----------------------------------------------'); diff --git a/sort/select_Sort.dart b/sort/select_Sort.dart index dd766542..4a1161a9 100644 --- a/sort/select_Sort.dart +++ b/sort/select_Sort.dart @@ -3,8 +3,11 @@ import 'dart:math' show Random; //main function,the program start void main() { final seed = 100, rnd = Random(), length = 100; - var list = - List.generate(length, (i) => rnd.nextInt(seed), growable: false); + var list = List.generate( + length, + (i) => rnd.nextInt(seed), + growable: false, + ); print('before sorting:'); print(list); print('--------------------------------------'); diff --git a/sort/shell_Sort.dart b/sort/shell_Sort.dart index c4f93cc8..6d5275d1 100644 --- a/sort/shell_Sort.dart +++ b/sort/shell_Sort.dart @@ -2,8 +2,11 @@ import 'dart:math' show Random; void main() { final seed = 100, rnd = Random(), length = 100; - var list = - List.generate(length, (i) => rnd.nextInt(seed), growable: false); + var list = List.generate( + length, + (i) => rnd.nextInt(seed), + growable: false, + ); print('before sorting:'); print(list); print('----------------------------------------------'); diff --git a/strings/knuth_morris_prat.dart b/strings/knuth_morris_prat.dart index 5564ddcb..2841bdb3 100644 --- a/strings/knuth_morris_prat.dart +++ b/strings/knuth_morris_prat.dart @@ -13,8 +13,10 @@ bool stringCompare(String string, String subString) { return false; } - List pattern = - new List.generate(subString.length, (int index) => -1); + List pattern = new List.generate( + subString.length, + (int index) => -1, + ); int i = 1; int j = 0; diff --git a/strings/reverse_words_of_string.dart b/strings/reverse_words_of_string.dart index dfb41f26..4b73b5fc 100644 --- a/strings/reverse_words_of_string.dart +++ b/strings/reverse_words_of_string.dart @@ -34,7 +34,9 @@ void main() { }); test("reverseStringWords", () { - expect(reverseStringWords("abhishek.is.a.good.boy"), - equals("boy.good.a.is.abhishek")); + expect( + reverseStringWords("abhishek.is.a.good.boy"), + equals("boy.good.a.is.abhishek"), + ); }); } diff --git a/trees/path_sum.dart b/trees/path_sum.dart index f5282866..a601ff0e 100644 --- a/trees/path_sum.dart +++ b/trees/path_sum.dart @@ -36,23 +36,8 @@ bool hasPathSum(TreeNode root, int targetSum) { void main() { TreeNode root = TreeNode( 5, - TreeNode( - 4, - TreeNode( - 11, - TreeNode(7), - TreeNode(2), - ), - ), - TreeNode( - 8, - TreeNode(13), - TreeNode( - 4, - null, - TreeNode(1), - ), - ), + TreeNode(4, TreeNode(11, TreeNode(7), TreeNode(2))), + TreeNode(8, TreeNode(13), TreeNode(4, null, TreeNode(1))), ); test('Test Case 1: true case', () {