summaryrefslogtreecommitdiff
path: root/c++
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-10-29 14:03:28 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-10-29 14:03:28 +0100
commitdbf65fecbaa86335d4beb44c87ad2638e8a2f80d (patch)
treeacded26780a6fc2144fb6d6a2fc17f002ee2692c /c++
parentaeedc7e99ffdbbee2f4c2366a137230af003c3e3 (diff)
downloadapps-lights_out-dbf65fecbaa86335d4beb44c87ad2638e8a2f80d.tar.gz
Fixing lights_outmain
Diffstat (limited to 'c++')
-rw-r--r--c++/.nix/derivation.nix4
-rw-r--r--c++/lights_out.cpp46
2 files changed, 36 insertions, 14 deletions
diff --git a/c++/.nix/derivation.nix b/c++/.nix/derivation.nix
index a47b023..e3f712d 100644
--- a/c++/.nix/derivation.nix
+++ b/c++/.nix/derivation.nix
@@ -15,8 +15,8 @@ stdenv.mkDerivation {
EM_CACHE=$TMPDIR/emscripten_cache
emcc lights_out.cpp \
-s WASM=1 \
- -s EXPORTED_FUNCTIONS='["_fake_main"]' \
- -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \
+ -s EXPORTED_FUNCTIONS='["_solve_lights_out_dispatch","_malloc","_free"]' \
+ -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap","HEAPU8"]' \
-o lights_out.js
'';
diff --git a/c++/lights_out.cpp b/c++/lights_out.cpp
index 7dc8dc1..b35c4ee 100644
--- a/c++/lights_out.cpp
+++ b/c++/lights_out.cpp
@@ -155,20 +155,42 @@ int solve_lights_out(const Vec<MM,NN>& b, Vec<MM,NN>& x){
return 0;
}
-extern "C"{
-int solve_lights_out_dispatch(int8_t* b, int m, int n){
- if ( m == 3 and n == 3){
- Vec<3,3> b_raw;
- Vec<3,3> x;
+template<uint64_t M, uint64_t N>
+int solve_lights_out_interconnect(int8_t* b_raw){
+ Vec<M,N> b;
+
+ for(point<M,N> i{}; i.x < M && i.y < N; i.inc()){
+ auto is = i.stride();
+ b[is] = b_raw[is];
+ }
- auto rc = solve_lights_out<3,3>(b_raw,x);
- if(rc == 0) {
- for(point<3,3> i{}; i.x < 3 && i.y < 3; i.inc()){
- auto is = i.stride();
- b[is] = x[is];
- }
+ Vec<M,N> x;
+
+ auto rc = solve_lights_out<M,N>(b,x);
+ if(rc == 0) {
+ for(point<M,N> i{}; i.x < M && i.y < N; i.inc()){
+ auto is = i.stride();
+ b_raw[is] = x[is];
}
- return rc;
+ }
+ return rc;
+}
+
+extern "C"{
+int solve_lights_out_dispatch(int8_t* b_raw, int m, int n){
+
+ if ( m == 1 and n == 1){
+ return solve_lights_out_interconnect<1,1>(b_raw);
+ }else if( m == 2 and n == 2){
+ return solve_lights_out_interconnect<2,2>(b_raw);
+ }else if( m == 3 and n == 3){
+ return solve_lights_out_interconnect<3,3>(b_raw);
+ }else if( m == 6 and n == 6){
+ return solve_lights_out_interconnect<6,6>(b_raw);
+ }else if( m == 7 and n == 7){
+ return solve_lights_out_interconnect<7,7>(b_raw);
+ }else if( m == 8 and n == 8){
+ return solve_lights_out_interconnect<8,8>(b_raw);
}
return -2;
}