File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- /** delegates to Node.js until https://github.com/denoland/deno/issues/17171 is fixed */
21export default async function solve ( input : string ) {
3- const command = new Deno . Command ( "node" , {
4- args : [ `${ import . meta. dirname } /solve.mts` ] ,
5- stdin : "piped" ,
6- stdout : "piped" ,
7- } ) ;
8-
9- const child = command . spawn ( ) ;
10- const writer = child . stdin . getWriter ( ) ;
11- await writer . write ( new TextEncoder ( ) . encode ( input ) ) ;
12- writer . releaseLock ( ) ;
13- await child . stdin . close ( ) ;
14-
15- const { stdout } = await child . output ( ) ;
16- return + new TextDecoder ( ) . decode ( stdout ) ;
2+ const { href : workerUrl } = new URL ( "./worker.ts" , import . meta. url ) ;
3+ const worker = new Worker ( workerUrl , { type : "module" } ) ;
4+ try {
5+ const { promise, resolve } = Promise . withResolvers < number > ( ) ;
6+ worker . onmessage = ( { data } ) => resolve ( data ) ;
7+ worker . postMessage ( input ) ;
8+ return await promise ;
9+ } finally {
10+ worker . terminate ( ) ;
11+ }
1712}
Original file line number Diff line number Diff line change 1- import process from "node:process" ;
2- import { text } from "node:stream/consumers" ;
1+ /// <reference no-default-lib="true" />
2+ /// <reference lib="deno.worker" />
3+
34import { init } from "z3-solver" ;
45import { parseManual } from "../../manuals.ts" ;
56
6- export default async function solve ( input : string ) {
7+ async function solve ( input : string ) {
78 const manual = parseManual ( input ) ;
89 const { Context } = await init ( ) ;
10+ const { Int, Optimize } = Context ( "main" ) ;
911 let sum = 0 ;
1012 for ( const { buttons, requirements } of manual ) {
11- const { Int, Optimize } = Context ( "main" ) ;
1213 const variables = buttons . map ( ( _ , i ) => Int . const ( `b${ i } ` ) ) ;
1314 const optimize = new Optimize ( ) ;
1415 optimize . add (
@@ -29,6 +30,4 @@ export default async function solve(input: string) {
2930 return sum ;
3031}
3132
32- const input = await text ( process . stdin ) ;
33- const output = await solve ( input ) ;
34- console . log ( output ) ;
33+ self . onmessage = async ( { data } ) => self . postMessage ( await solve ( data ) ) ;
Original file line number Diff line number Diff line change 1717 "@std/path" : " jsr:@std/path@^1.0.8" ,
1818 "nerdamer" : " npm:nerdamer@^1.1.13" ,
1919 "pretty-ms" : " npm:pretty-ms@^9.3.0" ,
20- "z3-solver" : " npm: z3-solver@^4.15 .4"
20+ "z3-solver" : " jsr:@macil/ z3-solver@^1.0 .4"
2121 }
2222}
You can’t perform that action at this time.
0 commit comments