The TransCompilator

Solved LeetCode program · 942 of 1,000

#1307 · Verbal Arithmetic Puzzle

Hard Array chunk-19.md

Original English source

Keep a shared assigned holding -1, -1, -1, -1, -1, -1, -1, and -1. Keep a shared taken as a list of 10 zeros. Keep a shared leading as a list of 8 zeros. Set item 0 of leading to 1. Set item 4 of leading to 1. Keep a shared addends holding 3, 1, 2, 6, 1, 5, 0, and 4. Keep a shared sumstarts holding 0, 2, 4, 6, and 8. Keep a shared sumcounts holding 2, 2, 2, 2, and 0. Keep a shared letterorder holding 3, 1, 7, 2, 6, 1, 1, 5, 2, 0, 4, 5, and 4. Keep a shared letterstarts holding 0, 3, 6, 9, and 12. Keep a shared lettercounts holding 3, 3, 3, 3, and 1. Keep a shared outputslots holding 7, 1, 2, 5, and 4. Keep a shared found of 0. Keep a shared passing of 0.

To verify from column (a whole number) with carried (a whole number). The total is carried. The start is item column of sumstarts. The count is item column of sumcounts. If count is more than 0, set total to total plus item (item start of addends) of assigned. If count is more than 1, set total to total plus item (item (start plus 1) of addends) of assigned. The target is 0. If item column of outputslots is at least 0, set target to item (item column of outputslots) of assigned. If total modulo 10 is not target, return. If column is 4 and total divided by 10 is 0, set found to 1, return. If column is 4, return. Fill from column plus 1 with 0 and total divided by 10.

To pick from column (a whole number) with offset (a whole number) and chosen (a whole number). The slot is item (item column of letterstarts plus offset) of letterorder. Set item slot of assigned to chosen. Set item chosen of taken to 1. Fill from column with offset plus 1 and passing. Set item slot of assigned to -1. Set item chosen of taken to 0.

To fill from column (a whole number) with offset (a whole number) and carried (a whole number). If found is 1, return. The count is item column of lettercounts. If offset is at least count, Verify from column with carried, return. The start is item column of letterstarts. The slot is item (start plus offset) of letterorder. If item slot of assigned is at least 0, Fill from column with offset plus 1 and carried, return.
For every candidate from 0 to 9.
Set passing to carried. The fresh is 1. If item candidate of taken is 1, set fresh to 0. If item slot of leading is 1 and candidate is 0, set fresh to 0. If fresh is 1, Pick from column with offset and candidate.

Fill from 0 with 0 and 0. If found is 1, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true