sonstiges
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| sonstiges [2024/08/22 12:59] – [Ärzte] lutz | sonstiges [2026/04/29 09:49] (aktuell) – [SQL] lutz | ||
|---|---|---|---|
| Zeile 8: | Zeile 8: | ||
| Tel +49 221 508887 | Tel +49 221 508887 | ||
| Fax +49 221 80064591 | Fax +49 221 80064591 | ||
| - | | + | |
| Praxis Gerald S. Langner | Praxis Gerald S. Langner | ||
| Facharzt für Kinder- und Jugendpsychiatrie und Psychotherapie | Facharzt für Kinder- und Jugendpsychiatrie und Psychotherapie | ||
| Zeile 41: | Zeile 41: | ||
| ^ Freitag | ^ Freitag | ||
| - | https:// | + | |
| ===== Syntaxhighlighting ===== | ===== Syntaxhighlighting ===== | ||
| - | <sxh css> | + | <codeprism lang=css> |
| @media (max-width: 664px) { | @media (max-width: 664px) { | ||
| .wp-block-group: | .wp-block-group: | ||
| Zeile 50: | Zeile 50: | ||
| } | } | ||
| } | } | ||
| - | </sxh> | + | </codeprism> |
| ==== SQL ==== | ==== SQL ==== | ||
| Zeile 65: | Zeile 65: | ||
| ==== Visual Basic ==== | ==== Visual Basic ==== | ||
| - | <sxh vb> | + | <codeprism lang=vb> |
| Case " | Case " | ||
| Filename = CreatingFilename(pRow(" | Filename = CreatingFilename(pRow(" | ||
| Zeile 85: | Zeile 85: | ||
| OutputFile.Export(pRow, | OutputFile.Export(pRow, | ||
| End If | End If | ||
| - | </sxh> | + | </codeprism> |
| ==== C# ==== | ==== C# ==== | ||
| - | <sxh csharp> | + | <codeprism lang=cs> |
| if (posibleCustomerIds.Count < 1) | if (posibleCustomerIds.Count < 1) | ||
| { | { | ||
| Zeile 100: | Zeile 100: | ||
| } ... | } ... | ||
| } | } | ||
| - | </sxh> | + | </codeprism> |
| + | |||
| + | ==== Python ==== | ||
| + | < | ||
| + | |||
| + | class ShikakuSolver: | ||
| + | def __init__(self, | ||
| + | self.width = dimension[0] | ||
| + | self.height = dimension[1] | ||
| + | self.rows = 0 | ||
| + | self.values = defaultdict(int) | ||
| + | self.grid = defaultdict(list) | ||
| + | self.solution = defaultdict(dict) | ||
| + | self.solutions = list() | ||
| + | self.requirements = list() | ||
| + | self.actions = defaultdict(list) | ||
| + | self.names = " | ||
| + | self.id = 0 | ||
| + | |||
| + | def add_row(self, | ||
| + | for i, value in enumerate(row): | ||
| + | self.grid[self.rows].append(value) | ||
| + | self.requirements.append((' | ||
| + | if value > 0: | ||
| + | self.values[(self.rows, | ||
| + | self.requirements.append((' | ||
| + | self.rows += 1 | ||
| + | if self.rows == self.height: | ||
| + | self.set_shapes() | ||
| + | |||
| + | def set_shapes(self): | ||
| + | for p in self.values.keys(): | ||
| + | r = p[0] | ||
| + | c = p[1] | ||
| + | n = self.values[(r, | ||
| + | i = 1 | ||
| + | shapes = set() | ||
| + | while i <= n: | ||
| + | if n % i == 0 and i <= self.height and n // i <= self.width: | ||
| + | shapes.add((i, | ||
| + | i += 1 | ||
| + | for shape in shapes: | ||
| + | h = shape[0] | ||
| + | w = shape[1] | ||
| + | self.place_shape(r, | ||
| + | |||
| + | def place_shape(self, | ||
| + | r0 = rn - h if rn - h > 0 else 0 | ||
| + | c0 = cn - w if cn - w > 0 else 0 | ||
| + | for r in range(r0, rn + 1): | ||
| + | for c in range(c0, cn + 1): | ||
| + | cells = self.check_rectangle(r, | ||
| + | if r + h <= self.height and c + w <= self.width and cells != None: | ||
| + | self.actions[(' | ||
| + | |||
| + | def check_rectangle(self, | ||
| + | value_included = False | ||
| + | cells = list() | ||
| + | for r in range(r0, r0 + h): | ||
| + | for c in range(c0, c0 + w): | ||
| + | cells.append((' | ||
| + | if r == rn and c == cn: | ||
| + | value_included = True | ||
| + | elif (r, c) in self.values.keys(): | ||
| + | return None | ||
| + | if value_included: | ||
| + | return cells | ||
| + | return None | ||
| + | |||
| + | def get_solutions(self): | ||
| + | solver = AlgorithmXSolver(self.requirements, | ||
| + | for solution in solver.solve(): | ||
| + | self.solution.clear() | ||
| + | self.id = 0 | ||
| + | for i, action in enumerate(sorted(solution)): | ||
| + | self.set_rectangle(action) | ||
| + | self.id += 1 | ||
| + | self.solutions.append(self.solution) | ||
| + | #break | ||
| + | print(solver.solution_count) | ||
| + | return self.solutions | ||
| + | |||
| + | def set_rectangle(self, | ||
| + | _, row, col, width, height = action | ||
| + | value = self.names[self.id] | ||
| + | # | ||
| + | for r in range(row, row + height): | ||
| + | for c in range(col, col + width): | ||
| + | # | ||
| + | self.solution[r][c] = value | ||
| + | |||
| + | def print_grid(self): | ||
| + | output = " | ||
| + | for r in range(self.height): | ||
| + | output += " | ||
| + | for c in range(self.width): | ||
| + | output += " | ||
| + | print(output) | ||
| + | print(" | ||
| + | |||
| + | # Test the first simple grids: | ||
| + | for riddle in riddles: | ||
| + | solver = ShikakuSolver(riddle[0]) | ||
| + | for i in range(riddle[0][1]): | ||
| + | solver.add_row(riddle[i + 1]) | ||
| + | solver.print_grid() | ||
| + | # | ||
| + | solutions = solver.get_solutions().sort() | ||
| + | solution = solutions[0] | ||
| + | for r in range(riddle[0][1]): | ||
| + | row = "" | ||
| + | for c in range(riddle[0][0]): | ||
| + | row += solution[r][c] | ||
| + | print(row) | ||
| + | </ | ||
| ==== XML ==== | ==== XML ==== | ||
| - | <sxh xml> | + | <codeprism lang=xml> |
| <?xml version=" | <?xml version=" | ||
| < | < | ||
| Zeile 151: | Zeile 265: | ||
| </ | </ | ||
| </ | </ | ||
| - | </sxh> | + | </codeprism> |
| ==== SMTP ==== | ==== SMTP ==== | ||
| <code email> | <code email> | ||
sonstiges.1724331565.txt.gz · Zuletzt geändert: von lutz