Skip to content

Commit

Permalink
chore: trim whitespace, no \n\n in response
Browse files Browse the repository at this point in the history
  • Loading branch information
ctjlewis committed Apr 22, 2024
1 parent 4eaaa50 commit c9de573
Show file tree
Hide file tree
Showing 4 changed files with 961 additions and 1,087 deletions.
1 change: 1 addition & 0 deletions programs/automata/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Example = {
input: string;
}

// const selected: number[] = []
const selected = [1, 0, 30, 54, 60, 62, 90, 94, 102, 110, 122, 126, 150, 158, 182, 188, 190, 220, 222, 250, 254]
const examples: Example[] = []

Expand Down
25 changes: 10 additions & 15 deletions programs/automata/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ function integerToBinaryTape(num: number, log: (...args: string[]) => void): str
}

function generateRule(ruleNumber: RuleNumber, log: (...args: string[]) => void): Rule {
log(`\nRULE ${ruleNumber}`)
log(`RULE ${ruleNumber}`)
const ruleBinaryString = integerToBinaryTape(ruleNumber, log)

log(`BINARY ${ruleBinaryString.split("").map((v, i) => `${7-i}${format(v)}`).join(" ")}`)
// LOG(`REVERSE BINARY POSITIONS ${ruleBinaryString.split("").map((v, i) => `${i}${format(v)}`).join(" ")}`)
log("\nRULES FROM BINARY")
log("RULES FROM BINARY")
for (let i = 0; i < 8; i++) {
log(`${format(PATTERNS[i], " ")}: ${7-i}${format(ruleBinaryString[i])}`)
}
Expand Down Expand Up @@ -85,8 +85,8 @@ export default function testAutomata(
let state = initialState
const width = initialState.length
const states: Tape[] = [initialState]
console.log("\n---")
console.log(`[USER]\n${formatTape(state)}\n${ruleNumber}\n${generations}`)

console.log(`\n[USER]\n${formatTape(state)}\n${ruleNumber}\n${generations}`)
console.log("\n[ASSISTANT]")
log(`START: MAX ${generations}`)
log(formatTape(state))
Expand All @@ -97,16 +97,11 @@ export default function testAutomata(

function info(i: number) {
const indexLabel = `${i-1}/${generations}`
// const doneLabel =
// i-1 === generations
// ? "DONE"
// : "LOOP"
log("")
log(`TAPE ${positions(format(state).split(""))}`)
log(`PRINT ${indexLabel} ${format(state, " ")}`)
// log(`${doneLabel}`)
// log("")
// log("LOOP")
if (i - 1 === generations) {
log("DONE")
}
}

function evolve(state: Tape) {
Expand All @@ -120,20 +115,20 @@ export default function testAutomata(
const patternIndex = 7 - PATTERNS.indexOf([left, center, right].join(""))

const leftLabel =
i > 0 ? `${i - 1}${format([left])}` : ` ${format([0])}`
i > 0 ? `${i - 1}${format([left])}` : `${format([0])}`

const centerLabel = `${i}${format([center])}`

const rightLabel =
i < width - 1 ? `${i + 1}${format([right])}` : ` ${format([0])}`
i < width - 1 ? `${i + 1}${format([right])}` : `${format([0])}`

const ruleLabel =
`${format([left, center, right], " ")}: ${patternIndex}${format([pattern])}`

// const indexLabel = i === width-1 ? "STOP" : ""
const matchLabel = `${i}${format([pattern])}`.padStart(3)

log(`${leftLabel.padStart(3)} ${centerLabel.padStart(3)} ${rightLabel.padStart(3)} ${ruleLabel.padStart(4)} ${matchLabel}`)
log(`${leftLabel.padStart(3)} ${centerLabel.padStart(3)} ${rightLabel.padStart(3)} ${ruleLabel.padStart(4)} ${matchLabel}`)
newState.push(pattern)
}

Expand Down
Loading

0 comments on commit c9de573

Please sign in to comment.