Commit f88a6964 authored by Kai Brandes's avatar Kai Brandes

reference wasm-fn automatically

parent 6be4efce
import React from "react";
import * as wasm from "adventofcode_2017";
export class SolutionComponent extends React.Component {
constructor(props) {
......@@ -12,11 +13,11 @@ export class SolutionComponent extends React.Component {
}
resultA(event) {
this.setState({a: this.props.fn_a(event.target.value)});
this.setState({a: wasm['calc_day_'+this.props.day+'_a'](event.target.value)});
}
resultB(event) {
this.setState({b: this.props.fn_b(event.target.value)});
this.setState({b: wasm['calc_day_'+this.props.day+'_b'](event.target.value)});
}
renderInput(resultTriggerFn, defaultVal) {
......
import {SolutionComponent} from './components/solution-component';
import React from "react";
import ReactDOM from "react-dom";
import * as wasm from "adventofcode_2017";
const TEXTAREA_COLS = 50;
const TEXTAREA_ROWS = 10;
function day1() {
return <SolutionComponent day={1}
fn_a={wasm.calc_day_1_a}
default_a={'91212129'}
fn_b={wasm.calc_day_1_b}
default_b={'123425'}
/>;
}
function day2() {
return <SolutionComponent day={2}
fn_a={wasm.calc_day_2_a}
default_a={'91212129'}
fn_b={wasm.calc_day_2_b}
default_b={'123425'}
cols={TEXTAREA_COLS}
rows={TEXTAREA_ROWS}
......@@ -28,9 +23,7 @@ function day2() {
function day3() {
return <SolutionComponent day={3}
fn_a={wasm.calc_day_3_a}
default_a={'312051'}
fn_b={wasm.calc_day_3_b}
default_b={'312051'}
/>;
}
......@@ -38,9 +31,7 @@ function day3() {
function day4() {
return <SolutionComponent day={4}
fn_a={wasm.calc_day_4_a}
default_a={'aa bb cc dd aa\naa bb cc dd aaa\n'}
fn_b={wasm.calc_day_4_b}
default_b={'bqs bqs dbutvgf mmzb izpyud rap izpyud xlzeb mnj hjncs\ncirkjq nmjuu xtgejv gtexvj vjcmtqq unjmu\nofbh bdrsk rdrjj elaxvk jrjdr\n'}
cols={TEXTAREA_COLS}
rows={TEXTAREA_ROWS}
......@@ -58,9 +49,7 @@ function day5() {
"-4\n" +
"-6";
return <SolutionComponent day={5}
fn_a={wasm.calc_day_5_a}
default_a={'0\n3\n0\n1\n-3'}
fn_b={wasm.calc_day_5_b}
default_b={inputFor5B}
cols={TEXTAREA_COLS}
rows={TEXTAREA_ROWS}
......@@ -69,9 +58,7 @@ function day5() {
function day6() {
return <SolutionComponent day={6}
fn_a={wasm.calc_day_6_a}
default_a={'0 2 7 0'}
fn_b={wasm.calc_day_6_b}
default_b={'0 2 7 0'}
/>;
}
......@@ -79,9 +66,7 @@ function day6() {
function day7() {
const day7input = "pbga (66)\nxhth (57)\nebii (61)\nhavc (66)\nktlj (57)\nfwft (72) -> ktlj, cntj, xhth\nqoyq (66)\npadx (45) -> pbga, havc, qoyq\ntknk (41) -> ugml, padx, fwft\njptl (61)\nugml (68) -> gyxo, ebii, jptl\ngyxo (61)\ncntj (57)";
return <SolutionComponent day={7}
fn_a={wasm.calc_day_7_a}
default_a={day7input}
fn_b={wasm.calc_day_7_b}
default_b={day7input}
cols={TEXTAREA_COLS}
rows={TEXTAREA_ROWS}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment