# aedda_flippinbits_12

Run some MiniScript code right in your browser!

bit0 = "." bit1 = "O" p=@print fbit = function(grid, x, y) if x >= 0 and x < grid.len and y >= 0 and y < grid[0].len then grid[x][y] = not grid[x][y] end if end function fg = function(grid, x, y) fbit(grid, x, y) fbit(grid, x-1, y) fbit(grid, x+1, y) fbit(grid, x, y-1) fbit(grid, x, y+1) end function showgrid = function(grid) p " a b c d e f g h" for i in range(0, grid.len-1) c = grid[i] p (i+1) + " " + c.join(" ").replace("0",bit0).replace("1",bit1) end for end function number.inRange = function(min, max) if self > max then; return 1;end if if self < min then; return -1;end if return 0 end function randInt = function(min, max) return floor(rnd*((max+1)-min))+min end function isWon = function(grid) for i in grid if i.sum > 0 then; return false; end if end for return true end function grid = [] for i in range(0,5) grid.push [0,0,0,0,0,0,0,0] end for msg = "" moves = 0 difficulty = 0 while true p char(13) * 30 if msg.len > 0 then; p msg; end if s = input("Enter difficulty (1-99): ") if s.len > 0 and s.val > 0 and s.val.inRange(1,99) == 0 then for i in range(1,s.val) fg(grid, randInt(0, 5), randInt(0, 7)) end for difficulty = s.val break else msg = "Invalid difficulty!" end if end while hist = [] while not isWon(grid) p char(13) * 30 if msg.len > 0 then; p msg; end if p "Moves: " + moves p "Difficulty: " + difficulty if hist.len >= 5 then hist = hist[-5:] end if if hist.len > 0 then p "History: " + hist.join(", ") end if p "" showgrid(grid) s = input("Enter position such as b5: ") if s.len == 2 then x = -1 y = -1 s = s.lower if s[1].val.inRange(1, 6) == 0 then x = s[1].val - 1 end if if s[0].code.inRange(97, 104) == 0 then y = s[0].code - 97 end if if x >= 0 and y >= 0 then msg = "" fg(grid, x, y) moves = moves + 1 hist.push(s) else msg = "Invalid position!" end if end if end while p char(13) * 30 p "You won in " + moves + " moves, well done!"