Created
October 27, 2020 07:04
-
-
Save malkia/deddbbcf9556447c0c7c3c0e78626b23 to your computer and use it in GitHub Desktop.
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'; | |
import 'dart:io'; | |
var random = Random(); | |
List<int> makeRandom(int n) { | |
var x = List<int>(n); | |
for (int i = 0; i < n; i++) { | |
x[i] = random.nextInt(n * 10); | |
} | |
return x; | |
} | |
List<int> makeDiff(List<int> nums) { | |
var n = nums.length; | |
var xx = List<int>(n * n); | |
for (int j = 1; j < n; j++) { | |
for (int i = 0; i < n && i + j < n; i++) { | |
xx[j * n + i + j - 1] = nums[i + j] - nums[i]; | |
} | |
} | |
return xx; | |
} | |
void main() { | |
var n = 30; | |
var nums = makeRandom(n); | |
nums.sort(); | |
for (int k = 0; k < 2; k++) { | |
var n1 = random.nextInt(n); | |
var n2 = random.nextInt(n); | |
var v1 = nums[n1]; | |
var v2 = nums[n2]; | |
nums[n1] = v2; | |
nums[n2] = v1; | |
} | |
//nums.shuffle(); | |
var nums2 = makeDiff(nums); | |
for (int i = 0; i < n; i++) { | |
var num = nums[i]; | |
var snum = num.toString().padLeft(5); | |
stdout.write(snum); | |
} | |
print(""); | |
for (int j = 1; j < n; j++) { | |
for (int i = 0; i < n; i++) { | |
var num = nums2[j * n + i]; | |
var snum = (num != null) ? (num >= 0 ? num.toString() : '___') : '****'; | |
snum = snum.padLeft(5); | |
stdout.write(snum); | |
} | |
stdout.write('\n'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment