Skip to content

Commit

Permalink
Create a tiny library of functions (#11)
Browse files Browse the repository at this point in the history
* Move functions into their own file.

* A hack to extract the result from Maxima's verbose output.
  • Loading branch information
MHenderson authored Jul 4, 2024
1 parent 34480fd commit 58b9fdb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ install:
sudo apt-get -y install maxima maxima-share --no-install-suggests --no-install-recommends

run:
maxima --very-quiet --batch=src/euler.mac
@cd src; maxima --very-quiet --batch=eulersberg.mac | grep "RESULT: "
12 changes: 1 addition & 11 deletions src/euler.mac
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
defstruct(graph(V, E))$

path(G, P):= block(
[result: true],
for i: 2 step 2 thru (length(P)-1) do (
Expand All @@ -10,12 +8,4 @@ path(G, P):= block(

euler_path(G, P):= (
is(path(G, P)) and is(length(P) = 2*length(G@E) + 1)
)$

eulersberg: new(graph({A,B,C,D,E,F}, {[a,{E,F}], [b,{B,F}], [c,{B,F}], [d,{A,F}], [e,{A,F}], [f,{C,F}], [g,{A,C}], [h,{A,C}], [i,{C,D}], [k,{A,D}], [l,{D,E}], [m,{A,E}], [n,{A,E}], [o,{B,E}], [p,{A,B}]}))$

s: "EaFbBcFdAeFfCgAhCiDkAmEnApBoElD"$

journey: map(eval_string, charlist(s))$

euler_path(eulersberg, journey);
)$
11 changes: 11 additions & 0 deletions src/eulersberg.mac
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("euler.mac")$

defstruct(graph(V, E))$

eulersberg: new(graph({A,B,C,D,E,F}, {[a,{E,F}], [b,{B,F}], [c,{B,F}], [d,{A,F}], [e,{A,F}], [f,{C,F}], [g,{A,C}], [h,{A,C}], [i,{C,D}], [k,{A,D}], [l,{D,E}], [m,{A,E}], [n,{A,E}], [o,{B,E}], [p,{A,B}]}))$

s: "EaFbBcFdAeFfCgAhCiDkAmEnApBoElD"$

journey: map(eval_string, charlist(s))$

print(concat(supcase("result: "), string(euler_path(eulersberg, journey))))$
1 change: 1 addition & 0 deletions src/maxima-init.mac
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
showtime:all;

0 comments on commit 58b9fdb

Please sign in to comment.