Webseiten-Werkzeuge


sonstiges

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
sonstiges [2025/02/19 13:14] – [C#] lutzsonstiges [2026/04/29 09:49] (aktuell) – [SQL] lutz
Zeile 44: Zeile 44:
  
 ===== Syntaxhighlighting ===== ===== Syntaxhighlighting =====
-<sxh css>+<codeprism lang=css>
 @media (max-width: 664px) { @media (max-width: 664px) {
  .wp-block-group:not(.alignfull):not(.alignwide) > .wp-block-group__inner-container > * {  .wp-block-group:not(.alignfull):not(.alignwide) > .wp-block-group__inner-container > * {
Zeile 50: Zeile 50:
  }  }
 } }
-</sxh>+</codeprism>
  
 ==== SQL ==== ==== SQL ====
Zeile 65: Zeile 65:
  
 ==== Visual Basic ==== ==== Visual Basic ====
-<sxh vb>+<codeprism lang=vb>
 Case "PROSKURNIN", "CAMES", "INTERTABAK", "MACK", "SZZ", "BRUECK" Case "PROSKURNIN", "CAMES", "INTERTABAK", "MACK", "SZZ", "BRUECK"
     Filename = CreatingFilename(pRow("LocalFilePath").ToString, pRow("LocalFilePrefix").ToString, strTakeorderNumber, "CSV")     Filename = CreatingFilename(pRow("LocalFilePath").ToString, pRow("LocalFilePrefix").ToString, strTakeorderNumber, "CSV")
Zeile 85: Zeile 85:
         OutputFile.Export(pRow, strTakeorderNumber, OriginOfOrder, relation)         OutputFile.Export(pRow, strTakeorderNumber, OriginOfOrder, relation)
     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 ==== ==== Python ====
-<sxh py> +<codeprism lang=py>
-import sys +
-import math +
-from collections import defaultdict +
-from AlgorithmX import AlgorithmXSolver+
  
-class LatinSquare+class ShikakuSolver
-    possible_values = list() +    def __init__(self, dimension): 
-    multiple_solutions bool +        self.width dimension[0] 
-    empty_value str +        self.height dimension[1] 
-    size int +        self.rows 0 
-    box_size = int +        self.values defaultdict(int) 
-    grid = defaultdict(list)+        self.grid = defaultdict(list) 
 +        self.solution = defaultdict(dict) 
 +        self.solutions = list() 
 +        self.requirements = list() 
 +        self.actions = defaultdict(list) 
 +        self.names = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 
 +        self.id = 0
  
-    def __init__(self, all_possible_values, multiple_solutions_possible = False): +    def add_row(self, row): 
-        self.empty_value = all_possible_values[0] +        for i, value in enumerate(row): 
-        self.possible_values = all_possible_values[1:] +            self.grid[self.rows].append(value) 
-        self.multiple_solutions = multiple_solutions_possible +            self.requirements.append(('cell covered', self.rows, i)
-        self.size = len(self.possible_values+            if value > 0: 
-        #print("Empty={}, Values={}, Size={}".format(self.empty_value, self.possible_values, self.size)file=sys.stderr, flush=True)+                self.values[(self.rowsi)] = value 
 +                self.requirements.append(('value covered', self.rowsi)) 
 +        self.rows +
 +        if self.rows == self.height: 
 +            self.set_shapes()
  
-    def add_row(self, new_row): +    def set_shapes(self): 
-        i = len(self.grid) // self.size +        for p in self.values.keys(): 
-        row = list(new_row) +            r = p[0] 
-        for j in range(self.size): +            c p[1] 
-            if row[j] == self.empty_value: +            n = self.values[(rc)] 
-                self.grid[(ij)] = self.possible_values +            i 1 
-            else+            shapes = set() 
-                self.grid[(i, j)] = [row[j]]+            while i <= n
 +                if n % i == 0 and i <= self.height and n // i <= self.width: 
 +                    shapes.add((i, n // i)
 +                i += 1 
 +            for shape in shapes: 
 +                h = shape[0] 
 +                w shape[1] 
 +                self.place_shape(r, c, w, h)
  
-    def get_requirements(self): +    def place_shape(self, rn, cn, w, h): 
-        return [('cell covered', row, col) for row in range(self.size) for col in range(self.size)\ +        r0 = rn - h if rn - h > 0 else 0 
-               [('value in row', rowvalfor row in range(self.size) for val in self.possible_values+ \ +        c0 = cn - w if cn - w > 0 else 0 
-               [('value in col', colvalfor col in range(self.size) for val in self.possible_values]+        for in range(r0, rn + 1)
 +            for in range(c0, cn + 1): 
 +                cells = self.check_rectangle(r, c, w, h, rn, cn) 
 +                if r + h <= self.height and c w <= self.width and cells != None: 
 +                    self.actions[('set rectangle', rc, w, h)] [('value covered', rncn), *cells]
  
-    def get_actions(self): +    def check_rectangle(self, r0, c0, w, h, rn, cn): 
-        actions dict() +        value_included = False 
-        for row in range(self.size): +        cells list() 
-            for col in range(self.size): +        for in range(r0, r0 + h): 
-                for val in self.grid[(row, col)]: +            for in range(c0, c0 + w): 
-                    action = ('place value', rowcol, val+                cells.append(('cell covered', rc)) 
-                    actions[action] [('cell covered', row, col), +                if r == rn and c == cn: 
-                                    ('value in row', rowval)+                    value_included True 
-                                    ('value in col', col, val)] +                elif (rc) in self.values.keys()
-        return actions+                    return None 
 +        if value_included: 
 +            return cells 
 +        return None
  
-    def get_solution(self): +    def get_solutions(self): 
-        solver = AlgorithmXSolver(self.get_requirements(), self.get_actions()) +        solver = AlgorithmXSolver(self.requirements, self.actions)
-        result = defaultdict(dict)+
         for solution in solver.solve():         for solution in solver.solve():
-            for action in solution: +            self.solution.clear() 
-                _, row, col, val = action +            self.id = 0 
-                result[row][col] val +            for i, action in enumerate(sorted(solution))
-            if not self.multiple_solutions: +                self.set_rectangle(action) 
-                break +                self.id +1 
-        return result+            self.solutions.append(self.solution) 
 +            #break 
 +        print(solver.solution_count) 
 +        return self.solutions
  
-    def get_solution_count(self): +    def set_rectangle(self, action): 
-        #print("Grid={}".format(self.grid)file=sys.stderrflush=True) +        _rowcol, width, height action 
-        solver AlgorithmXSolver(self.get_requirements(), self.get_actions()+        value = self.names[self.id] 
-        for solution in solver.solve(): +        #print(self.names[i], row, col, width, height
-            pass +        for in range(row, row + height): 
-        return solver.solution_count+            for c in range(col, col + width): 
 +                #print("({}|{})={}".format(r, c, value)) 
 +                self.solution[r][c] = value
  
-    def print_solution(self): +    def print_grid(self): 
-        result = self.get_solution() +        output "--"self.width + "-" 
-        for row in range(self.size): +        for in range(self.height): 
-            print("".join(result[row][colfor col in range(self.size)))+            output += "\n" 
 +            for c in range(self.width): 
 +                output += "{:2d}".format(self.grid[r][c]
 +        print(output) 
 +        print("--"self.width + "-")
  
-Name all values, including the first one, that marks an empty cell +Test the first simple grids: 
-#all_possible_values = "0123456789" +for riddle in riddles: 
-all_possible_values list("0123456789"+    solver ShikakuSolver(riddle[0]) 
-n = 4 +    for i in range(riddle[0][1]): 
-square = LatinSquare(all_possible_values[:n-9], True+        solver.add_row(riddle[i + 1]
- +    solver.print_grid() 
-#for i in range(len(all_possible_values) - 1): +    #print(solver.actions
-#    sudoku_solver.add_row(input()+    solutions = solver.get_solutions().sort() 
-square.add_row("0000"+    solution = solutions[0] 
-square.add_row("0000"+    for r in range(riddle[0][1]): 
-square.add_row("0000") +        row = "" 
-square.add_row("0000"+        for c in range(riddle[0][0])
- +            row += solution[r][c] 
-print("The number of possible solutions is {}".format(square.get_solution_count())+        print(row
-</sxh>+</codeprism>
 ==== XML ==== ==== XML ====
-<sxh xml>+<codeprism lang=xml>
 <?xml version="1.0" encoding="iso-8859-15"?> <?xml version="1.0" encoding="iso-8859-15"?>
 <Auftrag> <Auftrag>
Zeile 237: Zeile 265:
   </Positionen>   </Positionen>
 </Auftrag> </Auftrag>
-</sxh>+</codeprism>
 ==== SMTP ==== ==== SMTP ====
 <code email> <code email>
sonstiges.1739970876.txt.gz · Zuletzt geändert: von lutz