Skip to content

Instantly share code, notes, and snippets.

@guregu
guregu / aoc2022-1.pl
Last active December 1, 2022 16:24
Advent of Code 2022 #1 in Prolog (Trealla Prolog)
% caveat: add an extra line break to the input :-)
:- use_module(library(dcgs)).
:- use_module(library(pio)).
elves([N|Ns]) --> elf(N), elves(Ns).
elves([]) --> [].
elf(Calories) --> sum(Calories), nl.
sum(X) --> number(A), nl, sum(B), { X is A + B }.
@guregu
guregu / main.go
Created December 4, 2022 19:26
text adventure generated by AI
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
type Room struct {

(Testing against trealla-go)

Previous version:

cpu: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
BenchmarkQuery
BenchmarkQuery-16           1837            678403 ns/op
BenchmarkRedo
BenchmarkRedo-16 4272 287292 ns/op
@guregu
guregu / channelpredicate.go
Last active August 5, 2024 19:06
Example of a trealla-prolog/go native predicate returning multiple choice points
package trealla_test
import (
"context"
"sync/atomic"
"testing"
"sync"
"github.com/trealla-prolog/go/trealla"