paranid5

12 28.11

Nov 28th, 2021
640
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ignore_for_file: unused_element
  2.  
  3. extension on int {
  4.   List<int> getDivs(final bool Function(int) predicate) {
  5.     final divs = List<int>.empty(growable: true);
  6.  
  7.     for (int i = 1; i * i <= this; i++) {
  8.       if (this % i == 0) {
  9.         if (predicate(i)) {
  10.           divs.add(i);
  11.         }
  12.  
  13.         if (i * i < this && predicate(this ~/ i)) {
  14.           divs.add(this ~/ i);
  15.         }
  16.       }
  17.     }
  18.  
  19.     return divs;
  20.   }
  21.  
  22.   bool get isSimple {
  23.     for (int i = 2; i * i <= this; i++) {
  24.       if (this % i == 0) {
  25.         return false;
  26.       }
  27.     }
  28.  
  29.     return true;
  30.   }
  31.  
  32.   bool get isUnique {
  33.     final s = toString();
  34.  
  35.     if (s.length < 5) {
  36.       return false;
  37.     }
  38.  
  39.     final nums = s.codeUnits.map((e) => e - '0'.codeUnitAt(0)).toList();
  40.  
  41.     if (nums[2] % 2 != 0 || nums[4] % 2 != 0) {
  42.       return false;
  43.     }
  44.  
  45.     return nums
  46.         .filterIndexed((ind, x) => ind != 2 && ind != 4)
  47.         .every((element) => element % 2 == 1);
  48.   }
  49. }
  50.  
  51. extension on List<int> {
  52.   List<int> sortAndGet([int Function(int, int)? compare]) {
  53.     sort(compare);
  54.     return this;
  55.   }
  56. }
  57.  
  58. extension IntIterableExt on Iterable<int> {
  59.   static Iterable<int> createRange(final int startInclusive, final int endExclusive) =>
  60.       Iterable.generate(endExclusive - startInclusive + 1, (x) => x + startInclusive);
  61.  
  62.   int get sum => fold(0, (previousValue, element) => previousValue + element);
  63. }
  64.  
  65. extension IterableExt<T> on Iterable<T> {
  66.   Iterable<T> withStep(final int step) {
  67.     final list = List<T>.empty(growable: true);
  68.     final thisList = toList();
  69.  
  70.     for (int i = 0; i < length; i += step) {
  71.       list.add(thisList[i]);
  72.     }
  73.  
  74.     return list;
  75.   }
  76.  
  77.   void forEachIndexed(void Function(int, T) action) {
  78.     final iter = iterator;
  79.  
  80.     for (int i = 0; i < length; i++) {
  81.       iter.moveNext();
  82.       action(i, iter.current);
  83.     }
  84.   }
  85.  
  86.   Iterable<T> filterIndexed(bool Function(int, T) predicate) {
  87.     final list = List<T>.empty(growable: true);
  88.     final thisList = toList();
  89.  
  90.     for (int i = 0; i < length; i++) {
  91.       final elem = thisList[i];
  92.       if (predicate(i, elem)) {
  93.         list.add(elem);
  94.       }
  95.     }
  96.  
  97.     return list;
  98.   }
  99. }
  100.  
  101. class Pair<F, S> {
  102.   F first;
  103.   S second;
  104.   Pair(this.first, this.second);
  105. }
  106.  
  107. void main(final List<String> arguments) {
  108.   final divsNotMatch = List.generate(3, (index) => index + 6);
  109.  
  110.   final filter = IntIterableExt
  111.       .createRange(33333, 55555)
  112.       .where((element) => divsNotMatch.every((e) => element % e != 0) && element.isUnique)
  113.       .toList();
  114.  
  115.   print(filter.length);
  116.   filter.sort();
  117.   print(filter.last - filter.first);
  118. }
  119.  
RAW Paste Data