Skip to content

Instantly share code, notes, and snippets.

View gegen07's full-sized avatar

Germano Barcelos gegen07

View GitHub Profile
@gegen07
gegen07 / np-completeness-reduce-3sat-to-3dm.md
Last active June 15, 2023 22:33 — forked from rcyeh/np-completeness-reduce-3sat-to-3dm.md
Reducing 3-SAT to 3-dimensional matching

Watched Eric Demaine's lecture and initially did not understand the reduction from 3-SAT to 3-dimensional matching.

  1. Complexity: P, NP, NP-completeness, Reductions https://youtu.be/eHZifpgyH_4?t=2786

Goal

To reduce 3-SAT to 3DM, we need to show how to express every 3-SAT problem as a 3DM problem. If 3DM has a solution, then that solution can be applied to solve any 3-SAT problem.

@gegen07
gegen07 / mclp.py
Created October 31, 2021 15:56
plot results function used in JOSS figure
from spopt.locate.coverage import MCLP
mclp = MCLP.from_cost_matrix(
cost_matrix,
ai,
max_coverage=service_dist,
p_facilities=4,
)
mclp = mclp.solve(pulp.GLPK(msg=False))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gegen07
gegen07 / mult_matrix.c
Created November 3, 2019 20:42
This is an algorithm to multiplying two matrix
#include <stdio.h>
int main() {
int matriz[3][3], matriz1[3][3] = {{1, 2, 3}, {2, 3, 1}, {3, 2, 1}}, matriz2[3][3]={{1, 2, 3}, {2, 3, 1}, {3, 2, 1}};
for (int k = 0; k < 3; k++) {
for (int i = 0; i < 3; i++) {
int aux = 0;
for (int j = 0; j < 3; j++) {
aux += matriz1[k][j] * matriz2[j][i];
def hasInverse(det):
return True if det != 0 else False
def det(mat, tam):
detPrim = detSec = 1
for i in range(tam):
for j in range(tam):
if i == j:
detPrim *= mat[i][j]
if i + j == tam - 1:
@gegen07
gegen07 / divNum.py
Created April 18, 2019 13:10
Get all div of a number
fator = 2
n = int(input())
vetor = []
aux = []
while n > 1:
while n % fator == 0:
n /= fator
if len(vetor) > 0:
for i in vetor:
if (fator*i) not in vetor:
@gegen07
gegen07 / pisano.go
Last active December 31, 2018 19:41
A program to append the pisano period into an array
func getPisanoPeriodFast(n int) []int {
var period []int
period = append(period, 0, 1)
var remainder int
for index := 0; index < n*n; index++ {
remainder = (period[index] + period[index+1]) % n
/**
* Copy and Paste this snippet and solve your homework 2.3 of Mongo course for Java Developers.
* Remember to import all libraries before you use.
* This project is handled by Maven so you have to use Maven too with the dependency of MongoJavaDriver
*
* Created By gegen07
*/
public class App {
public static void main( String[] args ) {
MongoClient client = new MongoClient("localhost", 27017);