,[>,]-[<]>>++[<[<+<+>>-]<[>+<-]>[>]>[>>[>>>>]>]++[-<+]-[<]<++[>>[>]>[>>[>>>>]>]+<++[-<+]-[<]<-]>>>-]>[>]>[>>[>>>>]<<<->>>>]+[-<+]-[<]>>[[>]>--<<[<]>>[[>]+[->+]+>>[>>>>]>--<+[-<+]-[<]>>-]>[>]+[->+]+>>--<+[-<+]-[<]<[>>[>]+[->+]+>>>>--<+[-<+]-[<]<-]>>[>]+[->+]+>++[-<+]-[<]>>]>[+>>[>>>>]>]<<<<<[<<<<]>>-<+[-<+]>>>>[>>>>]>[-[--<<<<<[<<<<]>>>>--[>>>>]>>>[>>>>]>>>--<+[-<+]++>>>>>>[>[<--<<<[-[>>>>>>+<<<<<+<-]>+<]>[<+>-]>>>>+++[<<<+[-<+]->[-[+[->+]->>>+<<<<+[-<+]->>+<-]>+<]>[<+>-]+[->+]->>-[<<<+[-<+]+>>>>-->+[->+]->>[<<<+>>>-]]<<<[>>>+<<<-]>>>]<<<+[-<+]+<<<<-->+[->+]->>>>>[-[<<+>>>+<-]>+<]>[<+>-]<<<<+++[+[->+]->[-[<<+[-<+]->>>++[->+]->>+<-]>+<]>[<+>-]<<<+[-<+]->>-[+[->+]+>>>>--<+[-<+]->>[<<<+>>>-]]<<<[>>>+<<<-]>>>]+[->+]+<<<<--<+[-<+]->-[>>[-]<<++++++[>++++++<-]>.[-]+<<<]<[>>>[<++++++[>++++++++<-]>.[-]<]<<<[<++++++++[<+++++++++++>-]<.[-]>]<]>>>>+<<++>]>[<+>-]>>]->+[->+]++[-<+]++++++++++.[-]]>]
Pruébalo en línea! o prueba la versión anterior con entrada entera
Un día de programación y tres días de corrección de errores ^^
Esto usa algunas partes de mi código de Game Of Life. En lugar de contar las células vivas, esto cuenta las bombas. Dado que la entrada como puntos de código está permitida por las reglas generales, esto los usa en lugar de enteros "legibles".
[
Data: colCount, rowCount, {BombCoordinates}, -1 (start of arrays/"soa"), 0, {RowData}
BombCoordinates: bombCol, bombRow
RowData: rowFlag, 0, {CellData}, 0
CellData: cellFlag, cellState, temp, bombCount
rowFlag: 0=EOF, 1=inactive (all cells inactive), 2=active
cellFlag: -1=marker for finding cell (cell to be counted or current cell), 0=EOF, 1=normal
cellState: 0=inactive, 1=normal, 2=bomb
temp: helper to exit if-statements
bombCount: count of neighbor cells that contain bombs
inactive cells or rows will not be printed. They are only used for an easier counting algorithm.
]
#### input values as codepoints ####
,[>,]
#### setup two dimensional array ####
- set soa
[<]>> go to rowCount
++ add two inactive rows
[ for each row
<[<+<+>>-] copy colCount two times to the next left cells
<[>+<-] move one of the copies back to the original cell
>[>]>[>>[>>>>]>] go to new row position
+ set rowFlag (only 1 while initialization)
+[-<+]-[<]< go to copy of colCount
++ add two inactive cells per row
[ for each col
>>[>]>[>>[>>>>]>] go to new cell position
+<+ set cellFlag and cellState = normal
+[-<+]-[<]< return to copy of colCount
- decrement
]
>>>- decrement rowCount
]
#### setup active/inactive flags of cells ####
>[>]>[ for each row
>>[>>>>]<<<- set last cell inactive
>>>> go to next row
]
#### mark the bombs ####
+[-<+]-[<]>> go to bombRow
[ while there are bombRow values left
[>]>-- set rowFlag of first row = neg 1 (as a marker)
<<[<]>> return to bombRow
[ for each bombRow
[>]+[->+] find first marker after soa
+ set rowFlag = 1
>>[>>>>]> go to next rowFlag
-- make a marker of it
<+[-<+]-[<]>> return to bombRow
- decrement
]
>[>]+[->+] go to selected rowFlag
+ set rowFlag = 1
>>-- set cellFlag of first cell = marker
<+[-<+]-[<]< go to bombCol
[ for each bombCol
>>[>]+[->+] find first marker after soa
+ set cellState = 1
>>>> go to next cellState
-- set it neg 1 (as a marker)
<+[-<+]-[<]< return to bombCol
- decrement
]
>>[>]+[->+] find first marker after soa
+ set cellFlag = normal
>+ set cellState = bomb
+[-<+]-[<]>> go to next bombRow
]
#### setup active/inactive flags of rows ####
>[ for each row
+ set rowFlag = 2 (active)
>>[>>>>]> go to next rowFlag
]
<<<<<[<<<<]>>- set rowFlag of last row = 1 (inactive)
#### count bombs in neighborhood ####
<+[-<+]>>>>[>>>>]> go to second row
[ for each row
-[ if active
-- set it neg 1 (marker)
<<<<<[<<<<]>>>> go to cellFlag of first cell in previous row
-- set it neg 1 (marker)
[>>>>]>>>[>>>>]>>> go to cellFlag of first cell in next row
-- set it neg 1 (marker)
<+[-<+] return to rowFlag
++ set rowFlag = 2 (active)
>> >>>>[ for each cell (starting with second)
>[ if active
<-- set cellFlag = neg 1 (marker)
# check if cell to the left is a bomb
< << go to cellState of previous cell
[ if active
-[ if bomb
>> >>>>+ increment bombCount
<<<< < go back to checked cell
+ set temp = 1
<- set cellState = 0 to exit if
]
>+< increment temp
]
>[<+>-] restore cellState
# check if cells on top are bombs
> >>> go to temp of current cell
+++[ do three times
<<<+[-<+]- go to next marker to the left
>[ if active
-[ if bomb
+[->+]- return to current cell
>>>+ increment bombCount
<<<<+[-<+]-> return to counted cell
>+ set temp = 1
<- set cellState = 0 to exit if
]
>+< increment temp
]
>[<+>-] restore cellState
+[->+]- go to current cell
>>- decrement temp
[ if temp != 0
<<<+[-<+] go to marked cell
+ set cellFlag = normal
>>>>-- set cellFlag of next cell = marker
>+[->+]->> return to currentCell temp
[<<<+>>>-] store value of temp in previous cell bombCount (to exit if)
]
<<<[>>>+<<<-]>>> restore temp value
]
<<<+[-<+] go to marked cell
+ set cellFlag = normal
<<<<-- set previous cellFlag = marker
>+[->+]- return to current cell
# check if cell to the right is a bomb
>>> >> go to cellState of next cell
[ if active
-[ if bomb
<<+ increment bombCount
>>> go back to checked cell
+ set temp = 1
<- set cellState = 0 to exit if
]
>+< increment temp
]
>[<+>-] restore cellState
# check if cells below are bombs
<<< < go to currentCell temp
+++[ do three times
+[->+]- go to next marker to the right
>[ if active
-[ if bomb
<<+[-<+]- return to current cell
>>>+ increment bombCount
+[->+]-> return to counted cell
>+ set temp = 1
<- set cellState = 0 to exit if
]
>+< increment temp
]
>[<+>-] restore cellState
<<<+[-<+]- go to current cell
>>- decrement temp
[ if temp != 0
+[->+] go to marked cell
+ set cellFlag = normal
>>>>-- set cellFlag of next cell = marker
<+[-<+]->> return to currentCell temp
[<<<+>>>-] store value of temp in previous cell bombCount (to exit if)
]
<<<[>>>+<<<-]>>>restore temp value
]
+[->+] go to marked cell
+ set cellFlag = normal
<<<<-- set previous cellFlag = marker
<+[-<+]- return to current cell
# print
>-[ if bomb
>>[-]<< delete bombCount
++++++[>++++++<-]>.print "*"
[-]+ set temp = 1
<<< use previous cell bombCount as exitIf
]
<[ else
>>>[ if bombCount != 0
<++++++[>++++++++<-]add 48 to get ascii number
>. print
[-] set number = 0 (for use as exitIf from next cell)
< go to temp for exit if
]
<<<[ else
<++++++++[<+++++++++++>-]<.print "X"
[-] delete value (for use as exitIf from next cell)
> go to exitIf
]
< go to exitElse
]
> >>>+ increment temp
<<++> set cellFlag = normal
]
>[<+>-] restore cellState
>> go to cellFlag of next cell
]
- set marker
>+[->+] go to next marker
+ set cellFlag = normal
+[-<+] return to marker
+++++ +++++.[-] print newline
]
> go to next row
]
5 5 1
, nunca se aprobará?