type Dfa = List[DfaState]
record DfaState = {
accept: Number?,
transitions: List[Transition]
}
record Transition = {
max: Number,
to: Number
}
// .*((?<one>one|1)|(?<two>two|2)|etc
let digitDfa: List[DfaState] = [
(* 0 = ~ *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 1 = *) {
accept = 1,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 2 = *) {
accept = 2,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 3 = *) {
accept = 3,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 4 = *) {
accept = 4,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 5 = *) {
accept = 5,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 6 = *) {
accept = 6,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 7 = *) {
accept = 7,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 8 = *) {
accept = 8,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 9 = *) {
accept = 9,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 10 = ~e *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 19 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 11 = ~f *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 31 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 20 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 12 = ~n *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 25 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 13 = ~o *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 21 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 14 = ~s *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 32 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 29 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 15 = ~t *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 103, to = 0 },
{ max = 104, to = 16 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 118, to = 0 },
{ max = 119, to = 17 },
{ max = 1114111, to = 0 }
]
},
(* 16 = ~th *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 113, to = 0 },
{ max = 114, to = 27 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 17 = ~tw *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 35 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 18 = ~seve *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 19 },
{ max = 109, to = 0 },
{ max = 110, to = 37 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 19 = ~ei *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 103, to = 23 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 20 = ~fo *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 21 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 117, to = 22 },
{ max = 1114111, to = 0 }
]
},
(* 21 = ~on *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 34 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 25 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 22 = ~fou *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 113, to = 0 },
{ max = 114, to = 4 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 23 = ~eig *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 103, to = 0 },
{ max = 104, to = 24 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 24 = ~eigh *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 38 },
{ max = 1114111, to = 0 }
]
},
(* 25 = ~ni *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 26 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 26 = ~nin *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 39 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 25 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 27 = ~thr *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 28 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 28 = ~thre *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 36 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 19 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
],
},
(* 29 = ~si *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 119, to = 0 },
{ max = 120, to = 6 },
{ max = 1114111, to = 0 }
]
},
(* 30 = ~fiv *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 5 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 31 = ~fi *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 117, to = 0 },
{ max = 118, to = 30 },
{ max = 1114111, to = 0 }
]
},
(* 32 = ~se *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 19 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 117, to = 0 },
{ max = 118, to = 33 },
{ max = 1114111, to = 0 }
]
},
(* 33 = ~sev *) {
accept = null,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 18 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 34 = ~one *) {
accept = 1,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 19 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 35 = ~two *) {
accept = 2,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 109, to = 0 },
{ max = 110, to = 21 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 36 = ~three *) {
accept = 3,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 19 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 37 = ~seven *) {
accept = 7,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 25 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
},
(* 38 = ~eight *) {
accept = 8,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 103, to = 0 },
{ max = 104, to = 16 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 118, to = 0 },
{ max = 119, to = 17 },
{ max = 1114111, to = 0 }
]
},
(* 39 = ~nine *) {
accept = 9,
transitions = [
{ max = 48, to = 0 },
{ max = 49, to = 1 },
{ max = 50, to = 2 },
{ max = 51, to = 3 },
{ max = 52, to = 4 },
{ max = 53, to = 5 },
{ max = 54, to = 6 },
{ max = 55, to = 7 },
{ max = 56, to = 8 },
{ max = 57, to = 9 },
{ max = 100, to = 0 },
{ max = 101, to = 10 },
{ max = 102, to = 11 },
{ max = 104, to = 0 },
{ max = 105, to = 19 },
{ max = 109, to = 0 },
{ max = 110, to = 12 },
{ max = 111, to = 13 },
{ max = 114, to = 0 },
{ max = 115, to = 14 },
{ max = 116, to = 15 },
{ max = 1114111, to = 0 }
]
}
]
let isNewline: Number -> Boolean =
(x: Number) -> x == 10
let isDigit: Number -> Boolean =
(x: Number) -> (x >= 48) && (x < 58)
let toDigit: Number -> Number =
(x: Number) -> (x - 48)
let transition: (Dfa, Number, Number) -> Number =
let rec searchTransitions: (Number, List[Transition]) -> Transition =
(target: Number, transitions: List[Transition]) ->
let (h, t) = uncons(transitions)
if(target <= h.max) h
else searchTransitions(target, t)
(dfa: Dfa, state: Number, symbol: Number) ->
searchTransitions(symbol, dfa[state].transitions)
let handleLine: (Dfa, List[Number]) -> Number =
let rec iterate: (Dfa, Number?, Number?, List[Number]) -> Number =
(dfa: Dfa, first: Number?, last: Number?, state: Number, rest: List[Number]) ->
if(isEmpty(rest)) (first * 10) + last
else
let (h, t) = uncons(rest)
let nextState = transition(dfa, state, h)
let accept = dfa[nextState].accept
if(accept != null)
let newFirst = if(first == null) accept else first
iterate(dfa, newFirst, accept, nextState, t)
else iterate(dfa, first, last, nextState, t)
(dfa: Dfa, x: List[Number]) -> iterate(dfa, null, null, 0, x)
let splitLines: List[Number] -> List[List[Number]]
let rec unconsLine: (List[Number], List[Number]) -> (List[Number], List[Number]) =
(acc: List[Number], rest: List[Number]) ->
if(rest is Nil) (acc, rest)
else
let (h, t) = uncons(rest)
if(isNewline(h)) (acc, t)
else unconsLine(acc :+ h, t)
let rec accumulate: (List[List[Number]], List[Number]) -> List[List[Number]] =
(acc: List[List[Number]], rest: List[Number]) ->
if(rest == Nil) acc
else
let (hl, t) = unconsLine(Nil, rest)
accumulate(acc :+ hl, t)
(x: List[Number]) -> accumulate(Nil, x)
let rec sum: List[Number] -> Number =
(x: List[Number]) ->
if(x == Nil) 0
else
let (h, t) = uncons(x)
h + sum(t)
let main: List[Number] -> Number =
(input: List[Number]) ->
let lines = splitLines(input)
let dfa = digitDfa
let individuals = mapList(lines, (x: List[Number]) -> handleLine(dfa, x))
sum(individuals)