This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sentient -c -o -r -n 0 -m lingeling magic_square_7_of_8.snt | |
# Based on: https://twitter.com/standupmaths/status/1214921447644250113 | |
# Written in Sentient: https://sentient-lang.org/ | |
function main() { | |
int12 a, b, c, d, e, f, g, h, i; | |
# Needs to be: ceil(log2((2^(bits - 1))^2 * 3)) + 1 | |
int25 magicSum; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NUMBER_OF_BANDITS = 4 | |
EPSILON = 0.001 | |
VALUES_AND_OCCURENCES = NUMBER_OF_BANDITS.times.map { [0, 0] } | |
def greedy_action | |
VALUES_AND_OCCURENCES.map.with_index { |(v, o), i| [v, o, i] }.max_by(&:first).last | |
end | |
def random_action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sentient -c -o -r -n 0 -m lingeling digit-reversal.snt | |
# https://arxiv.org/pdf/math/0511366.pdf | |
# This program explores 'Open question one' | |
array5<int9> digits; | |
base = 198; | |
max = 197; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<center> | |
<canvas id="canvas" width="1000" height="1000"></canvas> | |
</center> | |
<script> | |
var canvas = document.getElementById("canvas"); | |
var context = canvas.getContext("2d"); | |
var done = false; | |
function circle_around(callback) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a greatly simplified version of https://github.com/tuzz/supersat | |
# It reduces the superpermutation problem to boolean satisfiability. | |
# | |
# To generate a SAT problem for N=3, LENGTH=9: | |
# ruby simplesupersat.rb 3 9 | |
# | |
# And to run a SAT solver on it: | |
# lingeling 3-9.dimacs | |
N = Integer(ARGV[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A proof-of-concept Sentient program for a set membership problem. | |
# $ sentient subset.snt --assign '{ target: [1, 1, 0, 1], max_selections: 2 }' | |
# | |
# Outputs: {"members":[false,false,false,false,true,false,false,false,true,false,false,false]} | |
# Corresponding to: uk - scotland | |
# Given: a set of all the countries in the world, and a set of possible | |
# groupings of those countries (e.g. “Scandinavia” or “Central America”, or | |
# “All”), given a set of arbitrary countries, I want to compute the most concise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Attempts to find a superpermutation for a given number of digits that fit into a given string length. | |
# https://en.wikipedia.org/wiki/Superpermutation | |
# | |
# Run: ruby superpermutation.rb | lingeling -f | |
# | |
# The program will be satisfiable if it is possible, but won't actually print the solution. | |
# I need to add some code to decode the output. | |
digits = 4 | |
length = 33 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Implements: https://gist.github.com/jcoglan/adc4ec173017e48f5ce68d6568fc5860 | |
// | |
// The basic idea is we store a vector of cursors that advance through the | |
// nested list and build up the result. If the predicate for the current | |
// element is false we append a row padded with zeroes, otherwise we move | |
// along to the next nested list until we reach the last one. When we do, | |
// we append the fully saturated row to the result and move to the next | |
// element in each of the nested lists. | |
// | |
// At the end we need to check if there are any elements that matched the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is a proof-of-concept, inspired by clojure, that stores just the | |
* transitions between multiple Foo structs, rather than copying the entire | |
* struct's fields each time. | |
*/ | |
#[derive(Default)] // <-- this derives Foo::default() which creates a Foo struct | |
// with a and b initialized to zero. | |
struct Foo { | |
a: u8, | |
b: u8, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple implementation of a Markov Model in Rust | |
#[derive(Debug, PartialEq)] | |
struct State { | |
name: &'static str, | |
} | |
struct Transition<'a> { | |
from: &'a State, | |
to: &'a State, |