The TransCompilator

HTML chunk · 50 solved programs

Chunk 17 · #1038–#1139

Full original English source and expected stdout for fifty solved programs. Prefer plain text? Read the Markdown equivalent.

#1038 · Binary Search Tree to Greater Sum Tree

Medium Depth-First Search

Keep a shared values holding 4, 1, 6, 0, 2, 5, and 7. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, -1, -1, and -1. Keep a shared running of 0.

To revise from node (a whole number). If node is less than 0, return. Revise from item node of rights. Increase running by item node of values. Set item node of values to running. Revise from item node of lefts.

Revise from 0. The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. Show item node of values. The left is item node of lefts. The right is item node of rights. If left is at least 0, Place left into queue, add 1 to count. If right is at least 0, Place right into queue, add 1 to count.

Expected stdout

22
25
13
25
24
18
7

Open in Playground Standalone Page

#1039 · Minimum Score Triangulation of Polygon

Medium Array

The values is a list of 3, 7, 4, and 5. The size is 4. The table is a list of 16 zeros.
For every gap from 2 to 3.
For every start from 0 to size minus 1 minus gap.
The finish is start plus gap. The cell is start times size plus finish. Set item cell of table to 1000000.
For every split from start plus 1 to finish minus 1.
The leftcell is start times size plus split. The rightcell is split times size plus finish. The candidate is item leftcell of table plus item rightcell of table plus item start of values times item split of values times item finish of values. If candidate is less than item cell of table, set item cell of table to candidate.

Show item 3 of table.

Expected stdout

144

Open in Playground Standalone Page

#1040 · Moving Stones Until Consecutive II

Medium Array

The stones is a list of 7, 4, and 9. Sort stones. The size is 3. The largest is item 2 of stones minus item 1 of stones. The smallest is item 1 of stones minus item 0 of stones. The span is the larger of largest and smallest. The most is span minus 1. The fewest is 3.
For every start from 0 to 2.
The finish is start. The count is 1. If size minus count is less than fewest, set fewest to size minus count.
Repeat while finish plus 1 is less than size and item (finish plus 1) of stones minus item start of stones plus 1 is at most size.
Add 1 to finish. Add 1 to count. If count is size, set fewest to 0. If count is size minus 1 and item finish of stones minus item start of stones plus 1 is size, set fewest to 1. If count is less than size minus 1 and size minus count is less than fewest, set fewest to size minus count.

Show fewest. Show most.

Expected stdout

1
2

Open in Playground Standalone Page

#1041 · Robot Bounded In Circle

Medium String

Keep a shared instructions as empty text. Place "GGLLGG" into instructions. Keep a shared across of 0. Keep a shared down of 0. Keep a shared facing of 0. Keep a shared east holding 0, 1, 0, and -1. Keep a shared north holding 1, 0, -1, and 0.

To travel.
For every spot from 0 to the last position of instructions.
The symbol is the slice of instructions from spot to spot plus 1. The move is 0. If symbol is "G", set move to 1. If symbol is "L", subtract 1 from facing, set facing to facing modulo 4. If symbol is "R", add 1 to facing, set facing to facing modulo 4. If facing is less than 0, set facing to facing plus 4. The side is facing. If move is 1, set across to across plus item side of east, set down to down plus item side of north.

Travel. The bounded is 1. If across is 0 and down is 0, set bounded to 1. If across is not 0 or down is not 0, set bounded to 0. If facing is not 0, set bounded to 1. If bounded is 1, show true, otherwise show false.

Expected stdout

true

Open in Playground Standalone Page

#1042 · Flower Planting With No Adjacent

Medium Depth-First Search

The firsts is a list of 0 and 2. The seconds is a list of 1 and 3. The count is 4. The colors is a list of 0, 0, 0, and 0.
For every garden from 0 to count minus 1.
The used is an empty list of whole numbers.
For every edge from 0 to the last position of firsts.
The other is -1. If item edge of firsts is garden, set other to item edge of seconds. If item edge of seconds is garden, set other to item edge of firsts. If other is at least 0, The shade is item other of colors, Place shade into used.
For every choice from 1 to 4.
If used does not contain choice, set item garden of colors to choice, stop.

For each value in colors, Show value.

Expected stdout

1
2
1
2

Open in Playground Standalone Page

#1043 · Partition Array for Maximum Sum

Medium Array

The numbers is a list of 1, 15, 7, 9, 2, 5, and 10. The span is 3. The count is 7. The best is a list of 8 zeros.
For every finish from 1 to count.
The largest is 0.
For every width from 1 to span.
If width is at most finish.
The start is finish minus width. The here is item start of numbers. If here is more than largest, set largest to here. The candidate is item start of best plus width times largest. If candidate is more than item finish of best, set item finish of best to candidate.

Show item count of best.

Expected stdout

84

Open in Playground Standalone Page

#1044 · Longest Duplicate Substring

Hard String

The source is "banana". The last is the last position of source. The found is 0. The answer is empty text.
For every step from 1 to last.
The span is last plus 1 minus step.
For every first from 0 to last plus 1 minus span.
For every second from first plus 1 to last plus 1 minus span.
The leftpiece is the slice of source from first to first plus span. The rightpiece is the slice of source from second to second plus span. If leftpiece matches rightpiece, set answer to leftpiece, set found to 1, stop. If found is 1, stop. If found is 1, stop.

Show answer.

Expected stdout

ana

Open in Playground Standalone Page

#1046 · Last Stone Weight

Easy Array

The stones is a list of 2, 7, 4, 1, 8, and 1.
Repeat while the number of items in stones is more than 1.
Sort stones. The heavy is the last item of stones. Remove the last item from stones. The light is the last item of stones. Remove the last item from stones. If heavy is not light, The rest is heavy minus light, Place rest into stones.

Show item 0 of stones.

Expected stdout

1

Open in Playground Standalone Page

#1047 · Remove All Adjacent Duplicates In String

Easy String

The source is "abbaca". The kept is empty text. The held is 0.
For every spot from 0 to the last position of source.
The symbol is character spot of source. The top is 0. If held is more than 0, set top to character (held minus 1) of kept. The removed is 0. If held is more than 0 and top is symbol, remove last character from kept, subtract 1 from held, set removed to 1. If removed is 0, Place symbol into kept, add 1 to held.

Show kept.

Expected stdout

ca

Open in Playground Standalone Page

#1048 · Longest String Chain

Medium Array

The words is a list of "a", "b", "ba", "bca", "bda", and "bdca". The count is 6. The last is count minus 1.
For every left from 0 to last.
For every right from left plus 1 to last.
The first is item left of words. The second is item right of words. The firstsize is the number of characters in first. The secondsize is the number of characters in second. If secondsize is less than firstsize, swap item left of words and item right of words.

The best is a list of 6 zeros.
For every spot from 0 to last.
Set item spot of best to 1.

For every right from 0 to last.
For every left from 0 to right minus 1.
The shortraw is item left of words. The longraw is item right of words. The short is empty text. Place shortraw into short. The long is empty text. Place longraw into long. The shortsize is the number of characters in short. The longsize is the number of characters in long. The longlast is the last position of long. The paired is 0.
For every cut from 0 to longlast.
The leftpart is the slice of long from 0 to cut. The rightpart is the slice of long from cut plus 1 to longlast plus 1. The joined is a copy of leftpart. Place rightpart into joined. If joined matches short, set paired to 1. If paired is 1 and item left of best plus 1 is more than item right of best, set item right of best to item left of best plus 1. If paired is 1, stop.

The answer is 0.
For each value in best.
If value is more than answer, set answer to value.

Show answer.

Expected stdout

4

Open in Playground Standalone Page

#1049 · Last Stone Weight II

Medium Array

The stones is a list of 2, 7, 4, 1, 8, and 1. The total is 0.
For each stone in stones.
Add stone to total.

The goal is total divided by 2. The possible is a list of 12 zeros. Set item 0 of possible to 1.
For each stone in stones.
For every step from 0 to goal.
The sum is goal minus step. If item sum of possible is 1 and sum plus stone is at most goal, set item (sum plus stone) of possible to 1.

The best is 0.
For every sum from 0 to goal.
If item sum of possible is 1, set best to sum.

The answer is total minus 2 times best. Show answer.

Expected stdout

1

Open in Playground Standalone Page

#1051 · Height Checker

Easy Array

The heights is a list of 1, 1, 4, 2, 1, and 3. The ordered is an empty list of whole numbers.
For each height in heights.
Place height into ordered.

Sort ordered. The total is 0.
For every spot from 0 to the last position of heights.
If item spot of heights is not item spot of ordered, add 1 to total.

Show total.

Expected stdout

3

Open in Playground Standalone Page

#1052 · Grumpy Bookstore Owner

Medium Array

The customers is a list of 1, 0, 1, 2, 1, 1, 7, and 5. The moods is a list of 0, 1, 0, 1, 0, 1, 0, and 1. The minutes is 3. The last is 7. The base is 0.
For every spot from 0 to last.
The amount is item spot of customers. If item spot of moods is 0, add amount to base.

The best is 0.
For every start from 0 to last minus minutes plus 1.
The extra is 0.
For every step from 0 to minutes minus 1.
The spot is start plus step. The amount is item spot of customers. If item spot of moods is 1, add amount to extra. If extra is more than best, set best to extra.

The answer is base plus best. Show answer.

Expected stdout

16

Open in Playground Standalone Page

#1053 · Previous Permutation With One Swap

Medium Array

Keep a shared numbers holding 1, 9, 4, 6, and 7. Keep a shared pivot of -1. Keep a shared bestspot of 0. Keep a shared bestvalue of 0.

To choose.
For every spot from pivot plus 1 to the last position of numbers.
The value is item spot of numbers. The place is pivot. The cap is item place of numbers. If value is less than cap and value is at least bestvalue, set bestvalue to value, set bestspot to spot.

The last is the last position of numbers.
For every step from 0 to last minus 1.
The spot is last minus 1 minus step. If item spot of numbers is more than item (spot plus 1) of numbers, set pivot to spot, stop.

Set bestspot to pivot plus 1. The target is bestspot. If pivot is at least 0, set bestvalue to item target of numbers. If pivot is at least 0, Choose. The place is pivot. The other is bestspot. If pivot is at least 0, swap item place of numbers and item other of numbers. For each value in numbers, Show value.

Expected stdout

1
7
4
6
9

Open in Playground Standalone Page

#1054 · Distant Barcodes

Medium Array

Keep a shared labels as an empty list of whole numbers. Keep a shared counts as an empty list of whole numbers. Keep a shared wanted of 0. Keep a shared located of 0. Keep a shared best of 0. Keep a shared bestcount of 0. Keep a shared previous of -1.

To locate from spot (a whole number). If spot is more than the last position of labels, return. If item spot of labels is wanted, set located to spot, return. Locate from spot plus 1.

The barcodes is a list of 1, 1, 1, 2, 2, and 3.
For each code in barcodes.
Set wanted to code. Set located to -1. Locate from 0. The place is located. If place is at least 0, set item place of counts to item place of counts plus 1. If place is less than 0, Place code into labels, Place 1 into counts.

To pick. Set best to 0. Set bestcount to -1.
For every spot from 0 to the last position of labels.
The label is item spot of labels. The amount is item spot of counts. If label is not previous and amount is more than bestcount, set best to spot, set bestcount to amount.

The result is an empty list of whole numbers.
For every position from 0 to the last position of barcodes.
Pick. The spot is best. The chosen is item spot of labels. Place chosen into result. The place is best. Decrease item place of counts by 1. Set previous to chosen.

For each code in result, Show code.

Expected stdout

1
2
1
2
1
3

Open in Playground Standalone Page

#1061 · Lexicographically Smallest Equivalent String

Medium String

Keep a shared alphabet as empty text. Keep a shared targetcode of 0. Keep a shared rankresult of 0. Keep a shared parents as an empty list of whole numbers. Keep a shared rootletter of 0.

To rank.
For every probe from 0 to 25.
If character probe of alphabet is targetcode, set rankresult to probe, return.

To seek from letter (a whole number). If item letter of parents is letter, set rootletter to letter, return. Seek from item letter of parents.

The letters is "abcdefghijklmnopqrstuvwxyz". The frozen is a copy of letters. Set alphabet to frozen.
For every spot from 0 to 25.
Place spot into parents.

The first is "parker". The second is "morris". The base is "parser".
For every spot from 0 to the last position of first.
Set targetcode to character spot of first. Rank. The left is rankresult. Set targetcode to character spot of second. Rank. The right is rankresult. Seek from left. The firstroot is rootletter. Seek from right. The secondroot is rootletter. If firstroot is less than secondroot, set item secondroot of parents to firstroot. If secondroot is less than firstroot, set item firstroot of parents to secondroot.

The answer is empty text.
For every spot from 0 to the last position of base.
Set targetcode to character spot of base. Rank. Seek from rankresult. The place is rootletter. The mapped is character place of alphabet. Place mapped into answer.

Show answer.

Expected stdout

makkek

Open in Playground Standalone Page

#1071 · Greatest Common Divisor of Strings

Easy String

Keep a shared leftsize of 0. Keep a shared rightsize of 0.

To reduce.
Repeat while rightsize is more than 0.
The rest is leftsize modulo rightsize. Set leftsize to rightsize. Set rightsize to rest.

The first is "ABCABC". The second is "ABC". The joined is a copy of first. Place second into joined. The other is a copy of second. Place first into other. The firstlast is the last position of first. The secondlast is the last position of second. Set leftsize to firstlast plus 1. Set rightsize to secondlast plus 1. Reduce. The span is leftsize. The piece is the slice of first from 0 to span. The answer is a copy of piece. The empty is empty text. The same is 0. If joined matches other, set same to 1. If same is 0, set answer to empty. Show answer.

Expected stdout

ABC

Open in Playground Standalone Page

#1072 · Flip Columns For Maximum Number of Equal Rows

Medium Array

The grid is a list of 0, 1, 1, and 0. The rows is 2. The columns is 2. The keys is an empty list of whole numbers.
For every row from 0 to rows minus 1.
The anchor is item (row times columns) of grid. The key is 0.
For every column from 0 to columns minus 1.
The cell is item (row times columns plus column) of grid. The bit is exclusive or of cell and anchor. Set key to key times 3 plus bit. Place key into keys.

The best is 0.
For each key in keys.
The count is 0.
For each other in keys.
If other is key, add 1 to count. If count is more than best, set best to count.

Show best.

Expected stdout

2

Open in Playground Standalone Page

#1073 · Adding Two Negabinary Numbers

Medium Array

The first is a list of 1, 1, 1, 1, and 1. The second is a list of 1, 0, and 1. The firstspot is the last position of first. The secondspot is the last position of second. The carry is 0. The digits is an empty list of whole numbers.
Repeat while firstspot is at least 0 or secondspot is at least 0 or carry is not 0.
The firstbit is 0. If firstspot is at least 0, set firstbit to item firstspot of first. The secondbit is 0. If secondspot is at least 0, set secondbit to item secondspot of second. The total is carry plus firstbit plus secondbit. If firstspot is at least 0, subtract 1 from firstspot. If secondspot is at least 0, subtract 1 from secondspot. The bit is total modulo 2. If bit is less than 0, add 2 to bit. Place bit into digits. Set carry to (total minus bit) divided by (0 minus 2).

The last is the last position of digits.
Repeat while last is more than 0 and item last of digits is 0.
Remove the last item from digits. Set last to the last position of digits.

For every step from 0 to last.
The place is last minus step. Show item place of digits.

Expected stdout

1
0
0
0
0

Open in Playground Standalone Page

#1074 · Number of Submatrices That Sum to Target

Hard Array

The grid is a list of 0, 1, 0, 1, 1, 1, 0, 1, and 0. The rows is 3. The columns is 3. The width is 4. The target is 0. The prefix is a list of 16 zeros.
For every row from 0 to rows minus 1.
For every column from 0 to columns minus 1.
The index is (row plus 1) times width plus column plus 1. The above is index minus width. The before is index minus 1. The corner is index minus width minus 1. The cell is item (row times columns plus column) of grid. Set item index of prefix to item above of prefix plus item before of prefix minus item corner of prefix plus cell.

The total is 0.
For every top from 0 to rows minus 1.
For every bottom from top to rows minus 1.
For every left from 0 to columns minus 1.
For every right from left to columns minus 1.
The bottomright is (bottom plus 1) times width plus right plus 1. The topright is top times width plus right plus 1. The bottomleft is (bottom plus 1) times width plus left. The topleft is top times width plus left. The measured is item bottomright of prefix minus item topright of prefix minus item bottomleft of prefix plus item topleft of prefix. If measured is target, add 1 to total.

Show total.

Expected stdout

4

Open in Playground Standalone Page

#1078 · Occurrences After Bigram

Easy String

The sentence is "alice is a good girl she is a good student". The firstraw is "a". The secondraw is "good". The first is empty text. Place firstraw into first. The second is empty text. Place secondraw into second. The parts is split sentence by " ". The answers is an empty list of text. The last is the last position of parts.
For every spot from 0 to last minus 2.
The leftraw is item spot of parts. The middleraw is item (spot plus 1) of parts. The rightraw is item (spot plus 2) of parts. The leftword is empty text. Place leftraw into leftword. The middleword is empty text. Place middleraw into middleword. The rightword is empty text. Place rightraw into rightword. The leftsame is 0. If leftword matches first, set leftsame to 1. The middlesame is 0. If middleword matches second, set middlesame to 1. If leftsame is 1 and middlesame is 1, Place rightword into answers.

For each word in answers, Show word.

Expected stdout

girl
student

Open in Playground Standalone Page

#1079 · Letter Tile Possibilities

Medium String

Keep a shared source as empty text. Keep a shared letters as empty text. Keep a shared targetcode of 0. Keep a shared rankresult of 0. Keep a shared used as an empty list of whole numbers. Keep a shared codes as an empty list of whole numbers. Keep a shared total of 0.

To rank.
For every probe from 0 to 25.
If character probe of letters is targetcode, set rankresult to probe, return.

To climb from code (a whole number).
For every spot from 0 to the last position of source.
If item spot of used is 0, Step from spot with code.

To step from spot (a whole number) with code (a whole number). Set item spot of used to 1. Set targetcode to character spot of source. Rank. The next is code times 27 plus rankresult plus 1. If codes does not contain next, Place next into codes, add 1 to total. Climb from next. Set item spot of used to 0.

The given is "AAB". Set source to a copy of given. The alphabet is "ABCDEFGHIJKLMNOPQRSTUVWXYZ". The frozen is a copy of alphabet. Set letters to frozen.
For every spot from 0 to the last position of source.
Place 0 into used.

Climb from 0. Show total.

Expected stdout

8

Open in Playground Standalone Page

#1080 · Insufficient Nodes in Root to Leaf Paths

Medium Depth-First Search

Keep a shared values as an empty list of whole numbers. Keep a shared lefts as an empty list of whole numbers. Keep a shared rights as an empty list of whole numbers. Keep a shared gone as an empty list of whole numbers. Keep a shared cap of 0. Keep a shared result of 0. Set cap to 22. Place 5 into values. Place 4 into values. Place 8 into values. Place 11 into values. Place 0 into values. Place 17 into values. Place 4 into values. Place 7 into values. Place 1 into values. Place 0 into values. Place 0 into values. Place 5 into values. Place 3 into values. Place 1 into lefts. Place 3 into lefts. Place 5 into lefts. Place 7 into lefts. Place -1 into lefts. Place -1 into lefts. Place 11 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place -1 into lefts. Place 2 into rights. Place -1 into rights. Place 6 into rights. Place 8 into rights. Place -1 into rights. Place -1 into rights. Place 12 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights. Place -1 into rights.
For every spot from 0 to 12.
Place 0 into gone.

To prune from node (a whole number) with total (a whole number). If node is less than 0, set result to -1000000000, return. The value is item node of values. The here is total plus value. The left is item node of lefts. The right is item node of rights. The leftbest is 0. The rightbest is 0. If left is at least 0, Prune from left with here, set leftbest to result. If right is at least 0, Prune from right with here, set rightbest to result. The best is -1000000000. If left is less than 0 and right is less than 0, set best to here. If left is at least 0 and leftbest is more than best, set best to leftbest. If right is at least 0 and rightbest is more than best, set best to rightbest. If best is less than cap, set item node of gone to 1. If best is at least cap, set item node of gone to 0. If left is at least 0 and item left of gone is 1, set item node of lefts to -1. If right is at least 0 and item right of gone is 1, set item node of rights to -1. Set result to best.

Prune from 0 with 0. The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1. The pieces is an empty list of text.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The piece is empty text. If node is at least 0, set piece to format whole number item node of values as text. If node is at least 0, Place piece into pieces. If node is less than 0, Place "null" into pieces. If node is at least 0 and item node of gone is 0, Place item node of lefts into queue, Place item node of rights into queue, add 2 to count.

Repeat while the last position of pieces is at least 0.
The tail is the last position of pieces. The tailpiece is item tail of pieces. The isnull is 0. If tailpiece matches "null", set isnull to 1. If isnull is 1, remove the last item from pieces. If isnull is 0, stop.

The line is join pieces with ",". Show line.

Expected stdout

5,4,8,11,null,17,4,7,null,null,null,5

Open in Playground Standalone Page

#1081 · Smallest Subsequence of Distinct Characters

Medium String

Keep a shared alphabet as empty text. Keep a shared targetcode of 0. Keep a shared rankresult of 0. Keep a shared remaining as an empty list of whole numbers. Keep a shared used as an empty list of whole numbers. Keep a shared stack as an empty list of whole numbers.

To rank.
For every probe from 0 to 25.
If character probe of alphabet is targetcode, set rankresult to probe, return.

To trim from code (a whole number). The stacklast is the last position of stack. The topcode is 0. If stacklast is at least 0, set topcode to item stacklast of stack.
Repeat while topcode is more than code and item topcode of remaining is more than 0.
Remove the last item from stack. Set item topcode of used to 0. Set stacklast to the last position of stack. Set topcode to 0. If stacklast is at least 0, set topcode to item stacklast of stack.

The source is "cbacdcbc". The letters is "abcdefghijklmnopqrstuvwxyz". The frozen is a copy of letters. Set alphabet to frozen.
For every spot from 0 to 25.
Place 0 into remaining. Place 0 into used.

For every spot from 0 to the last position of source.
Set targetcode to character spot of source. Rank. The code is rankresult. Increase item code of remaining by 1.

For every spot from 0 to the last position of source.
Set targetcode to character spot of source. Rank. The code is rankresult. Decrease item code of remaining by 1. The fresh is 1. If item code of used is 1, set fresh to 0. If fresh is 1, Trim from code. If fresh is 1, Place code into stack, set item code of used to 1.

The answer is empty text.
For each code in stack.
The letter is character code of alphabet. Place letter into answer.

Show answer.

Expected stdout

acdb

Open in Playground Standalone Page

#1089 · Duplicate Zeros

Easy Array

The numbers is a list of 1, 0, 2, 3, 0, 4, 5, and 0. The last is the last position of numbers. The size is last plus 1. The answers is a list of 8 zeros. The written is 0.
For every spot from 0 to size minus 1.
The value is item spot of numbers. If written is less than size, set item written of answers to value, add 1 to written. If value is 0 and written is less than size, set item written of answers to 0, add 1 to written.

For each value in answers, show value.

Expected stdout

1
0
0
2
3
0
0
4

Open in Playground Standalone Page

#1090 · Largest Values From Labels

Medium Array

The values is a list of 5, 4, 3, 2, and 1. The labels is a list of 1, 1, 2, 2, and 3. The wanted is 3. The limit is 1. The ranked is an empty list of whole numbers. The tags is an empty list of whole numbers.
For every spot from 0 to the last position of values.
The value is item spot of values. The tag is item spot of labels. Place value into ranked. Place tag into tags. The place is the last position of ranked.
Repeat while place is more than 0 and item (place minus 1) of ranked is less than value.
Set item place of ranked to item (place minus 1) of ranked. Set item place of tags to item (place minus 1) of tags. Subtract 1 from place. Set item place of ranked to value. Set item place of tags to tag.

The used is a list of 4 zeros. The total is 0. The taken is 0.
For every spot from 0 to the last position of ranked.
If taken is less than wanted.
The tag is item spot of tags.
If item tag of used is less than limit.
Increase item tag of used by 1. The value is item spot of ranked. Add value to total. Add 1 to taken.

Show total.

Expected stdout

9

Open in Playground Standalone Page

#1091 · Shortest Path in Binary Matrix

Medium Array

The board is a list of 0, 0, 0, 1, 1, 0, 1, 1, and 0. The side is 3. The downsteps is a list of -1, -1, -1, 0, 0, 1, 1, and 1. The sidesteps is a list of -1, 0, 1, -1, 1, -1, 0, and 1. The distances is a list of 9 zeros. The queue is a list of 81 zeros. The head is 0. The count is 0. The answer is -1.
If item 0 of board is 0.
Set item 0 of distances to 1. Set item 0 of queue to 0. Set count to 1.

Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The band is node divided by side. The column is node modulo side. The depth is item node of distances plus 1.
For every step from 0 to 7.
The nextband is band plus item step of downsteps. The nextcolumn is column plus item step of sidesteps.
If nextband is at least 0 and nextband is less than side and nextcolumn is at least 0 and nextcolumn is less than side.
The target is nextband times side plus nextcolumn.
If item target of board is 0 and item target of distances is 0.
Set item target of distances to depth. Set item count of queue to target. Add 1 to count.

If item 8 of distances is more than 0, set answer to item 8 of distances. Show answer.

Expected stdout

4

Open in Playground Standalone Page

#1092 · Shortest Common Supersequence

Hard String

The first is "abac". The second is "cab". The awidth is the length of first. The bwidth is the length of second. The width is bwidth plus 1. The table is an empty list of whole numbers.
For every spot from 0 to (awidth plus 1) times width minus 1.
Place 0 into table.

For every band from 1 to awidth.
For every column from 1 to bwidth.
The above is item ((band minus 1) times width plus column) of table. The beside is item (band times width plus column minus 1) of table. The corner is item ((band minus 1) times width plus column minus 1) of table. The best is above. If beside is more than best, set best to beside. The aat is band minus 1. The bat is column minus 1. The firstsymbol is character aat of first. The secondsymbol is character bat of second. If firstsymbol is secondsymbol, set best to corner plus 1. Set item (band times width plus column) of table to best.

The parts is an empty list of text. The band is awidth. The column is bwidth.
Repeat while band is more than 0 and column is more than 0.
The aat is band minus 1. The bat is column minus 1. The firstsymbol is character aat of first. The secondsymbol is character bat of second. The upper is item (aat times width plus column) of table. The lower is item (band times width plus bat) of table. If firstsymbol is secondsymbol, The piece is the slice of first from aat to band, Place piece into parts, Subtract 1 from band, Subtract 1 from column. If firstsymbol is not secondsymbol and upper is at least lower, The piece is the slice of first from aat to band, Place piece into parts, Subtract 1 from band. If firstsymbol is not secondsymbol and upper is less than lower, The piece is the slice of second from bat to column, Place piece into parts, Subtract 1 from column.

Repeat while band is more than 0.
The aat is band minus 1. The piece is the slice of first from aat to band. Place piece into parts. Subtract 1 from band.

Repeat while column is more than 0.
The bat is column minus 1. The piece is the slice of second from bat to column. Place piece into parts. Subtract 1 from column.

The answer is an empty list of text. The spot is the last position of parts.
Repeat while spot is at least 0.
Place item spot of parts into answer. Subtract 1 from spot.

The line is join answer with "". Show line.

Expected stdout

cabac

Open in Playground Standalone Page

#1093 · Statistics from a Large Sample

Medium Array

The counts is a list of 256 zeros. Set item 1 of counts to 1. Set item 2 of counts to 3. Set item 3 of counts to 4. The total is 0. The weighted is 0. The low is -1. The high is -1. The best is 0. The mode is 0.
For every value from 0 to 255.
The seen is item value of counts. If seen is more than 0 and low is less than 0, set low to value. If seen is more than 0, set high to value. Add seen to total. The contribution is seen times value. Add contribution to weighted. If seen is more than best, set best to seen, set mode to value.

The order is (total minus 1) divided by 2. The other is total divided by 2. The lower is 0. The upper is 0. The running is 0.
For every value from 0 to 255.
The seen is item value of counts. The before is running. Add seen to running. If order is at least before and order is less than running, set lower to value. If other is at least before and other is less than running, set upper to value.

Keep a shared rendered as empty text.
To render from scaled (a whole number). The parts is an empty list of text. The whole is scaled divided by 100000. The rest is scaled modulo 100000. The head is format whole number whole as text. Place head into parts. Place "." into parts. The remaining is rest.
For every slot from 0 to 4.
The unit is remaining divided by 10000. The digit is format whole number unit as text. Place digit into parts. Set remaining to (remaining modulo 10000) times 10. Set rendered to join parts with "".

The answers is an empty list of text. The lowscale is low times 100000. Render from lowscale. Place rendered into answers. The highscale is high times 100000. Render from highscale. Place rendered into answers. The meanscale is (weighted times 100000 plus total divided by 2) divided by total. Render from meanscale. Place rendered into answers. The medianscale is (lower plus upper) times 50000. Render from medianscale. Place rendered into answers. The modescale is mode times 100000. Render from modescale. Place rendered into answers.

The report is join answers with ",". Show report.

Expected stdout

1.00000,3.00000,2.37500,2.50000,3.00000

Open in Playground Standalone Page

#1094 · Car Pooling

Medium Array

The trips is a list of 2, 1, 5, 3, 3, and 7. The capacity is 4. The changes is a list of 1001 zeros.
For every trip from 0 to 1.
The base is trip times 3. The riders is item base of trips. The start is item (base plus 1) of trips. The finish is item (base plus 2) of trips. Increase item start of changes by riders. Decrease item finish of changes by riders.

The current is 0. The overloaded is 0.
For every place from 0 to 1000.
The change is item place of changes. Add change to current. If current is more than capacity, set overloaded to 1.

If overloaded is 1, show false, otherwise show true.

Expected stdout

false

Open in Playground Standalone Page

#1096 · Brace Expansion II

Hard String

Keep a shared current as empty text. Keep a shared pending as an empty list of text. Keep a shared finished as an empty list of text. Keep a shared pool as an empty list of text. Keep a shared prefix as empty text. Keep a shared suffix as empty text. Keep a shared inside as empty text. Keep a shared option as empty text. Keep a shared open of 0. Keep a shared close of 0. Keep a shared total of 0. Keep a shared order of 0. Keep a shared same of 0. Keep a shared candidate as empty text.

To uncover. Set open to -1. The place is 0. The last is the last position of current.
Repeat while place is at most last and open is less than 0.
The symbol is the slice of current from place to place plus 1. If symbol matches "{", set open to place. Add 1 to place.

To enclose. Set close to -1. The depth is 0. The walk is 0. The last is the last position of current.
Repeat while walk is at most last and close is less than 0.
The symbol is the slice of current from walk to walk plus 1. If symbol matches "{", add 1 to depth. If symbol matches "}", subtract 1 from depth. The closing is 0. If symbol matches "}", set closing to 1. If closing is 1 and depth is 0, set close to walk. Add 1 to walk.

To extend. The parts is a list of prefix, option, and suffix. The combined is join parts with "". Place combined into pending. Add 1 to total.

To expand inside. The start is 0. The level is 0. The spot is 0. The last is the last position of inside.
Repeat while spot is at most last.
The symbol is the slice of inside from spot to spot plus 1. If symbol matches "{", add 1 to level. If symbol matches "}", subtract 1 from level. The comma is 0. If symbol matches ",", set comma to 1. If comma is 1 and level is 0, The mark is spot, The piece is the slice of inside from start to mark, Set option to piece, Extend, Set start to spot plus 1. If spot is last, The finish is spot plus 1, The piece is the slice of inside from start to finish, Set option to piece, Extend. Add 1 to spot.

To search. Set same to 0. The spot is 0. The last is the last position of pool.
Repeat while spot is at most last and same is 0.
The other is item spot of pool. If other matches candidate, set same to 1. Add 1 to spot.

To compare from left (a whole number) with right (a whole number). Set order to 0. The first is item left of pool. The second is item right of pool. The firstsize is the length of first. The secondsize is the length of second. The span is firstsize. If secondsize is less than span, set span to secondsize.
For every spot from 0 to span minus 1.
The firstsymbol is character spot of first. The secondsymbol is character spot of second. If order is 0 and firstsymbol is less than secondsymbol, set order to -1. If order is 0 and firstsymbol is more than secondsymbol, set order to 1. If order is 0 and firstsize is less than secondsize, set order to -1. If order is 0 and firstsize is more than secondsize, set order to 1.

The source is "{a,b}{c,{d,e}}". Set current to a copy of source. The seed is a copy of source. Place seed into pending. Set total to 1. The front is 0.
Repeat while front is less than total.
The chosen is item front of pending. The next is a copy of chosen. Set current to a copy of next. Add 1 to front. Uncover. If open is less than 0, Place current into finished. If open is at least 0, Enclose. If open is at least 0, Set prefix to the slice of current from 0 to open. If open is at least 0, The begin is open plus 1, Set inside to the slice of current from begin to close. If open is at least 0, The tail is close plus 1, The end is the last position of current, The final is end plus 1, Set suffix to the slice of current from tail to final. If open is at least 0, Expand inside.

For every spot from 0 to the last position of finished.
The piece is item spot of finished. Set candidate to a copy of piece. Search. If same is 0, Place candidate into pool.

The lastpool is the last position of pool.
For every spot from 0 to lastpool minus 1.
For every probe from spot plus 1 to lastpool.
Compare from spot with probe. If order is more than 0, swap item spot of pool and item probe of pool.

For each piece in pool, show piece.

Expected stdout

ac
ad
ae
bc
bd
be

Open in Playground Standalone Page

#1103 · Distribute Candies to People

Easy Math

The candies is 7. The people is 4. The shares is a list of 4 zeros. The given is 0. The turn is 1.
Repeat while candies is more than 0.
The person is given modulo people. The gift is turn. If gift is more than candies, set gift to candies. Increase item person of shares by gift. Subtract gift from candies. Add 1 to turn. Add 1 to given.

For each share in shares, show share.

Expected stdout

1
2
3
1

Open in Playground Standalone Page

#1104 · Path In Zigzag Labelled Binary Tree

Medium Math

The label is 14. The answers is an empty list of whole numbers. The node is label. Keep a shared base of 0. Keep a shared depth of 0.
To measure from value (a whole number). Set base to 1. Set depth to 0.
Repeat while base times 2 is at most value.
Set base to base times 2. Add 1 to depth.

Repeat while node is more than 0.
Place node into answers. Measure from node. The index is node minus base. The width is base minus 1. The mirror is width minus index. The parent is base divided by 2 plus mirror divided by 2. Set node to parent.

The spot is the last position of answers.
Repeat while spot is at least 0.
Show item spot of answers. Subtract 1 from spot.

Expected stdout

1
3
4
14

Open in Playground Standalone Page

#1105 · Filling Bookcase Shelves

Medium Array

The thickness is a list of 1, 2, 2, 1, 1, 1, and 1. The tallness is a list of 1, 3, 3, 1, 1, 1, and 2. The shelf is 4. The count is 7. The costs is a list of 8 zeros. Set item 0 of costs to 0.
For every book from 1 to count.
Set item book of costs to 1000000. The width is 0. The height is 0. The start is book minus 1. The need is item start of thickness.
Repeat while start is at least 0 and need is at most shelf.
The thick is item start of thickness. The tall is item start of tallness. Add thick to width. If tall is more than height, set height to tall. The candidate is item start of costs plus height. If candidate is less than item book of costs, set item book of costs to candidate. Subtract 1 from start. If start is at least 0, The nextthick is item start of thickness, set need to width plus nextthick.

Show item count of costs.

Expected stdout

6

Open in Playground Standalone Page

#1106 · Parsing A Boolean Expression

Hard String

Keep a shared source as empty text. Place "|(&(t,f,t),!(t))" into source. Keep a shared cursor of 0. Keep a shared value of 0.
To parse. The index is cursor. The symbol is the slice of source from index to index plus 1. If symbol matches "t", set value to 1, add 1 to cursor, return. If symbol matches "f", set value to 0, add 1 to cursor, return. If symbol matches "!", Negate. If symbol matches "&", Conjoin. If symbol matches "|", Disjoin.

To negate. Add 2 to cursor. Parse. The inside is value. Add 1 to cursor. Set value to 1 minus inside.

To conjoin. Add 2 to cursor. The total is 1. The index is cursor. The symbol is the slice of source from index to index plus 1.
Repeat while symbol does not match ")".
Parse. Set total to total times value. The index is cursor. The symbol is the slice of source from index to index plus 1. If symbol matches ",", add 1 to cursor. If symbol matches ")", add 1 to cursor. Set value to total.

To disjoin. Add 2 to cursor. The total is 0. The index is cursor. The symbol is the slice of source from index to index plus 1.
Repeat while symbol does not match ")".
Parse. Increase total by value. The index is cursor. The symbol is the slice of source from index to index plus 1. If symbol matches ",", add 1 to cursor. If symbol matches ")", add 1 to cursor. Set value to total.

Parse. If value is 1, show true, otherwise show false.

Expected stdout

false

Open in Playground Standalone Page

#1108 · Defanging an IP Address

Easy String

The source is "1.1.1.1". The parts is an empty list of text.
For every spot from 0 to the last position of source.
The symbol is the slice of source from spot to spot plus 1. If symbol matches ".", Place "[.]" into parts, otherwise Place symbol into parts.

The result is join parts with "". Show result.

Expected stdout

1[.]1[.]1[.]1

Open in Playground Standalone Page

#1109 · Corporate Flight Bookings

Medium Array

The bookings is a list of 1, 2, 10, 2, 3, 20, 2, 5, and 25. The flights is 5. The changes is a list of 7 zeros.
For every booking from 0 to 2.
The base is booking times 3. The first is item base of bookings. The last is item (base plus 1) of bookings. The seats is item (base plus 2) of bookings. Increase item (first minus 1) of changes by seats. Decrease item last of changes by seats.

The running is 0.
For every flight from 0 to flights minus 1.
The change is item flight of changes. Add change to running. Show running.

Expected stdout

10
55
45
25
25

Open in Playground Standalone Page

#1110 · Delete Nodes And Return Forest

Medium Array

Keep a shared values holding 1, 2, 3, 4, 5, 6, and 7. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, -1, -1, and -1. Keep a shared removed holding 0, 0, 0, 0, 0, 0, and 0. Set item 2 of removed to 1. Set item 4 of removed to 1. Keep a shared roots as an empty list of whole numbers. Keep a shared order as an empty list of whole numbers. Keep a shared begin of 0. Keep a shared final of 0.

To discard from node (a whole number). The left is item node of lefts. The right is item node of rights. If left is at least 0, Prune from left with 1. If right is at least 0, Prune from right with 1.

To prune from node (a whole number) with rootflag (a whole number). If node is less than 0, return. If item node of removed is 1, Discard from node, return. If rootflag is 1, Place node into roots. The left is item node of lefts. The right is item node of rights. If left is at least 0 and item left of removed is 0, Prune from left with 0. If left is at least 0 and item left of removed is 1, Set item node of lefts to -1, Prune from left with 1. If right is at least 0 and item right of removed is 0, Prune from right with 0. If right is at least 0 and item right of removed is 1, Set item node of rights to -1, Prune from right with 1.

To walk from start (a whole number). The queue is a list of 64 zeros. Set item 0 of queue to start. The head is 0. The count is 1.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The content is 0. The left is 0. The right is 0. If node is at least 0, set content to item node of values. If node is at least 0, set left to item node of lefts. If node is at least 0, set right to item node of rights. If node is less than 0, Place -1 into order. If node is at least 0, Place content into order. If node is at least 0, The slotone is count, Set item slotone of queue to left, Add 1 to count. If node is at least 0, The slottwo is count, Set item slottwo of queue to right, Add 1 to count.

To trim. The spot is the last position of order. Set final to spot.
Repeat while spot is at least begin and item spot of order is -1.
Decrease spot by 1. Set final to spot.

To display. The parts is an empty list of text.
For every slot from begin to final.
The value is item slot of order. The piece is format whole number value as text. Place piece into parts. If slot is final, The line is join parts with ",", Show line.

Prune from 0 with 1.
For every which from 0 to the last position of roots.
The start is item which of roots. The prior is the last position of order. Set begin to prior plus 1. Walk from start. Trim. Display.

Expected stdout

1,2,-1,4
6
7

Open in Playground Standalone Page

#1111 · Maximum Nesting Depth of Two Valid Parentheses Strings

Medium String

The sequence is "(()())". The answers is an empty list of whole numbers. The depth is 0. The last is the last position of sequence.
For every spot from 0 to last.
The symbol is the slice of sequence from spot to spot plus 1. If symbol matches "(", The opening is depth modulo 2, Place opening into answers, Add 1 to depth. If symbol matches ")", subtract 1 from depth. If symbol matches ")", The closing is depth modulo 2, Place closing into answers.

The parts is an empty list of text.
For each choice in answers.
The piece is format whole number choice as text. Place piece into parts.

The line is join parts with ",". Show line.

Expected stdout

0,1,1,1,1,0

Open in Playground Standalone Page

#1122 · Relative Sort Array

Easy Array

The numbers is a list of 2, 3, 1, 3, 2, 4, 6, 7, 9, 2, and 19. The wanted is a list of 2, 1, 4, 3, 9, and 6. The counts is a list of 1001 zeros.
For each value in numbers.
Increase item value of counts by 1.

The answers is an empty list of whole numbers.
For every spot from 0 to the last position of wanted.
The value is item spot of wanted. The many is item value of counts. Set item value of counts to 0.
For every repeat from 1 to many.
Place value into answers.

For every value from 0 to 1000.
The many is item value of counts.
If many is more than 0.
For every repeat from 1 to many.
Place value into answers.

The parts is an empty list of text.
For each value in answers.
The piece is format whole number value as text. Place piece into parts.

The line is join parts with ",". Show line.

Expected stdout

2,2,2,1,4,3,3,9,6,7,19

Open in Playground Standalone Page

#1123 · Lowest Common Ancestor of Deepest Leaves

Medium Depth-First Search

Keep a shared values holding 3, 5, 1, 6, 2, 0, 8, -1, -1, 7, and 4. Keep a shared lefts holding 1, 3, 5, -1, 9, -1, -1, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, 10, -1, -1, -1, -1, -1, and -1. Keep a shared depths as an empty list of whole numbers.
For every node from 0 to 10.
Place 0 into depths.

Keep a shared ancestors as an empty list of whole numbers.
For every node from 0 to 10.
Place 0 into ancestors.

To score from node (a whole number). If node is less than 0, return. The left is item node of lefts. The right is item node of rights. Score from left. Score from right. The leftdepth is -1. If left is at least 0, set leftdepth to item left of depths. The rightdepth is -1. If right is at least 0, set rightdepth to item right of depths. If leftdepth is more than rightdepth, Set item node of depths to leftdepth plus 1, Set item node of ancestors to item left of ancestors. If rightdepth is more than leftdepth, Set item node of depths to rightdepth plus 1, Set item node of ancestors to item right of ancestors. If leftdepth is rightdepth, Set item node of depths to leftdepth plus 1, Set item node of ancestors to node.

Score from 0. The answer is item 0 of ancestors. The queue is a list of 32 zeros. Set item 0 of queue to answer. The head is 0. The count is 1. The order is an empty list of whole numbers.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The value is item node of values. Place value into order. The left is item node of lefts. The right is item node of rights. If left is at least 0, Set item count of queue to left, Add 1 to count. If right is at least 0, Set item count of queue to right, Add 1 to count.

The parts is an empty list of text.
For each value in order.
The piece is format whole number value as text. Place piece into parts.

The line is join parts with ",". Show line.

Expected stdout

2,7,4

Open in Playground Standalone Page

#1124 · Longest Well-Performing Interval

Medium Array

The hours is a list of 9, 9, 6, 0, 6, 6, and 9. The count is 7. The offset is count. The earliest is a list of 15 zeros.
For every spot from 0 to 14.
Set item spot of earliest to -2.

The score is 0. The best is 0.
For every spot from 0 to count minus 1.
The value is item spot of hours. If value is more than 8, add 1 to score, otherwise subtract 1 from score. The length is 0. If score is more than 0, set length to spot plus 1. The prior is score minus 1 plus offset. The seen is -2. If prior is at least 0, set seen to item prior of earliest. If score is at most 0 and seen is not -2, set length to spot minus seen. If length is more than best, set best to length. The here is score plus offset. If item here of earliest is -2, set item here of earliest to spot.

Show best.

Expected stdout

3

Open in Playground Standalone Page

#1125 · Smallest Sufficient Team

Hard Array

The requireds is a list of "java", "nodejs", and "reactjs". The skills is a list of "java", "nodejs", "nodejs", and "reactjs". The starts is a list of 0, 1, and 2. The counts is a list of 1, 1, and 2. The masks is a list of 3 zeros.
For every person from 0 to 2.
The mask is 0.
For every want from 0 to 2.
The required is item want of requireds. The bit is shift 1 left by want. The begin is item person of starts. The many is item person of counts. The finish is begin plus many minus 1.
For every entry from begin to finish.
The skill is item entry of skills. If skill matches required, set mask to bitwise or of mask and bit. Set item person of masks to mask.

The best is a list of 8 zeros. Set item 0 of best to 0.
For every state from 1 to 7.
Set item state of best to 1000000.

The chooser is a list of 8 zeros. The previous is a list of 8 zeros. The full is 7.
For every person from 0 to 2.
The gain is item person of masks. The state is full.
Repeat while state is at least 0.
The here is item state of best. The nextstate is bitwise or of state and gain. The candidate is here plus 1. If here is less than 1000000 and candidate is less than item nextstate of best, Set item nextstate of best to candidate, Set item nextstate of chooser to person, Set item nextstate of previous to state. Subtract 1 from state.

The answers is an empty list of whole numbers. The state is full.
Repeat while state is more than 0.
The person is item state of chooser. Place person into answers. The prior is item state of previous. Set state to prior.

The parts is an empty list of text. The spot is the last position of answers.
Repeat while spot is at least 0.
The person is item spot of answers. The piece is format whole number person as text. Place piece into parts. Subtract 1 from spot.

The line is join parts with ",". Show line.

Expected stdout

0,2

Open in Playground Standalone Page

#1128 · Number of Equivalent Domino Pairs

Easy Array

The dominoes is a list of 1, 2, 2, 1, 3, 4, 5, and 6. The counts is a list of 100 zeros. The total is 0.
For every domino from 0 to 3.
The base is domino times 2. The one is item base of dominoes. The other is item (base plus 1) of dominoes. The low is one. The high is other. If one is more than other, set low to other, set high to one. The key is low times 10 plus high. The seen is item key of counts. Add seen to total. Set item key of counts to seen plus 1.

Show total.

Expected stdout

1

Open in Playground Standalone Page

#1129 · Shortest Path with Alternating Colors

Medium Breadth-First Search

Keep a shared reds as a list of 9 zeros. Set item 1 of reds to 1. Set item 5 of reds to 1. Keep a shared blues as a list of 9 zeros. Keep a shared nodes as an empty list of whole numbers. Keep a shared colors as an empty list of whole numbers. Keep a shared steps as an empty list of whole numbers. Keep a shared seen as a list of 6 zeros. Keep a shared answers holding -1, -1, and -1. Keep a shared count of 0. Keep a shared head of 0. Place 0 into nodes. Place 0 into colors. Place 0 into steps. Place 0 into nodes. Place 1 into colors. Place 0 into steps. Set count to 2. Set item 0 of seen to 1. Set item 1 of seen to 1.

Repeat while head is less than count.
The front is head. The currentnode is item front of nodes. The currentcolor is item front of colors. The currentstep is item front of steps. Add 1 to head. If item currentnode of answers is -1, set item currentnode of answers to currentstep. The nextcolor is 1 minus currentcolor.
For every next from 0 to 2.
The edge is 0. If nextcolor is 0 and item (currentnode times 3 plus next) of reds is 1, set edge to 1. If nextcolor is 1 and item (currentnode times 3 plus next) of blues is 1, set edge to 1. The mark is next times 2 plus nextcolor. If edge is 1 and item mark of seen is 0, set item mark of seen to 1, Place next into nodes, Place nextcolor into colors, Place (currentstep plus 1) into steps, add 1 to count.

For each value in answers, show value.

Expected stdout

0
1
-1

Open in Playground Standalone Page

#1130 · Minimum Cost Tree From Leaf Values

Medium Array

The leaves is a list of 6, 2, and 4. The count is 3. The costs is a list of 9 zeros. The peaks is a list of 9 zeros.
For every spot from 0 to 2.
Set item (spot times count plus spot) of peaks to item spot of leaves.

For every span from 2 to count.
For every start from 0 to count minus span.
The end is start plus span minus 1. The best is 100000000. The tallpair is 0.
For every split from start to end minus 1.
The leftpeak is item (start times count plus split) of peaks. The rightpeak is item ((split plus 1) times count plus end) of peaks. The pair is leftpeak times rightpeak. The cost is item (start times count plus split) of costs plus item ((split plus 1) times count plus end) of costs plus pair. If cost is less than best, set best to cost, set tallpair to the larger of leftpeak and rightpeak. Set item (start times count plus end) of costs to best. Set item (start times count plus end) of peaks to tallpair.

Show item (count minus 1) of costs.

Expected stdout

32

Open in Playground Standalone Page

#1131 · Maximum of Absolute Value Expression

Medium Array

The firsts is a list of 1, 2, 3, and 4. The seconds is a list of -1, 4, 5, and 6. The best is 0.
For every left from 0 to 3.
For every right from 0 to 3.
The firstgap is the absolute value of (item left of firsts minus item right of firsts). The secondgap is the absolute value of (item left of seconds minus item right of seconds). The indexgap is the absolute value of (left minus right). The score is firstgap plus secondgap plus indexgap. If score is more than best, set best to score.

Show best.

Expected stdout

13

Open in Playground Standalone Page

#1137 · N-th Tribonacci Number

Easy Math

The wanted is 25. The older is 0. The middle is 1. The newer is 1. The spot is 3.
Repeat while spot is at most wanted.
The next is older plus middle plus newer. Set older to middle. Set middle to newer. Set newer to next. Add 1 to spot.

Show newer.

Expected stdout

1389537

Open in Playground Standalone Page

#1138 · Alphabet Board Path

Medium String

The target is "leet". The moves is an empty list of text. The line is 0. The column is 0. The last is the last position of target.
For every spot from 0 to last.
The symbol is character spot of target. The code is symbol minus character 0 of "a". The wantline is code divided by 5. The wantcolumn is code modulo 5. Repeat while line is less than wantline, Place "D" into moves, Add 1 to line. Repeat while line is more than wantline, Place "U" into moves, Subtract 1 from line. Repeat while column is less than wantcolumn, Place "R" into moves, Add 1 to column. Repeat while column is more than wantcolumn, Place "L" into moves, Subtract 1 from column. Place "!" into moves.

The path is join moves with "". Show path.

Expected stdout

DDR!UURRR!!DDD!

Open in Playground Standalone Page

#1139 · Largest 1-Bordered Square

Medium Array

The grid is a list of 1, 1, 1, 1, 0, 1, 1, 1, and 1. The size is 3. The best is 0.
For every side from 1 to size.
For every top from 0 to size minus side.
For every left from 0 to size minus side.
The bottom is top plus side minus 1. The right is left plus side minus 1. The good is 1.
For every step from 0 to side minus 1.
The upper is item (top times size plus left plus step) of grid. The lower is item (bottom times size plus left plus step) of grid. The western is item ((top plus step) times size plus left) of grid. The eastern is item ((top plus step) times size plus right) of grid. If upper is 0, set good to 0. If lower is 0, set good to 0. If western is 0, set good to 0. If eastern is 0, set good to 0. If good is 1 and side times side is more than best, set best to side times side.

Show best.

Expected stdout

9

Open in Playground Standalone Page