From fae88187c81a97b0900434e81cfde88dad06eaad Mon Sep 17 00:00:00 2001 From: GRayHook Date: Sun, 2 Apr 2023 13:51:04 +0700 Subject: [PATCH] Init --- .gitignore | 1 + App.java | 34 ++++++++++++++++++++++++++++++++++ Calculations.java | 31 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 .gitignore create mode 100644 App.java create mode 100644 Calculations.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/App.java b/App.java new file mode 100644 index 0000000..6ba57e2 --- /dev/null +++ b/App.java @@ -0,0 +1,34 @@ +public class App { + private static final int WIDTH = 81; + private static final int HEIGHT = 5; + private static char[][] lines; + static { + lines = new char[HEIGHT][WIDTH]; + for (int i = 0; i < HEIGHT; i++) { + for (int j = 0; j < WIDTH; j++) { + lines[i][j] = '*'; + } + } + } + + private static void show(int start, int len, int index) { + int seg = len / 3; + if (seg == 0) return; + for (int i = index; i < HEIGHT; i++) { + for (int j = start + seg; j < start + seg * 2; j++) { + lines[i][j] = ' '; + } + } + show(start, seg, index + 1); + show(start + seg * 2, seg, index + 1); + } + public static void main(String[] args) { + show(0, WIDTH, 1); + for (int i = 0; 1 < HEIGHT; i++) { + for (int j = 0; j < WIDTH; j++) { + System.out.print(lines[i][j]); + } + System.out.println(); + } + } +} diff --git a/Calculations.java b/Calculations.java new file mode 100644 index 0000000..f41f6f0 --- /dev/null +++ b/Calculations.java @@ -0,0 +1,31 @@ +import java.util.function.Predicate; + +public class Calculations { + public static void main(String[] args) { + char[] chars = {'a', 'b', 'c', 'd'}; + // поиск bba + calculate(chars, 3, i -> i[0] == 1 && i[1] == 1 && i[2] == 0); + } + static void calculate(char[] a, int k, Predicate decider) { + int n = a.length; + if (k < 1 || k > n) + throw new IllegalArgumentException("Forbidden"); + int[] indexes = new int[n]; + int total = (int) Math.pow(n, k); + while (total-- > 0) { + for (int i = 0; i < n - (n - k) ; i++) + System.out.print(a[indexes[i]]); + System.out.println(); + if (decider.test(indexes) ) + break; + for (int i=0; i < n; i++) { + if (indexes[i] >= n - 1) { + indexes[i] = 0; + } else { + indexes[i]++; + break; + } + } + } + } +}