Best Python code snippet using pandera_python
nonogram_table_sat.py
Source:nonogram_table_sat.py
1# Copyright 2021 Hakan Kjellerstrand hakank@gmail.com2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""15 Nonogram (Painting by numbers) in OR-tools CP-SAT Solver.16 http://en.wikipedia.org/wiki/Nonogram17 '''18 Nonograms or Paint by Numbers are picture logic puzzles in which cells in a19 grid have to be colored or left blank according to numbers given at the20 side of the grid to reveal a hidden picture. In this puzzle type, the21 numbers measure how many unbroken lines of filled-in squares there are22 in any given row or column. For example, a clue of '4 8 3' would mean23 there are sets of four, eight, and three filled squares, in that order,24 with at least one blank square between successive groups.25 '''26 See problem 12 at http://www.csplib.org/.27 http://www.puzzlemuseum.com/nonogram.htm28 Haskell solution:29 http://twan.home.fmf.nl/blog/haskell/Nonograms.details30 Brunetti, Sara & Daurat, Alain (2003)31 'An algorithm reconstructing convex lattice sets'32 http://geodisi.u-strasbg.fr/~daurat/papiers/tomoqconv.pdf33 The Comet model (http://www.hakank.org/comet/nonogram_regular.co)34 was a major influence when writing this model.35 I have also blogged about the development of a Nonogram solver in Comet36 using the regular constraint.37 * 'Comet: Nonogram improved: solving problem P200 from 1:30 minutes38 to about 1 second'39 http://www.hakank.org/constraint_programming_blog/2009/03/comet_nonogram_improved_solvin_1.html40 * 'Comet: regular constraint, a much faster Nonogram with the regular41 constraint,42 some OPL models, and more'43 http://www.hakank.org/constraint_programming_blog/2009/02/comet_regular_constraint_a_muc_1.html44 This is a port of my old CP model nonogram_table.py45 The old CP model nonogram_regular.py was almost identical to nonogram_table.py,46 with the difference that it used the `regular_element` instead of `regular_table`.47 This model incorporates selection of these constraints via the second 48 argument of the program, e.g.:49 $ python3 nonogram_table_sat.py nonogram_pbn_merka.py regular_element50 $ python3 nonogram_table_sat.py nonogram_pbn_merka.py regular_table51 The default is to use regular_table which seems to be quite faster than52 regular_element.53 Note: All methods are defined in nonogram_utils_sat.py54 This model was created by Hakan Kjellerstrand (hakank@gmail.com)55 Also see my other OR-tools models: http://www.hakank.org/or_tools/56"""57from __future__ import print_function58from ortools.sat.python import cp_model as cp59import math, sys60from cp_sat_utils import regular_table, regular_element61from nonogram_utils_sat import SolutionPrinter, make_transition_matrix, check_rule, run_nonogram62def main(rows, row_rule_len, row_rules, cols, col_rule_len, col_rules, regular_method):63 run_nonogram(rows, row_rule_len, row_rules, cols, col_rule_len, col_rules, regular_method)64#65# Default problem66#67# From http://twan.home.fmf.nl/blog/haskell/Nonograms.details68# The lambda picture69#70rows = 1271row_rule_len = 372row_rules = [[0, 0, 2], [0, 1, 2], [0, 1, 1], [0, 0, 2], [0, 0, 1], [0, 0, 3],73 [0, 0, 3], [0, 2, 2], [0, 2, 1], [2, 2, 1], [0, 2, 3], [0, 2, 2]]74cols = 1075col_rule_len = 276col_rules = [[2, 1], [1, 3], [2, 4], [3, 4], [0, 4], [0, 3], [0, 3], [0, 3],77 [0, 2], [0, 2]]78regular_method = "regular_table"79if __name__ == '__main__':80 if len(sys.argv) > 1:81 file = sys.argv[1]82 # If one accidentally forgot to add a file83 # as first argument.84 if file in ["regular","regular_table"]:85 regular_method = file86 else:87 exec(compile(open(file).read(), file, 'exec'))88 if len(sys.argv) > 2:89 m = sys.argv[2]90 if m in ["regular","regular_table"]:91 regular_method = m92 print(f"Using regular method `{regular_method}`.")...
class_method_types.py
Source:class_method_types.py
...17 @staticmethod18 def static_method():19 """ Can be called on either TestClass class for TestClass() instance. Has no access to class or instance attributes """20 print(">>static_method (no instance or class attrs)")21 def regular_method():22 """ Can only be called on either TestClass class. Has no access to class or instance attributes.23 (Seems identicial to static_method() but cannot be called on instance)24 25 """26 print(">>regular_method (no instance or class attrs)")27if __name__ == '__main__':28 TestClass.static_method()29 TestClass.class_method()30 TestClass.regular_method()31 32 # Calling TestClass.instance_method() raises TypeError33 # >>> TestClass.instance_method()34 # Traceback (most recent call last):35 # File "<stdin>", line 1, in <module>36 # TypeError: instance_method() missing 1 required positional argument: 'self'37 tc = TestClass( {"data-scope": "instance"} )38 tc.instance_method()39 tc.class_method()40 tc.static_method()41 42 # Calling tc.regular_method raise TypeError43 # >>> tc = TestClass()44 # >>> tc.regular_method()45 # Traceback (most recent call last):46 # File "<stdin>", line 1, in <module>...
Using_metaclass_to_inherit_type.py
Source:Using_metaclass_to_inherit_type.py
...7class MyRegularClass(object, metaclass=MyMetaClass): # 'object' is redundant8 def __init__(self, num, denom):9 self.numerator = num10 self.denominator = denom11 def regular_method(self):12 return self.numerator / float(self.denominator)13 def __repr__(self): # __repr__ is more for developer use14 return "Regular class __repr__ method"15 def __str__(self): # __str__ is for end-user use16 return "Regular class __str__ method"17def example():18 # Â Creating an instance of MyRegularClass:19 f = MyRegularClass(1, 3)20 # Printing different attributes:21 print(type(f)) # Prints meta-class type22 print(f) # Prints __str__ method23 print(repr(f)) # Prints __repr__ method24 print(f.numerator) # Prints class attribute 'numerator'25 print(f.regular_method()) # Prints the return of 'regular_method'26 print(type(f.regular_method())) # Prints type of the return27example()28# if __name__ == "__main__":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!