Giter Site home page Giter Site logo

solutiontable's Introduction

SolutionTable Unlicensed work

wheel (GitLab) wheel (GHA via nightly.link) GitLab Build Status GitLab Coverage GitHub Actions Libraries.io Status Code style: antiflash

We have moved to https://codeberg.org/KOLANICH-libs/SolutionTable.py, grab new versions there.

Under the disguise of "better security" Micro$oft-owned GitHub has discriminated users of 1FA passwords while having commercial interest in success and wide adoption of FIDO 1FA specifications and Windows Hello implementation which it promotes as a replacement for passwords. It will result in dire consequencies and is competely inacceptable, read why.

If you don't want to participate in harming yourself, it is recommended to follow the lead and migrate somewhere away of GitHub and Micro$oft. Here is the list of alternatives and rationales to do it. If they delete the discussion, there are certain well-known places where you can get a copy of it. Read why you should also leave GitHub.


This library was initially written in 2013 for analyzing Mafia/Werewolf games but it is suitable to solving problems. it has 3 main methods:

  • .init([one set],[another set]) - initializes table columns and rows
  • .aIsNotB("element of the first set","element of the second set") - used when it is known that 2 elements differ
  • .removePairAndResolve(name1, name2) - used when it is known that 2 elements are equal

Look the examples (the problems were taken from http://mmmf.msu.ru/archive/20052006/z5/11.html) .

Problem 1 - Clowns

The three clown: Bim, Bom and Bam act in green, red and blue shirts. Their shoes are of the same colors. Colors of Bim's shoes and shirt match. Neither Bom's shirt, nor shoes are red. Bam wears green shoes and a shirt of a different color. How are the clowns dressed? (All the clowns wear different shirts and different shoes).

var a = new SolutionTable();
var shoes={}, shirts={};
a.onResolved.push(console.info);
a.onResolved.push(function(v){for(let n in v) shoes[n]=v[n];});

// prbs/clowns_shoes.prb
a.init(["Bim","Bom","Bam"],["r","g","b"]);
a.isNot("Bom","r");  // Neither Bom's shirt, nor **shoes are red**.
a.equal("Bam","g");  // Bam wears green shoes

a.onResolved[a.onResolved.length-1]=(function(v){for(let n in v) shirts[n]=v[n];});
a.init(["Bim", "Bom", "Bam"],["r", "g", "b"]);
a.isNot("Bom", "r");//**Neither Bom's shirt**, nor shoes **are red**.
a.isNot("Bam", "g");//Bam wears green shoes
a.equal("Bim", shoes["Bim"]);//Colors of Bim's shoes and shirt match.
console.log(shoes,shirts);

Problem 2 - Plant

One plant employs three friends: turner, fitter and welder. Their surnames are Borisov, Ivanov and Semenov. The fitter has neither brothers, nor sisters. He is the youngest of the friends. Semenov is married to Borisov's sister and he is older than the turner. Match the surnames to the occupations.

var a = new SolutionTable();
a.onResolved.push(console.info);
// prbs/plant.prb
a.init(["turner", "fitter", "welder"], ["Borisov", "Ivanov", "Semenov"]);
a.isNot("fitter","Borisov"); // fitter has no sisters, Borisov has
a.isNot("turner","Semenov"); // Semenov is older than the turner
a.isNot("fitter", "Semenov"); // fitter is the youngest, Semenov is older than someone
console.log(a.hash1,a.hash2);

Initially this was developed to reveal roles from mafia game log

var a = new SolutionTable();
a.onResolved.push(console.info);
a.init(["maniac", "maf", "doc", "psy"], ["Paul", "Vlad", "Nick", "Paul"]);
var alone = a.equal("doc", "Paul"); // we know he is doc
var alone = a.equal("maniac", "Paul"); // you need to be careful - no checks are implemented, so this will delete maniac column though Paul cannot be a maniac and this can be seen from the table.
console.log(alone,a.hash1,a.hash2);

// prbs/mafia_2.prb
a.init(["maniac", "maf", "doc", "psy"],["Paul", "Vlad", "Nick", "Paul"]);
var alone = a.isNot("doc", "Paul");
var alone = a.isNot("maniac", "Paul");
var alone = a.isNot("maniac", "Vlad");
var alone = a.isNot("psy", "Vlad");
var alone = a.isNot("psy", "Nick");
var alone = a.isNot("maniac", "Nick");
console.log(alone, a.hash1, a.hash2);

Python

This repo also contains some python classes. They are not finished yet.

  • SolutionTable.py contains my try to implement the same as in SolutionTable.js, but using Bayessian approach.
  • prbs contains machine-readable problems in a form of *.prb files. You need prb.py to read them. You can also open them with Logic Problem Solver by Gary Darby. The archives with the tool contain quite some pre-formalized examples, that may be used in future to test this library.

solutiontable's People

Contributors

kolanich avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.