ryanbhayward / algs Goto Github PK
View Code? Open in Web Editor NEWpython algorithms for CMPUT 204 and 304
python algorithms for CMPUT 204 and 304
When stepping through the program for the sake of my own understanding, I came across a nasty bug in the fix_literal()
method in backsat.py.
The problem is on these lines:
Lines 44 to 51 in 38b5341
Essentially, there is a for loop iterating on a list whose order is modified during the for loop. In some cases this doesn't cause any problems but is generally considered bad practice. Python's for x in y
loop syntax uses indexing in the background, so removing an element might shift a further unseen element to an index for which Python has explored already.
Specifically, when there are two elements side by side in the list, that both match the removal condition, the first one will be removed and the second one will be skipped. Running the following input to the function:
f = [[1, 4, -5], [1, 3, -4], [2, -3, -4], [3, 4, 5]]
fix_literal(1, f, '?????')
produces the following result:
[[1, 3, -4], [2, -3, -4], [3, 4, 5]]
instead of the expected result:
[[2, -3, -4], [3, 4, 5]]
I'm not exactly sure what issues this might cause when the broader program is considered, as I have not analyzed it to that extent at the moment. I would imagine some valid satisfying assignments are thrown out because of this bug, though I haven't confirmed this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.