Skip to content

Instantly share code, notes, and snippets.

@robertcampion
robertcampion / ortools_ilp_example.py
Created January 16, 2023 01:04
OR-Tools integer linear programming example (Python)
# code to solve the problem described in https://codereview.stackexchange.com/q/282605/209865
# based on https://developers.google.com/optimization/cp/cp_example
from ortools.sat.python import cp_model
from itertools import product
variable_names = list('abcdef')
coefficients = [-42, 75, -30, 80, 25, 50]
upper_bound = 150
@robertcampion
robertcampion / solution.txt
Created October 25, 2022 01:12
Solutions to [Reviving the Ruins of Number Kingdom](https://puzzling.stackexchange.com/q/118454)
1. sf
2. f
3. c
4. c!!ssf!ssc
5. c!!ssf
6. c!
7. c!!ssf!sf!s3c
8. c!!ssf!sf!s3c!ssf
9. c!!ssf!sf!s3c!ssc
10. c!!ssf!sf
# https://puzzling.stackexchange.com/questions/111833/ernie-and-the-equi-area-tetrahedra
# coordinates of vertices
var x[{1..4}] >= -1 <= 1;
var y[{1..4}] >= -1 <= 1;
var z[{1..4}] >= -1 <= 1;
# squared area of each face
var a_sq[{1..4}];
# cross product for face areas
import z3
N = 8 # number of athletes
M = 3 # number of medals
R = 3 # number of rounds
solver = z3.Solver()
# rank[i][r] is the rank of athlete i in round r
# ... except in the last round, where athlete i currently ranks (i+1)st
from scipy.spatial import Voronoi, Delaunay
from scipy import optimize
import matplotlib.pyplot as plt
import numpy as np
from numpy.linalg import norm
from itertools import islice
from time import time
from multiprocessing import Process, Queue
from queue import Empty
[
((0,3.89771),-0.607492),
((3.89771,7.79542),-0.601695),
((7.79542,11.6931),-0.595723),
((11.6931,15.5908),-0.589687),
((15.5908,19.4885),-0.58344),
((19.4885,23.3862),-0.577019),
((23.3862,27.284),-0.570459),
((27.284,31.1817),-0.563693),
((31.1817,35.0794),-0.556756),
JPEGsnoop 1.7.5 by Calvin Hass
http://www.impulseadventure.com/photo/
-------------------------------------
Filename: [C:\...\cw-ccw-random.jpg]
Filesize: [222467] Bytes
Start Offset: 0x00000000
*** Marker: SOI (xFFD8) ***
JPEGsnoop 1.7.5 by Calvin Hass
http://www.impulseadventure.com/photo/
-------------------------------------
Filename: [C:\..\jpeg-rotate-test\cw.jpg]
Filesize: [23645] Bytes
Start Offset: 0x00000000
*** Marker: SOI (xFFD8) ***
aaaaaaa
aaaaaaa
aaaacaa
aaaayaa
aaacaaa
aaacyaa
aaayaaa
aaaycaa
acaaaca
acaayca
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xxx.xxxx.....xxx...xx....xx.xxxxx..x.xx
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xxx.xxxx.....xxx...xx....xx.xxxxx...xx.
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xxx.xxxx.....xxx...xx....xx.xxxxx...x.x
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xxx.xxxx.....xxx...xx....x.xx.xxx..xxx.
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xxx.xxxx.....xxx...xx....x.xx.xxx..xx.x
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xxx.xxxx.....xxx...xx....x.x.xxxx..xxxx
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xx.x.xxx.....xxxx..xx....xx.x.xxx..x.xx
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xx.x.xxx.....xxxx..xx....xx.x.xxx...xx.
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xx.x.xxx.....xxxx..xx....xx.x.xxx...x.x
xxxxxxxx.xx.xx...x..xx...x.x.xx.x..xxxxx...xx..x.xx......xx.x.xxx.....xxxx..xx....xx..xxxx...xxx