title: Find one point per pyramidal region

text:
# Question
Title: Find one point per pyramidal region
Consider 3 dimensional space which has been partitioned by at least two planes which go through the origin. If there are `n` planes then the number of distinct pyramidal regions this creates is exactly `2 - n + n^2` as long as they are in "general position", a term I make specific below.

> The challenge is write code that will return one point per pyramidal region. That is to return `2 - n + n^2` points in 3d space, each of which is in a different pyramidal region.

Notice that a plane through the origin can be defined by a single vector starting at the origin which is orthogonal to the plane.

Your code should take a list of planes in as input, each plane being described by a vector from the origin which is orthogonal to it. The vector itself is just represented as a space separated list of three numbers. Your should output a list of `2 - n + n^2` points. You can assume the planes are in general position, that is that no three of the vectors defining the planes are coplanar.

I will verify that the points are really all in different pyramidal regions using the following code.

Let us assume the variable `planes` contains an array of vectors, each one of which defines the plane. For example, let n = 4, the `planes` could equal

```
[[ 0.44060338 -0.55711491 -0.70391167]
 [ 0.15640806  0.89972402  0.40747172]
 [-0.48916566  0.86280671  0.12759912]
 [ 0.25920378 -0.94828262  0.18323068]]

```

We can then choose a number of points and put them in a 2d array called `testpoints`. To determine if they are all in distinct pyramidal regions we can call the following Python function which just looks to see which side of each plane the points are on and checks that each point is on at least one different side from every other point.

```
def all_in_distinct_pyramidal_regions(testpoints, planes):
    signs = np.sign(np.inner(testpoints, hyperplanes))
    return (len(set(map(tuple,signs)))==len(signs))

```

You can create some random test planes by first sampling points on a sphere and then using those points to define the hyperplanes. Here is a Python function that does this sampling.

```
import numpy as np
def points_on_sphere(N, norm=np.random.normal):
    """
    http://en.wikipedia.org/wiki/N-sphere#Generating_random_points
    """
    normal_deviates = norm(size=(N, 3))
    radius = np.sqrt((normal_deviates ** 2).sum(axis=0))
    points = normal_deviates / radius
    return points

```

You can use any language you choose for which there is a free and easy way to run the code in Linux. You can use any standard libraries of that language. I will however want to test your code so please give full instructions for how to run it.

Code to produce 10 random points on a sphere can be run using http://ideone.com/cuaHy5 .

Here is a picture of the 4 planes described above along with 2 - 4 + 16 = 14 points, one in each of the pyramidal regions created by the planes.

A valid output for this instance would therefore be the 14 points.

```
0.96716439  0.21970818  0.12775507
-0.84226594 -0.37162037 -0.39049504
0.60145419  0.58557551 -0.54346497
-0.4850864   0.26433373 -0.83355796
-0.69380885 -0.62124759  0.36425364
0.09880807 -0.09275638  0.99077405
0.19131628 -0.97946254 -0.06364919
-0.98100047  0.17593773 -0.08175574
-0.76331009  0.63554838 -0.11591362
0.89104146  0.34728895  0.29229352
-0.61696755 -0.26411912  0.74134482
0.18382632 -0.03398322 -0.98237112
-0.44983933 -0.18244731  0.87427545
0.8391045   0.18244157 -0.51246338

```

# Answer
> 5 votes
# Python, ~~423~~ ~~376~~ 353

```
S=sum
from numpy import*
C=cross
e=1e-15
def P(N,I,M):
 if M:v=M[0];L=[C(n,v)for m in N for n in-m,m if all(dot(N,C(n,v))<e)];[P(N+[u*v],[i for i in I if all(dot(N+[u*v],i)<e)]+L,M[1:])for u in-1,1]if L else P(N,I,M[1:])
 else:
    for u in-1,1:print list(u*S(I))
N=map(array,input())
a,b=N[:2]
c=C(a,b)
for u in-1,1:P([a,u*b],[c,-c,C(a,c)+u*C(b,c)],N[2:])

```

Reads a list of comma-separated triplets from STDIN and writes a list of triplets to STDOUT. Assumes at least two planes are given.

## Example

```
$ python cone.py <<< [0.44060338,-0.55711491,-0.70391167],[0.15640806,0.89972402,0.40747172],[-0.48916566,0.86280671,0.12759912],[0.25920378,-0.94828262,0.18323068]
[0.50892804716566153, 0.17353382779474077, -1.1968194626314141]
[-0.50892804716566153, -0.17353382779474077, 1.1968194626314141]
[0.1422280331828244, -0.62348456475000202, -0.24583080842150512]
[-0.1422280331828244, 0.62348456475000202, 0.24583080842150512]
[-1.2182327603643608, 0.1230166261435828, -1.5722574943149592]
[1.2182327603643608, -0.1230166261435828, 1.5722574943149592]
[-1.5849327743471977, -0.67400176640115994, -0.62126884010505024]
[1.5849327743471977, 0.67400176640115994, 0.62126884010505024]
[2.0938608215128593, 0.84753559419590085, -0.5755506225263638]
[-2.0938608215128593, -0.84753559419590085, 0.5755506225263638]
[1.7271608075300224, 0.050517201651157972, 0.37543803168354511]
[-1.7271608075300224, -0.050517201651157972, -0.37543803168354511]
[0.36670001398283714, 0.79701839254474283, -0.95098865420990886]
[-0.36670001398283714, -0.79701839254474283, 0.95098865420990886]

```

## How it works

Note that when three planes (whose normals are non-coplanar) partition the space, each of the eight resulting regions is bounded by (subsets of) all three planes. If we added a plane, it would divide some of the regions in two, resulting, again, in a pair of subregions bounded by at least three planes. Any cross-section of such a region is a polygon, whose vertices lie on the lines of intersection of the planes bounding the region. Moreover, since these planes extend to infinity (as planes usually do), the polygon is necessarily convex, the upshot of which is that the region is closed under addition. In particular, if we take one vector along each line of intersection of a pair of bounding planes that lies within the region, the sum of these vectors is also within the region and not on any of the planes (and, hence, not in any other region.)

The program recursively partitions the space by incrementally adding planes and subdividing the currently-explored region, while keeping a track of vectors along the lines of intersection and eventually taking their sum.

This method breaks if only two planes are given, since then there's only one line of intersection. We treat this as a special case and return the sum of a pair of vectors, each of which lies on a different plane, taking the four different sign combinations.

---
Tags: code-golf
---


# Question
Title: BrainF***edBotsForBattling - A Brainf*** Tournament
All bots at the battle arena suddenly got brainfucked and no one can explain why. But who cares as long as they are still able to fight - although Brainfuck is the only language they understand anymore.

---

It's been a while since the last submission so I'll finally annouce the winner of BrainFuckedBotsForBattling: **Congratulations to LymiaAluysia for winning with NyurokiMagicalFantasy!**

---

## Scoreboard

```
|       Owner        |          Bot            Score |
|--------------------|-------------------------------|
| LymiaAluysia       | NyurokiMagicalFantasy -  600  |
| Sylwester          | LethalLokeV2.1        -  585  |
| weston             | MickeyV4              -  584  |
| Sp3000             | YandereBot            -  538  |
| Comintern          | CounterPunch          -  512  |
| Sylwester          | BurlyBalderV3         -  507  |
| LymiaAluysia       | NestDarwin            -  493  |
| IstvanChung        | Bigger                -  493  |
| Manu               | DecoyMaster           -  489  |
| archaephyrryx      | Wut                   -  478  |
| DLosc              | LightfootPlodder      -  475  |
| archaephyrryx      | 99BottlesOfBats       -  461  |
| Sylwester          | TerribleThorV2        -  458  |
| MikaLammi          | WallE2.0              -  443  |
| Mikescher          | MultiVAC              -  441  |
| archaephyrryx      | Twitcher              -  439  |
| Timtech            | MetalDetector         -  438  |
| AndoDaan           | BeatYouMate           -  433  |
| csarchon           | TheWallmaster         -  427  |
| Sparr              | SeeSawRush            -  412  |
| archaephyrryx      | Stitcher              -  406  |
| PhiNotPi           | RandomOscillator      -  403  |
| ccarton            | AnybodyThere          -  398  |
| Comintern          | 2BotsOneCup           -  392  |
| kaine              | SternBot              -  387  |
| PhiNotPi           | EvoBot2               -  385  |
| PhiNotPi           | EvoBot1               -  381  |
| Brilliand          | TimedAttack           -  373  |
| Sylwester          | ReluctantRanV2        -  373  |
| AndoDaan           | PrimesAndWonders      -  359  |
| Nax                | TruthBot              -  357  |
| DLosc              | Plodder               -  356  |
| weston             | FastTrapClearBot      -  345  |
| MikaLammi          | PolarBearMkII         -  340  |
| Sp3000             | ParanoidBot           -  336  |
| Moop               | Alternator            -  319  |
| TestBot            | FastClearBot          -  302  |
| icedvariables      | PyBot                 -  293  |
| TestBot            | DecoyBot              -  293  |
| kaine              | BestOffense           -  291  |
| Geobits            | Backtracker           -  289  |
| bornSwift          | ScribeBot             -  280  |
| IngoBuerk          | Geronimo              -  268  |
| flawr              | CropCircleBot         -  239  |
| plannapus          | CleanUpOnAisleSix     -  233  |
| frederick          | ConBot                -  230  |
| frederick          | 128Bot                -  222  |
| AndoDaan           | EndTitled             -  219  |
| PhiNotPi           | CloakingDeviceBot     -  215  |
| AndoDaan           | GetOffMate            -  206  |
| DLosc              | ScaredyBot            -  205  |
| isaacg             | CleverAndDetermined   -  202  |
| PhiNotPi           | CantTouchThis         -  202  |
| Moop               | StubbornBot           -  174  |
| Cruncher           | StallBot              -  168  |
| IngoBuerk          | Gambler               -  157  |
| BetaDecay          | RussianRoulette       -  129  |
| flawr              | DoNothingBot          -  123  |
| SebastianLamerichs | Dumbot                -  115  |
| mmphilips          | PacifistBot           -  112  |
| SeanD              | DontUnderstand        -  92   |
| proudHaskeller     | PatientBot            -  83   |
| frederick          | Dumberbot             -  70   |
| flawr              | MetaJSRandomBot       -  68   |
| Darkgamma          | TheRetard             -  61   |
| BetaDecay          | Roomba                -  61   |
| BetaDecay          | PrussianRoulette      -  31   |
| frederick          | Dumbestbot            -  0    |

```

*Final Scores from 09.10.2014*

**EDIT6**: Discarded logs due to extreme size and runtime. You can generate them yourself by uncommenting the lines in `RunThisTournament.py`.

**EDIT5**: Implemented Abbreviation handling into the controller, no huge runtimes anymore. **This has the side effect that numbers and parentheses are not treated as comments anymore.** You can still use them if you want to provide an annotated version, but it would be very helpful if there would be **also an uncommented version of your code**, so I don't need to remove the comments manually. Thanks!

**EDIT4**: Changed the title, because the tournament got removed from the hot network questions. Thanks to @Geobits for pointing this out!

**EDIT3**: Removed comments in bf programs, due to an unexpected result, should be fixed now. If anyone has a problem with removing his comments, please report.

**EDIT2**: Since it caused an arcane runtime on my quite slow computer, I reduced the timeout limit from 100000 cycles to 10000 cycles. Not that anyone has turned the resultof a running game beyond this point anyway.

**EDIT1**: Fixed a bug in the convert script causing the interpreter to not ignore numbers in commented programs.

---

## Description

This is a Brainfuck tournament inspired by BF Joust. Two bots (Brainfuck programs) are fighting each other in an arena which is represented by a memory tape. Each cell can hold values from -127 up to 128 and wrap at their limits (so 128 + 1 = -127).

Valid instructions are similiar to regular Brainfuck, which means:

```
+ : Increment cell at your pointer's location by 1
- : Decrement cell at your pointer's location by 1
> : Move your memory pointer by 1 cell towards the enemy flag
< : Move your memory pointer by 1 cell away from the enemy flag
[ : Jump behind the matching ']'-bracket if the cell at your pointer's location equals 0
] : Jump behind the matching '['-bracket if the cell at your pointer's location is not 0
. : Do nothing

```

The arena has a size of 10 to 30 cells which is pseudorandomly chosen each battle. At both ends is a 'flag' located which has an initial value of 128, while all other cells are zeroed. Your bot's goal is to zero the enemy's flag for 2 consecutive cycles before he zeroes your own flag.

Each bot starts at his own flag, which is cell \[0\] from his own perspective. The opponent is located on the other side of the tape.

```
[ 128 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 128 ]
   ^                                             ^
my bot                                       other bot

```

Both bots execute their action simultaneously, this is considered one cycle. The game ends after 10000 cycles or as soon as one of the winning conditions is reached. If one of the programs reaches its end, it simply stops doing anthing until the end of the game, but can still win.

---

## Winning conditions

Your bot wins under one of the following conditions:

* Your enemy's flag is zeroed before yours
* Your enemy moves his pointer out of the tape (executes `>` on your flag or `<` on his own)
* Your flag's value is more far away from 0 than the value of your opponent's flag after 10000 cycles

---

## Rules

Your post should contain a name for your bot and its code.

* You can use the following abbreviation syntax to make your code more readable:
    + e.g. `(+)*4` is the same as `++++`, this is valid for any instruction **except unmatched brackets in parentheses** since the loop logic collides with the abbreviation logic. Please use `[-[-[-` instead of `([-)*3`
* Every other character than `+-><[].` is a comment and therefore ignored, except `()*` for abbreviations

Bots which do not follow the rules will excluded from the tournament.

* Only basic Brainfuck is allowed, no other variants which supports procedures or arithmetic operations
* Your bot's source code should not contain unmatched brackets

You may inform yourself about basic strategies but do **not** use another one's code for your own bot.

---

## Scoring

A bot's score is determined by the number of wins against all other bots. An encounter between 2 bots consists of 10 matches with different memory tape lengths, which results in a maximum score of 10 points per encounter. A draw results in no points for this match.

---

## Control program

You can find the control program on github, along with the full logs from the battles. The leaderboard will be posted here once it is generated.

Feel free to clone the repository and try your bot against the others on your own. Use `python Arena.py yourbot.bf otherbot.bf` to run a match. You can modify the conditions with the command-line flags `-m` and `-t`. If your terminal does not support ANSI escape sequences, use the `--no-color` flag to disable colored output.

---

## Example bots

FastClearBot.bf

```
(>)*9       Since the tape length is at least 10, the first 9 cells can be easily ignored
([          Find a non-zero cell
+++         Increment at first, since it could be a decoy
[-]         Set the cell to zero
]>          Move on to the next cell
)*21        Repeat this 21 times

```

DecoyBot.bf

```
>(+)*10     Set up a large defense in front of your flag
>(-)*10     Set up another one with different polarity
(>+>-)*3    Create some small decoys
(>[-]       Move on and set the next cell to zero
.           Wait one round, in case it is the enemy's flag
)*21        Repeat this 21 times

```

The DecoyBot will win every match with a tape length greater than ten, since the FastClearBot can avoid the small decoys, but not the larger ones. The only situation in which the FastClearBot can win against DecoyBot, is when it is fast enough to reach the enemy's flag before his opponent has built up large decoys.

# Answer
# Nyuroki Magical Fantasy

I think it's about time to get serious~ I finished up my compiler for a little HLL to make writing BF Joust programs easier. This was my first serious attempt to make something with it. The bot's concept is pretty simple. It sets up a few decoys of varying polarities, then goes crazy with a large wiggle clear with a reverse offset clear in the middle.

Oh, by the way, the expected score is roughly 577 points against the last round's hill. That's a 93% win rate. \<3

Compiled | Source Code

```
Nyuroki Magical Fantasy by Lymia Aluysia
Released under the terms of MIT license

>>>>>>>>++<--<+<--<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+<-------------------------------------------------------------<---------------
----------------------------------------------<++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++<(-)*19(>)*8(>[-[-[-[(+)*3+[+[+[(-)*6-[-[-[-[-[-[-
[-[-[-[(+)*16+[+[+[+[+[+[+[+[(-)*24-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[(+)*41+[+[
+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[(+)*82[[+.].]--(>[-[-[-[(+)*3+[+[+[(-)*6-
[-[-[-[-[-[-[-[-[-[(+)*16+[+[+[+[+[+[+[+[(-)*24-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[
-[(+)*41+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[(+)*82[[+.].]--(>[-[-[-[(+)*3
+[+[+[(-)*6-[-[-[-[-[-[-[-[-[-[(+)*16+[+[+[+[+[+[+[+[(-)*24-[-[-[-[-[-[-[-[-[-[
-[-[-[-[-[-[-[(+)*41+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[(+)*82[[+.].]--(>
[-[-[-[(+)*3+[+[+[(-)*6-[-[-[-[-[-[-[-[-[-[(+)*16+[+[+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]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
]]]]]]]]]]]]]]]]--)*18]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
]]]]]]--)*19]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]--)*
20]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]--)*21

```

---

**Edit**: I squeezed a few more wins out of Nyuroki.

**Edit 2**: Hey, look, I did it again!

**Edit 3**: After wrestling for a while with a stupid parsing bug in Arena.py, I finally got another improvement in~ This is what I mean by "time to get serious", you know. \<3
> 18 votes

# Answer
# Cloaking Device Bot

This bot basically tries to hide its base, making it so that other bots will move right past it and off the tape.

```
(-)*127(-+--+-++)*12500

```
> 43 votes

# Answer
# Burly Balder v3

Burly Balder is a medium slow rush. It makes two large decoys before going into rush mode. In rush mode it has a loop that only uses 4 steps each zero cell and when a non zero cell it has a case analysis for \[-18,18\] before blindly reducing with 107 before clearing with `[-.]`. He clears an unchanged flag in 242 steps, 114 more than a uncertain `-*128` and 14 less than a naive `[-]` clear. When a cell is cleared he continues leaving a trail of -2 decoys. He has a special case only for index 9 to save some steps for size 10 games and it leaves the cell with a 1 decoy.

```
>((-)*18>)*2                                  Make two minus seventeen decoys
(->)*6                                        Move to cell nine

[                                             special case for ten cell game
   +[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[       if not minus one to minus eighteen
   (-)*18                                     decrease by eighteen
   -[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[       if not plus one to plus eighteen
       (-)*107                                decrease by hundred and seven
       [-.]                                   slow clear
   ]]]]]]]]]]]]]]]]]]                         end plus conditionals
   ]]]]]]]]]]]]]]]]]]                         end minus conditionals
]                                             end special case
+
([>                                           while true go right
  [                                           start clear cell
   +[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[+[       if not minus one to minus eighteen
   (-)*18                                     decrease by eighteen
   -[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[       if not plus one to plus eighteen
       (-)*107                                decrease by hundred and seven
       [-.]                                   slow clear
   ]]]]]]]]]]]]]]]]]]                         end plus conditionals
   ]]]]]]]]]]]]]]]]]]                         end minus conditionals
  ]                                           end clear cell
  --                                          set to minus two
 ]                                            while true end
 -                                           decrease and loop
)*5                                          In case of clash or initial column minus seven is zero

```

Trivia: Balder is a nordic god and son of Odin. He is known mostly for the story of his death: He was scared for his safety so the other gods tried to predict and shield against every threat. He was eventually killed by Loki since while they protected him against swords and arrows they forgot to protect him against Mistletoe.
> 19 votes

# Answer
# EvoBot 1

This is a simple bot created via genetic algorithm. I started with a template, and my program slowly adjusted the numbers to create a better warrior-bot. The code below has been edited to increase readability.

```
>+>---(>)*6(>[+++[-]])*30

```

I used the other entries in the competition to measure the fitness of the different candidates.

Since this was my first attempt at an evobot, I started with a simple template:

```
>(+)*n>(-)*n(>)*n(>[(+)*n[-]])*30  #template

```

I predict that this bot will receive a score in the 50s to 60s range.

~~I am currently working on a reverse decoy template.~~

# EvoBot 2

This is a bot created by the same genetic algorithm, but with the following template:

```
>>>>(-)*n<(+)*n<(-)*n<(+)*n(>)*8(>[+++[-]])*30  #template

```

This bot uses the reverse decoy strategy to set 4 decoys of varying height. The resulting bot is:

```
>>>>(-)*4<(+)*6<(-)*7<(+)*8(>)*8(>[+++[-]])*30

```

I expect this new bot to fare better than the previous bots, possibly earning a score in the 70s (probably much higher than that since there are many new entries).
> 13 votes

# Answer
# Alternator

It assumes most people will zero a cell by either adding or subtracting to it, so on average every cell will take 128 turns to zero.

```
(>+>-)*4>+(>[-][.])*21

```

Annotated version

```
(>+>-)*4       Move eight squares alternating polarity
>+             Move one more
(
    >          Move to the next square
    [-]        Zero it
    [.]        Wait while it is zero
)*21           Repeat

```
> 12 votes

# Answer
So, someone else here using an genetic algorithm to try and make programs here. Well... a long time ago, I wrote an BF Joust evolver for an ongoing hill in an IRC channel. I decided to give it a spin for this contest as well~

And... unlike the other person with an evolver, my evolver can actually change more of the program more than repeat counts. :)

# NestDarwin (Generation 309)

This is the best result my evolver has come up with so far. I'm not sure how much the nested structure helps in this case, but, structures like this was what the evolver is meant to be able to do. Expected performance on the 27.08.2014 hill is 474 points. (Calculated by running the battle on all 21 tape lengths, and multiplying by 10/21. Note that this isn't normalized for the fact that this hill has one extra program on it)

```
(-)*5(>[(-)*4----[.+]]--((-)*5(>[(-)*4----[.+]]--((-)*5(>[(-)*4----[.+]]--((-)*5(>[(-)*4----[.+]]--)*10000)*10000)*10000)*10000)*10000)*10000)*10000

```

---

**EDIT**: Changed list of programs I wanna enter into this hill. Ran evolver overnight. :)

---

**EDIT 2**: I went and manually analyzed the evolver's output. Despite looking very different, NestDarwin is basically an optimized version of TinyDarwin... Manually minimized (with identical functionality) and analyzed:

```
(-)*5                     Break stuff that assumes flag size.
(>[(-)*8[.+]](-)*7)*3     Make a few larger decoys next to our flag.
                          The clear loop is basically dead code here.
                          Few things are going to approach so fast, so.
(>[(-)*8[.+]](-)*2)*10000 And go on an rampage with an offset clear!
                          I presume the slow clear is to beat tripwires.

```

So, an almost identical program would be as follows... which is basically a super-optimized version of TinyDarwin.

```
(-)*5(>.(-)*7)*3(>[(-)*8[.+]](-)*2)*10000

```

TinyDarwin was as follows. Not very different, hun? I'm just going to withdraw it from the hill. I thought it was distinct, but... well, I was wrong.

```
((-)*5>[(-)*4.[+.]].)*10000

```

It's become apparent that the current hill isn't strong enough to allow it to evolve much more complex things. :(
> 11 votes

# Answer
# Pacifist Bot

My bot believes violence is never the answer and will try to avoid combat at all costs.

```
(.)*8       Since it takes at least 9 turns for a bot to come to mine, remain idle for 8
>           Skedaddle over one spot
([(>)*8     If a bot has approached, RUN
[(<)*8      If you accidentally ran into a bot, run the other way this time
]].         If it's safe here, chill out
)*6249      keep running until the end of battle, or until tired

```
> 10 votes

# Answer
## Polar bear Mk II

There are two kinds of *polar bears*: those who get trapped and those who trap other people.

Tries to guess polarity of the opponent and then uses that information to lock opponent into infinite loop. Works well against simple clearing strategies and somewhat randomly against other. Traps can be quite easily avoided so I might add some backup strategies later.

```
>++>- create polar bear traps
[[]]<
[][
[[]]<
(+)*290 (>)*9  (+)*120 (.+)*16 (<)*9
(+)*112 (>)*10 (+)*120 (.+)*16 (<)*10
(+)*112 (>)*11 (+)*120 (.+)*16 (<)*11
(+)*112 (>)*12 (+)*120 (.+)*16 (<)*12
(+)*111 (>)*13 (+)*120 (.+)*16 (<)*13
(+)*111 (>)*14 (+)*120 (.+)*16 (<)*14
(+)*111 (>)*15 (+)*120 (.+)*16 (<)*15
(+)*110 (>)*16 (+)*120 (.+)*16 (<)*16
(+)*110 (>)*17 (+)*120 (.+)*16 (<)*17
(+)*110 (>)*18 (+)*120 (.+)*16 (<)*18
(+)*109 (>)*19 (+)*120 (.+)*16 (<)*19
(+)*109 (>)*20 (+)*120 (.+)*16 (<)*20
(+)*109 (>)*21 (+)*120 (.+)*16 (<)*21
(+)*108 (>)*22 (+)*120 (.+)*16 (<)*22
(+)*108 (>)*23 (+)*120 (.+)*16 (<)*23
(+)*108 (>)*24 (+)*120 (.+)*16 (<)*24
(+)*107 (>)*25 (+)*120 (.+)*16 (<)*25
(+)*107 (>)*26 (+)*120 (.+)*16 (<)*26
(+)*107 (>)*27 (+)*120 (.+)*16 (<)*27
(+)*106 (>)*28 (+)*120 (.+)*16 (<)*28
(+)*106 (>)*29 (+)*120 (.+)*16 (<)*29
(+)*106 (>)*29 [-]
]<
(-)*290 (>)*9  (+)*120 (.+)*16 (<)*9
(-)*112 (>)*10 (+)*120 (.+)*16 (<)*10
(-)*112 (>)*11 (+)*120 (.+)*16 (<)*11
(-)*112 (>)*12 (+)*120 (.+)*16 (<)*12
(-)*111 (>)*13 (+)*120 (.+)*16 (<)*13
(-)*111 (>)*14 (+)*120 (.+)*16 (<)*14
(-)*111 (>)*15 (+)*120 (.+)*16 (<)*15
(-)*110 (>)*16 (+)*120 (.+)*16 (<)*16
(-)*110 (>)*17 (+)*120 (.+)*16 (<)*17
(-)*110 (>)*18 (+)*120 (.+)*16 (<)*18
(-)*109 (>)*19 (+)*120 (.+)*16 (<)*19
(-)*109 (>)*20 (+)*120 (.+)*16 (<)*20
(-)*109 (>)*21 (+)*120 (.+)*16 (<)*21
(-)*108 (>)*22 (+)*120 (.+)*16 (<)*22
(-)*108 (>)*23 (+)*120 (.+)*16 (<)*23
(-)*108 (>)*24 (+)*120 (.+)*16 (<)*24
(-)*107 (>)*25 (+)*120 (.+)*16 (<)*25
(-)*107 (>)*26 (+)*120 (.+)*16 (<)*26
(-)*107 (>)*27 (+)*120 (.+)*16 (<)*27
(-)*106 (>)*28 (+)*120 (.+)*16 (<)*28
(-)*106 (>)*29 (+)*120 (.+)*16 (<)*29
(-)*106 (>)*29 [-]

```
> 10 votes

# Answer
# AnybodyThere?

Periodically looks behind to determine when the enemy has started clearing it's decoys, then rushes ahead.

Seems to do well, but I'm not sure if that's because of the strategy or just because I'm adding 10 to every cell before clearing.

Edit: Fixed a logic problem. First time writing a brainfuck program. It lives up to it's name.

```
>>>+<(+)*5<(-)*5>>             Initial defense
[                              While he hasn't passed us yet
  (>[([(+)*10[-]]>)*29])*4     Jump ahead four, checking for enemy
  +                            Front marker
  <<<<                         Check behind
  [                            If he hasn't passed us yet
    >>>
    (+)*5<(-)*5                Set decoys in reverse
    <<[-]
  ]
  >>>>                         Check ahead
]
([-[(+)*10[-]]]>)*29           Clear to the end

```
> 9 votes

# Answer
## WALL-E 2.0

Rushes to location 9 and adds 128 to it, winning quickly in size 10 arena if opponent hasn't changed initial flag value. On larger arenas, this works as large decoy. After that it fills the space between location 9 and own flag with large decoys. When decoys are placed, it scans for non-empty locations and tries to clear them quickly.

**Version 2.0** builds larger decoys and has some tolerance against changing initial flag value. It can also switch to backup strategy if things start to look hairy.

```
(>)*9
(+)*128 <
< [ (<)*7 ((-+-)*256)*15 ] > [ (<)*8 ((+-+)*256)*15 ]
(-)*47 < (+)*63 < (-)*72 < (+)*69 <
(-)*84 < (+)*66 < (-)*76 < (+)*66 <
++++ (>)*9 +.+.+.----.-.-. (>[-[++[(+)*124.+.+.+.+.+.+.+.+.>]]])*21

```

Effectiveness of this bot is based on two facts:

1. Most bots do not change the initial value of their flag.
2. Building large decoys is faster than clearing them.
> 9 votes

# Answer
# Lethal Loke V2.1 (with Mistletoe)

This is of course a deadly bot and he kills not only beautiful Burly Balder a with mistletoe, but wins almost every time against the other bots as well. It is a combined medium and fast rush. My test gives me a score of 567

Compiled BFJ file for battle, Racket BFJ generator source:

```
#lang racket
;; bare minimum bfj support
(define (bf . args)
  (apply string-append
         (map (lambda (x)
                (if (number? x)
                    (number->string x)
                    x))
              args)))

(define (dup x num)
  (let loop ((n num) (lst '()))
    (cond ((< n 0) (error "Negative n"))
          ((zero? n) (apply bf lst))
          (else (loop (sub1 n) (cons x lst))))))

;; Useful procedures
(define (wiggle amount default-zero n)
  (let rec ((n n))
    (if (zero? n)
        ""
        (bf "["
            (dup "-[" amount)
            (bf "(+)*" amount)
            (dup "+[" amount)
            default-zero
            ">"
            (rec (sub1 n))
            (dup "]" (* amount 2))
            "]"))))

(define (goto from to)
  (let* ((dst (- to from))
         (op (if (> dst 0) ">" "<"))
         (abs (if (> dst 0) dst (- dst))))
    (if (= from to)
        ""
        (bf "(" op ")*" abs))))

(define max-position 30)
(define initial-decoy  "(-)*17")
(define small-decoy "(+)*10")
(define large-decoy "(-)*32")
(define flag-position 7)
(define decoy-phase-end-position 14)
(define wiggle-amount 8)
(define plodd-clear "..(+)*120(+.)*27>")
(define plodd-inner-clear (bf "(+)*"
                              (- 78 wiggle-amount)
                              "..(+)*42(+.)*27"))
;; Main body of Loke V2
(define (generate-loke2)
  (bf ">"
      initial-decoy
      ">->+>->+>->"
      (let gen-rec ((n flag-position) (p #t))
        (if (> n decoy-phase-end-position)
            (bf (medium-slow n))
            (bf "["
                (medium-slow n)
                "]"
                (if p small-decoy large-decoy)
                ">"
                (gen-rec (+ n 1) (not p)))))))

;; Retreat goes back to home
;; leaving a trail of flags
;; from flag position
(define (medium-slow last-index)
  (bf (goto last-index 2)
      (let medium-rec ((n 2) (p #f))
        (if (= n flag-position)
                (fast-rush n last-index)
            (bf (if p "-" "+")
                "[" (fast-rush n (max 9 last-index)) "]"
                (if p small-decoy large-decoy)
                ">"
                (medium-rec (+ n 1) (not p)))))))

(define (fast-rush cur-position last-known)
  (bf (goto cur-position last-known)
      "([" plodd-clear
      "("
      (wiggle wiggle-amount
              plodd-inner-clear
              (- max-position last-known 1))
      ">)*" (- max-position last-known)
      "]>)*" (- max-position last-known)))

(display (generate-loke2))

```

**Trivia**: Loke (Loki) is a god in Nordic mythology that likes to play with everyone and trick them. He is a shape shifter (into animals and people) and usually goes his own ways. In the stories he often travel with and assist the other gods and does small tricks and stir things up. Besides killing Balder he fathered Hel (godess of Hell/Helvete), the beast Fenrir, and the Midgard Serpent that starts Ragnarok (norse armageddon).

**How it works**

In the beginning he makes a large (-17) decoy then make `+-` pattern all the way to index 7. He scan forwards from to 13 leaving a trail of (+10,-32)+ decoys but when he detects a set he will abort and start a medium\*1 rush mode. If no cells are set he will also start the slow\*3 rush mode.

\*1 In medium rush mode he has detected opponent activity in one of index 7-13 and he starts from index 2. Some opponents leave a zero and other leave a different value and he now have means to detect opponent activity while before making decoys in index 2-6 (-32,+10)+. If cell is not expected value (-1, 1) or he finished making all decoys he goes in fast\*2 rush mode.

\*2 The fast rush mode he expects he has been detected so decoys won't work. We hope the ones we already have set is stopping the opponent and focus on running through opponents decoys. He starts rushing at the farthest point we know based on the previous scanning \[9,14\] or index 9 if we were made earlier than that. He has special case for first decoy where we just add 120 and plodd 27 since he doesn't want to reduce tha value below zero incase it's a trap, but for every decoy after we wiggle clear at \[-8,8\] before increasing by 120 and plodding 27 steps ebfore contiuing forward to next cell.

Slow rush mode was removed since it didn't affect the score with the current hill and it makes my bot a little smaller (but not much).
> 9 votes

# Answer
# Geronimo

Is even more offensive than kaine's BestOffense bot as it does not build up any defense. The strategy here is: Others will try to be clever, but being clever takes cycles. So let's just skip to the part we know the enemy is in and clear everything we find.

```
(>)*9(>[-])*21

```

Seems to win most matches against the OP's example bots and kaine's bot.
> 8 votes

# Answer
## SternBot

An actual half serious bot now that things are started. Addressing the simular nature of some of these bots.

```
(>->+>)*3(>[+]>[-])*21

```
> 7 votes

# Answer
# CounterPunch - Edited

Balanced combination of building a strong defense and then attacking.

```
(+)*6>(-)*12(>)*7(<(-)*12<(+)*12)*3(>)*7(([-([(-)*6[+.]])*5])*4>)*21

```

**Annotated:**

```
(+)*6                             Switch polarity of the flag
>(-)*12                           Build a quick decoy in front of the flag
(>)*7(<(-)*12<(+)*12)*3           Hop out and start building decoys backward
(>)*7                             Tally ho!
(([-([(-)*6[+.]])*5])*4>)*21      Clear toward the opposite end

```

Defends similar to @Geobit's Backtracker, but defends against fast attackers by putting a quick decoy out in front of the flag first.

Attack is nested clearing with opposite polarity to quickly clear out decoys with smallish values. Worst case scenario should be a decoy of 64 (either polarity).

**Edit 1:** Improve attacking efficiency against decoys (had a logic error in the polarity switching).

**Edit 2:** Testing indicates that the pause performs slightly better in the inner-most loop.
> 7 votes

# Answer
# DoNothingBot

> The best defense (...) is ignorance.

```
.

```

It does nothing.

EDIT: Wow, I was astonished to see that it did a better job than more than the least 20% of all bots=) (Does this mean it uses a superior strategy or ....?)
> 7 votes

# Answer
# Backtracker

A reverse decoy strategy. Start laying decoys down from the front back, so nobody skips over the rest as I'm building them.

If the board is less than size 20 or so, this doesn't work against fast-attack bots, since we'll just pass each other before I start decoying.

```
(>)*9((-)*4<+<-<(+)*4<)*2(>)*8(>[-])*21

(>)*9                   Jump ahead 9
((-)*4<+<-<(+)*4<)*2    Lay down alternating polarity/size decoys for 8 spots behind
(>)*8                   Jump back forward
(>[-])*21               Clear until flag

```

<sub>Note: I don't BF, but this like it does what I want to me. If not, please let me now.</sub>
> 6 votes

# Answer
# Can't Touch This

This is a defense-oriented program that attempts to determine how the opponent is clearing cells, and builds a decoy of the appropriate size.

```
>---    create 1st decoy
>+      decoy for timing
>+      decoy for waiting
[]<     tripwire activated!
[<-->]  increase size of 1st decoy while opponent clears 2nd decoy
(>)*8   attack!
[+(<)*9(+)*20(>)*9]    slowly clear, while going back to stop enemy progress
>[+(<)*10(+)*22(>)*10]
>[+(<)*11(+)*24(>)*11]
>[+(<)*12(+)*26(>)*12]
>[+(<)*13(+)*28(>)*13]
>[+(<)*14(+)*30(>)*14]
>[+(<)*15(+)*32(>)*15]
>[+(<)*16(+)*34(>)*16]
>[+(<)*17(+)*36(>)*17]
>[+(<)*18(+)*38(>)*18]
>[+(<)*19(+)*40(>)*19]
>[+(<)*20(+)*42(>)*20]
>[+(<)*21(+)*44(>)*21]
>[+(<)*22(+)*46(>)*22]
>[+(<)*23(+)*48(>)*23]
>[+(<)*24(+)*50(>)*24]
>[+(<)*25(+)*52(>)*25]
>[+(<)*26(+)*54(>)*26]
>[+(<)*27(+)*56(>)*27]
>[+(<)*28(+)*58(>)*28]

```

I am currently working on a version that can win against both polarities.
> 6 votes

# Answer
# ImpatientTripwire (a.k.a. YandereBot)

Tries to be a tripwire so that it can lay decoys of (mostly) the corresponding polarity, but gives up if you take too long and assumes you're the opposite parity instead. Has a reverse tripwire for small boards.

```
(+)*5                                     Toggles the base
>-                                        Sets up reverse tripwire
>>++>-->                                  Sets up basic decoys
(+)*20                                    Makes a massive antioffset tripwire
(([)*150                                  Waits for a while
    <<<<                                  Goes to check on the other tripwire
    +[
      <                                   Bot found you and is furious
      ((+)*128 (>)*9 (+.)*55 (<)*9)*5     Tries to tie you up
      ((+)*128 (>)*10 (+.)*54 (<)*10)*5   And torture you
      ((+)*128 (>)*11 (+.)*53 (<)*11)*5   As it destroys the world
      ((+)*128 (>)*12 (+.)*52 (<)*12)*5
      ((+)*128 (>)*13 (+.)*51 (<)*13)*6
      ((+)*128 (>)*14 (+.)*50 (<)*14)*6
      ((+)*128 (>)*15 (+.)*49 (<)*15)*6
      ((+)*128 (>)*16 (+.)*48 (<)*16)*6
      ((+)*128 (>)*17 (+.)*47 (<)*17)*6
      ((+)*128 (>)*18 (+.)*46 (<)*18)*6
      ((+)*128 (>)*19 (+.)*45 (<)*19)*6
      ((+)*128 (>)*20 (+.)*44 (<)*20)*6
      ((+)*128 (>)*21 (+.)*43 (<)*21)*6
      ((+)*128 (>)*22 (+.)*42 (<)*22)*7
      ((+)*128 (>)*23 (+.)*41 (<)*23)*7
      ((+)*128 (>)*24 (+.)*40 (<)*24)*7
      ((+)*128 (>)*25 (+.)*39 (<)*25)*7
      ((+)*128 (>)*26 (+.)*38 (<)*26)*7
      ((+)*128 (>)*27 (+.)*37 (<)*27)*7
      ((+)*128 (>)*28 (+.)*36 (<)*28)*8
      ((+)*128 (>)*29 (+.)*35 (<)*29)*8
    ]-
    >>>>)*2                                 Waits again
      <(+)*20                               Bot got stood up, is sad
      <(+)*20                               Sets up some decoys
      <(+)*20                               Grabs a knife
      <(-)*20                               Licks the blade
      <(-)*5                                Locks the house
      >>>>>>>>                              Goes to hunt you down
     (
       >                                    Start searching
       [
         +[+[+[                             Search from minus three
         ---
         -[-[-[                             To plus three
         (-)*17                             If that's no good, do an offset
         [+]                                Clear by adding
         [-.--]                             Just in case
         ]]]]]]                             I would duplicate the program to skip these like at
       ]                                    the bottom but the file would get too large
       [--.---]                             Also just in case
       -                                    Leave a small trail
     )*22
(
  ]                                         Skip the bracket closing
  <(-)*20                                   Bot found you and is happy
  <(-)*20                                   Has just the perfect presents for you
  <(-)*20                                   You like decoys right?
  <(+)*20                                   Here's a plus one in case you are sneaky
  <(-)*5
  >>>>>>>>                                  Time to hunt you down

  (>[+[+[+[----[-[-[(-)*17[+][-.--]]]]]]]][--.---]-)*22
)*300

```

**Current version:** 1.3 \- edited to do better on smaller boards, at the expense of losing games due to enemies sneaking past during tripwire checking

**Past versions:** 1.2.1

(I need a better clear algorithm :/ )
> 6 votes

# Answer
# Lightfoot Plodder - EDITED

Based on the Plodder, this speedy behemoth is able to "fast forward" through consecutive 0's quickly until it reaches something nonzero (at which point it starts plodding as expected).

Now improved with a more robust skimming algorithm, which also allows fast-forwarding through small decoys, and bigger decoys of its own.

**Edit #2**: Now is able to go back to skimming if it finds more pockets of zeros.

```
>(-)*4
>(-)*7
>(-)*4
>(+)*7
>(-)*17
>(+)*3
> -
>(-)*10
>(+)*16[-]<-
([
[>>
 [+
  [--
   [+++
    [<+>(+)*14[-]]
   ]
  ]
 ]<-
]>>
[(+)*126(+.)*4>]
<]+)*10

```
> 5 votes

# Answer
# Reluctant Rán v2

The strategy is easy. Try to get the opponent to think her flag is a decoy and precede past the board and loose (a kind of tripwire / vibrator). After 10 full rounds she gives up and tries to determine if opponent is at her flag and if not she will make -17 decoys until she hits a set cell. The clearing method she uses is special case for \[-12,12\] and starts plodding similar to Loke.

```
>>-<<                                  set a flag
(.)*11                                 wait for sixteenth step
((-)*256)*10                           reduce by ten rounds
                                       We give up check flags
> [(>)*7                               detected fast rush mode
    (-[>[
        -[-[-[-[-[-[-[-[-[-[-[-[       from plus one to twelve
        (+)*12                         reduce by twelwe
        +[+[+[+[+[+[+[+[+[+[+[+[       from minus one to twelve
          (+)*66..(+)*41(+.)*17>       increase and plod
        ]]]]]]]]]]]]]]]]]]]]]]]]]-])*3
  ](-)*31
>+[(>)*6                               detected fast rush mode
    (-[>[
        -[-[-[-[-[-[-[-[-[-[-[-[       from plus one to twelve
        (+)*12                         reduce by twelwe
        +[+[+[+[+[+[+[+[+[+[+[+[       from minus one to twelve
          (+)*66..(+)*41(+.)*17>       increase and plod
        ]]]]]]]]]]]]]]]]]]]]]]]]]-])*3
  ](-)*21
[>[                                    propably a trapper so we move slow
    ..+..-(+)*119(+.)*17               plodd the first cell so we dont go to zero on low positive
    ([>[
        -[-[-[-[-[-[-[-[-[-[-[-[       from plus one to twelve
        (+)*12                         reduce by twelwe
        +[+[+[+[+[+[+[+[+[+[+[+[       from minus one to twelve
          (+)*66..(+)*41(+.)*17>       increase and plod
        ]]]]]]]]]]]]]]]]]]]]]]]]]-]-)*3
  ](-)*17
]

```

Trivia: Rán is a Nordic Mythology sea goddess that takes sailors before they die at sea.
> 5 votes

# Answer
# Mickey V4

For V4 I used the same method as V3, against the updated bots but with more concurrent populations (30 not 10).

Developed against all 60 bots, including `BurlyBalderV3` and `LethalLoke` (but excluding 2botsonecup which is uncompilable by my strict implementation).

I discovered wildly different bots and success rates if I started with different random seeds. So I decided to separate these different starting points into populations and let them occasionally cross-pollinate.

In 1400 generations, 30 concurrently evolving populations created this program:

```
++>------>->---<<<------------->------>->
---->------------->>--->------<----------
------<------<-<<--<------------->-------
-<-->------>------->----------->---------
----->-------->------->----------------[>
[--[-[+]]]>[--[+]]-]-------[>[--[-[+]]]>[
--[+]]-]<--<------>------->--------------
--[>[--[-[+]]]>[--[+]]-]<--<-------------
--------->------>->-<-----

```

I calculate the win rate of this bot to be **90.0%** against the current crop. (1135/125/0 tape lengths won/lost/drawn).

## V3 info

Calculated win rate of 89.2% (1124/62/74 tape lengths won/lost/drawn).

## V2 info

The generation program now has analysis to tell which part of the end of the program is unused and trims it before generating the next generations from it. This means that random mutations happen in used parts of the program only and so evolution is faster.

72% against the current crop at the time. (892/204/143 tape lengths won/lost/drawn).

## V1 info

31500 generations, only 12 bots faced. 65% (165/80/7 tape lengths won/lost/drawn). I use all 21 tape lengths.

Potential bots are ranked by:

* most wins then;
* most draws then;
* quickest time drawn then;
* quickest time won

## Trivia

* Mickey is named after my cat and;
* To paraphrase T.S. Elliot: `The Naming of Cats is a difficult matter,
It isn't just one of your brainfuck bots`
* My java bf vm and genetic algorithm is on github.
* The vm is capable of running a complete tournament in under 4 seconds on a single core of an i7 (caution - results are not always identical to the tournaments engine).
> 5 votes

# Answer
# Gambler

This is closely related to my Geronimo bot. But where Geronimo is playing a sure thing, the Gambler tries to be quicker by doing what it does best -- gambling: It goes to the 20th cell and starts zero-ing from there.

That means that it might easily lose just because the arena isn't that big. But if it is, it might be the few cycles that count.

```
(>)*19(>[-])*11

```

<sub>Fun Fact: I was really considering entering a bunch of bots which all look like `(>)*X(>[-])*Y` where `X in 9..29` and `Y = 30 - X`. But I think entering twenty bots would be a little too much :) Or even forty if I had two versions, one which zero-s with `[+]` and one that does it with `[-]`.</sub>
> 4 votes

# Answer
## Dumbot

A remarkably stupid bot that just messes with the environment and hopes that the bots it battles all go off the tape.

```
(+)*50(>-)*7(([.])*50(+)*50>)*7([-])*256

```

(I'm not sure if this even works - it doesn't error out though!)

Annotated (with what I *think* it does):

```
(+)*50      Increase home cell by 50
(>-)*7      For next 7 cells, decrement once
(           Open loop
([.])*50    If cell is non-zero, do nothing. If cell is zero... Still do nothing? I'unno.
(+)*50      Now let's increment it fifty times for some reason.
>)*7        And let's do the above two instructions ten times more, in the next 7 cells
([-])*256    If the cell we're on is non-zero, decrement it continuously and hope it's the enemy.

```

(I will be staggered if this wins a single battle)
> 4 votes

# Answer
# CleverAndDetermined

```
>+>-(>+++[-])*21

```

Sets a few small traps, then races over to the other side, and tries to clear everything, above or below zero. Fails on `----`.
> 4 votes

# Answer
# CropCircleBot

```
[>>[+][-]-<[-][+]+][>[+][-]<[-][+]++]

```

This Bot uses advanced algorithms that were transmitted by aliens throu crop circles they placed on earth. It will change mankind and provide huge technological advancements and even solve many environmental problems.
> 4 votes

# Answer
# BeatYouMate

And because everybody should post a bot that will beat the first bot they post, here's a 5+ decoy laying bot:

```
(>------>+++++++)*4>([(+)*6[-]]>)*21

```
> 4 votes

# Answer
# MetaJSRandomBot

```
+[[>-[->+]>>[-]>-<<[>][+]<]+<]->

```

The idea behind this bot is making something total random that is still a valid js code without too much uselessness. I wrote following code (JSFiddle link) for generating it. Lets see how well it does=)

```
var nchars = 30;
var nbrack = 10;
var alphab = "+ - < >".split(' ');
var s = [];
for(var i=0;i<nchars;i++){
    s.push(alphab[(Math.random()*alphab.length)|0]);
}
var ind1,ind2;
for(var i=0;i<nbrack;i++){
    ind1 = (s.length*Math.random())|0;
    s.splice(ind1,0,'[');
    ind2 = ((s.length-ind1-1)*Math.random())|0 + ind1;
    s.splice(ind2,0,']');
}
s = s.join('')
for(var i=0;i<Math.max(nchars,nbrack);i++){//remove useless stuff
    s=s.replace('[]','');
    s=s.replace('+-','+');
    s=s.replace('-+','-');
    s=s.replace('<>','');
    s=s.replace('><','');
}
alert(s);

```
> 4 votes

# Answer
# Prussian Roulette

Russian Roulette made a bet with his friend Prussian, and now it's his turn to play.

```
>(+)*5(-.[>.[>(-)*10]]>>)*1000

```
> 4 votes

# Answer
# Bigger

**The arms race begins!!**

Both builds and destroys walls of height ~~16~~ 18, bigger than most competitors. Also has a little logic to beat the cloaker, flag-defenders, anti-alternators, and bots that assume an untouched flag

```
+>->+>+>-(>(-)*18>(+)*18)*2(>([(+)*18[-][-[+]]])*2)*21

```

## Annotated version

```
Off by one
==========
Adjust own flag a little for fun
-

Decoy stage
===========
Build decoys

>->+>+>-        Add four quick walls to deter rushers
                Also throw off bots depending on the alternation
(>(-)*18
 >(+)*18)*2     Build four large decoys

Clear stage
===========
(               Repeat the following forever:
  >             Move forward
  ([            Skip if the space is zeroed already
      (+)*18    Bust negative decoys smaller than 18
      [-]       Clear
      [-[+]]    Check that the wall is actually cleared; if it isn't,
                clear in the opposite direction to defeat bots that try
                to sense our clear direction and defend the flag
  ])*2          Repeat the "non-zero" check to guard against the cloaker
)*21

```
> 4 votes

# Answer
# PatientBot

A partly serious bot. this bot will attempt winning by the 100000 cycles limit. it will go to the enemy flag while putting a few traps in the way, decrease it a bit, go back and defend the flag.

```
>++>->->+>+>->->+(>+[-[-[(<)*9--[<--](+)*10000]]])*20

```

it will assume everything bigger than 1 or smaller than -1 is the flag, and when it will encounter one, it will go back. it defends by simply incrementing constantly. this assumes most programs will either use \[\] to check if the flag became 0, and so (+)\*100000 will be much faster

**Edit:** can't get it to work on the BF Joust interpreter. i'm giving up. maybe you should tell me how to improve my code.

**Edit:** now the bot makes the spot just before the flag 2, and after it decremented the flag a bit, it searches for a 2. this is meant to cancel the scenario where the bot would find a 0 cell other than the one before the flag.
> 3 votes

# Answer
# Plodder - EDITED

Instead of zeroing cells via loop, the plodder adds a large constant to each one. This is slow in general, but if the opponent has set up lots of traps, it doesn't make a bit of difference. Results are actually fairly good, especially for mid-range tape lengths.

```
(>----)*2                Set up traps for fast bots immediately
>(+)*7                   More traps
>(-)*17
>(+)*7
>(-)*7
>-
>(-.(+)*126(+.)*4>)*21   Starting with cell nine, stomp on each cell and plod on

```
> 3 votes

# Answer
# 128Bot

Not sure how good or bad this one is, but here:

```
>>(+)*128
<(+)*128
(>)*8
([-]>)*21

```

All I know is that this will be pointless upon sizes less than 12.

Also, as a response to Dumbot, here is "Dumberbot":

```
[-]

```

Then "Dumbestbot":

```
<

```

This is just about as dumb as it can get!

EDIT: I just came up with a really awesome one that I call "ConBot!"

# ConBot

```
>+[.]<(-)*10000

```

This one wins by tricking some opponents into moving off the tape, thus the con.
> 3 votes

# Answer
# Terrible Thor v2

Terrible Thor is a mixed medium slow and fast Rush that uses a small amount of time putting some small decoys (24 steps) before he goes to clear common and enemy territory. He detects enemies and go into fast rush mode and uses BalderV1's original clearing method. It also just plodd the first non-zero cell to prevent traps when enemy isn't detected in case there is a trap. This was originally the first draft of Loke so you'll se a mix between Balder and Loke in this code.

```
>(+)*22
(>)*6 [([>[+[+[+[+[+[+[+[(-)*7-[-[-[-[-[-[-[(-)*116[-]]]]]]]]]]]]]]]]+]-)*2] (+)*22
<<-<<-<
 [ (>)*6 ([>[+[+[+[+[+[+[+[(-)*7-[-[-[-[-[-[-[(-)*116[-]]]]]]]]]]]]]]]]+]-)*2 ] (-)*22 >
+[ (>)*5 ([>[+[+[+[+[+[+[+[(-)*7-[-[-[-[-[-[-[(-)*116[-]]]]]]]]]]]]]]]]+]-)*2 ] (+)*22 >
 [ (>)*4 ([>[+[+[+[+[+[+[+[(-)*7-[-[-[-[-[-[-[(-)*116[-]]]]]]]]]]]]]]]]+]-)*2 ] (-)*22 >
+[ (>)*3 ([>[+[+[+[+[+[+[+[(-)*7-[-[-[-[-[-[-[(-)*116[-]]]]]]]]]]]]]]]]+]-)*2 ] (+)*22 >
 [ (>)*2 ([>[+[+[+[+[+[+[+[(-)*7-[-[-[-[-[-[-[(-)*116[-]]]]]]]]]]]]]]]]+]-)*2 ] (-)*22 >>
([>
   [
    ..(+)*119(+.)*17
    ([>[+[+[+[+[+[+[+[(-)*7-[-[-[-[-[-[-[(-)*116[-]]]]]]]]]]]]]]]]+]-)*2
   ](-)*6<<((-)*8>)*2
  ]-)*2

```

Trivia: Thor is the lightning god of Nordic Mythology.
> 3 votes

# Answer
# SeeSawRush

sets some early decoys, then does a decrement clear with protection against decoys down to -4 at every cell past 9

```
>>>>------          decoy neg6 at cell 4
<+++++              decoy pos5 at cell 3
<----               decoy neg4 at cell 2
<+++                decoy pos3 at cell 1
>>>>                get to cell 5
(----->+++++>)*2    neg5 pos5 neg5 pos5 decoys at cells 5,6,7,8
(                   start attacking at cell 9
    [                   if current cell is nonzero
        (+)*4               handle decoys down to neg4
        [-]                 decrement to zero
    ]
    >                   step ahead
)*21                21 times

```
> 3 votes

# Answer
## BestOffense

is a good Defense

```
>-->+[+]<[-](>(-)*50)*10(>[+])*100

```

We will see how it actually does. In Loop 1 it moves right once and decrements by 128. It repeats this 20 times. In loop B if the cell is not 0, it increments until it is. It repeats this until i goes off the board. He isn't very smart but I wanted to get the game going.

update:

I've added a means to extend most battles into the first part for... fun? Mine still isn't intended to be serious and is not offensive at all. The sarcastic titles wrongness is reflected in the player's skill.
> 2 votes

# Answer
# Stubborn Bot

Move one spot over from the flag, and try to stubbornly prevent the other bot from zeroing the cell:

```
>([+]-)*1000

```

Annotated

```
 >            Move one spot
 (
   [+]        if non-zero increment
   -          decrement if zero
 )*1000       repeat until the game is over

```
> 2 votes

# Answer
# "Random" Oscillator

(Because "Alternator" was already taken).

This bot lays down a series of traps, and it tries to check to see if the enemy has lain similar traps.

```
 >->+>->+>+>->->+(>[+[-]])*21

```

I have attempted to make the traps have somewhat random polarities (-+-++--+) so that the opponent won't pick up on the pattern.
> 2 votes

# Answer
## Clean up on aisle 6

```
(>)*5(-)*4>+[](>[+[-]])*27

(>)*5      Go to cell 5
(-)*4      Decrement by 4
>+         Go to cell 6 and increment by 1
[]         Wait for opponent to clear up cell 6
(>[+[-]])*27  Then go ahead and zero what's forward

```

Lose against rushers if the tape is too short and bots leaving negative decoys.
> 2 votes

# Answer
# Russian Roulette

I have no idea if this bot will work or not... Just have to wait and see!

```
(>->[(+)*10])*5(-)*10

(>         Move forward 1
-          Decrement by 1
>          Move forward 1
[(+)*10]   If cell is zero then go forward else increment by 10
)*5        Do the whole thing 5 times
(-)*10     Decrement by 10

```
> 2 votes

# Answer
# GetOffMate

This is made with 2 central ideas. 1st: the average arena size will be 20, and 2nd: I haven't seen any decoys larger than 5 (if I'm interpreting things correctly) in others their submissions.

```
(>)*19([(+)*6[-]]>)*11

```

Annotated:

```
(>)*19            Like I said, the average arena size is 20 Still kinda stupid though
([(+)*6[-]]>)*21  If a decoy is 123 or bigger, it will increment it to 0 or beyond, and clear it. Known as an Offset clear.

```
> 2 votes

# Answer
I'm gonna do the most stupid thing imaginable:

**The Retard**

```
[+]

```

Since the rules clearly state: "Your bot's goal is to zero the enemy's flag for 2 consecutive cycles **before he zeroes your own flag**", this bot takes the liberty of zeroing his flag as soon as the game starts so that the enemy can't get to it first. Since the rules also state the victory condition: "Your enemy's flag is zeroed **before yours**", this means that the Retard cannot possibly win, but it can also sometimes not lose. Specifically, for it to not lose the enemy must take either an odd number of steps to get to it and start decrementing or for the enemy not to come to it at all; if the enemy takes an even amount of steps to get to it, he will zero the Retard's flag before the retard itself. Clear abuse of the rules but what can I say :)
> 2 votes

# Answer
# PrimesAndWonders

Utilizes a new strategy of offsetting its own flag. And offset its decoys with prime numbers and staggers them a bit more.

```
>>>>>-<<<<<--->------------(-)*5>++++++++++++++++(+)*7>>(+)*13+++++++++++++++++>------------------->+++++++++++++>----------------->++++++++++++++++++++++++++++++>([(+.)*16[-]]>[(-.)*16[-]]>[(+.+.+.+.)*4[-]]>)*7

```
> 2 votes

# Answer
# 2BotsOneCup - Edited (3rd Bot?)

Named in honor of the comment @Won't made on the post about removing this from the hot questions list.

**Unannotated:**

```
>(+)*3>(-)*3>+([)*300(>(-)*12>(+)*12)*2>(([-([(-)*6[+.]])*5])*4->)*21
(]<(-)*30<(+)*30(>)*9((-)*16(<)*8(+)*32(>)*8)*8>((-)*16(<)*9(+)*34(>)*9)*8>
((-)*16(<)*10(+)*36(>)*10)*8>((-)*16(<)*11(+)*38(>)*11)*8>((-)*16(<)*12(+)*40(>)*12)*8>
((-)*16(<)*13(+)*42(>)*13)*8>((-)*16(<)*14(+)*44(>)*14)*8>((-)*16(<)*15(+)*46(>)*15)*8>
((-)*16(<)*16(+)*48(>)*16)*8>((-)*16(<)*17(+)*50(>)*17)*8>((-)*16(<)*18(+)*52(>)*18)*8>
((-)*16(<)*19(+)*54(>)*19)*8>((-)*16(<)*20(+)*56(>)*20)*8>((-)*16(<)*21(+)*58(>)*21)*8>
((-)*16(<)*22(+)*60(>)*22)*8>((-)*16(<)*23(+)*62(>)*23)*8>((-)*16(<)*24(+)*64(>)*24)*8>
((-)*16(<)*25(+)*66(>)*25)*8>((-)*16(<)*26(+)*68(>)*26)*8)*300

```

**Annotated:**

```
>(+)*3>(-)*3>                       Toss two quick decoys out for the faster bots
+                                   Set a trip wire
([)*300                             Unmatched brackets wait three hundred rounds for the
                                    tripwire to be cleared

                                    This section executes if three hundred rounds pass
    (>(-)*12>(+)*12)*2>             Lay four more decoys in case another bot has a tripwire
    (
        ([-([(-)*6[+.]])*5])*4      Rush using the clear code from CounterPunch
        ->                          Lay breadcrumbs just for the hell of it
    )*21
(                                   This section executes if the tripwire is sprung
    ]   <(-)*30<(+)*30              Hop back and beef up the decoys
    (>)*9
    ((-)*16(<)*8(+)*32(>)*8)*8>     Alternate between repairing the decoy and decrementing
    ((-)*16(<)*9(+)*34(>)*9)*8>     each cell to the end of the tape by one twenty eight
    ((-)*16(<)*10(+)*36(>)*10)*8>
    ((-)*16(<)*11(+)*38(>)*11)*8>
    ((-)*16(<)*12(+)*40(>)*12)*8>
    ((-)*16(<)*13(+)*42(>)*13)*8>
    ((-)*16(<)*14(+)*44(>)*14)*8>
    ((-)*16(<)*15(+)*46(>)*15)*8>
    ((-)*16(<)*16(+)*48(>)*16)*8>
    ((-)*16(<)*17(+)*50(>)*17)*8>
    ((-)*16(<)*18(+)*52(>)*18)*8>
    ((-)*16(<)*19(+)*54(>)*19)*8>
    ((-)*16(<)*20(+)*56(>)*20)*8>
    ((-)*16(<)*21(+)*58(>)*21)*8>
    ((-)*16(<)*22(+)*60(>)*22)*8>
    ((-)*16(<)*23(+)*62(>)*23)*8>
    ((-)*16(<)*24(+)*64(>)*24)*8>
    ((-)*16(<)*25(+)*66(>)*25)*8>
    ((-)*16(<)*26(+)*68(>)*26)*8
)*300

```

One triplock bot wasn't enough for this contest, so here's my locking entry. It isn't as clever by half, but easily makes up for it in speed.

**EDIT:** A couple things were clear about this bot from the last round - it lost *a ton of points* due to ties with other bots that were purely defensive. So... the new and improved version uses a tripwire timer. If the tripwire isn't set off in the first 300 rounds, it will build some token decoys for other tripwire bots and then make a rush attack. If the tripwire **is** sprung, it will methodically decrement each cell by 128 while at the same time repairing the first decoy it set up.

The main thing this bot gets hurt by is the round limit of 10,000 rounds. Some of the longer tapes can take it well over that to clear (in the 15,000 to 20,000 round range), so it is currently eating a lot of ties that it would ultimately win.

**NOTE:** The rule on unmatched brackets in parenthesis (such as `([)*300`) has become somewhat ambiguous due to the comments here. The unannotated version above will run perfectly fine with the current version of the control program. For the more pedantic, there is a version that follows the letter of the rules available here with all of the brackets expanded out. It weighs in at over 170.5kb, and has 27,609 sets of parenthesis to expand (but all brackets are matched). Warning - on my machine this takes about 5 minutes to parse.

If you would like to try this bot on EgoJSout, there is an equivalent compliant version of the code here. This version uses the `[{}]` syntax, so it isn't compatible with the control program for the challenge.
> 2 votes

# Answer
# Fast Trap Clear Bot

```
(->)*9(+[-]>)*20

```

Lays down a set of it's own traps then proceeds to clear opponents traps. This works by adding one to remove `-1` traps, if that hasn't worked it zeros out with `[-]`.

It is extremely effective against **Alternator**, winning 16 lengths out of 21. Not tried against many others yet.

It's also fast so bots that lay larger decoys like **DecoyBot** don't have the time to place much of a wall.

I now realise is similar to **FastClearBot** example:

```
[          Find a non-zero cell
+++         Increment at first, since it could be a decoy
[-]         Set the cell to zero
]

```

But it does away with the outer loop, which means that for a cell that is already `0` it runs four instructions: `+[-]` compared to the FastClear's single `[`. When a cell isn't zero however it benefits by not having that extra comparison.
> 2 votes

# Answer
# TimedAttack

Hangs out at its own flag and spins its wheels for a while, then sets out for the opposing flag.

```
(-)*1024
(>+)*9
([-][-[++-]][+-]->)*21

```

This bot will leave its flag at its original value if the opponent doesn't mess with it. After that much time has passed, it can safely assume that the opponent isn't going for its flag, so it will take its time triple-checking that every possible enemy flag location is zeroed (and leaving decoys everywhere for the hell of it).
> 2 votes

# Answer
# ScaredyBot

Somewhat similar to StubbornBot, this neurotic little bot tries to barricade its flag and just avoid losing.

```
>+>(-)*8>(+)*7<<(+)*140>[]<[+]<[[+]+]

>+          Move right and start a positive buffer
>(-)*8      Move right and put up a negative buffer, slows bots that use decrement
>(+)*7      Move right and put up a positive buffer, slows bots that use increment
<<(+)*140   Move back to cell 1 and add a lot of numbers
>[]         Move to cell 2 and stay there until it is 0
<[+]        Agh! Someone's getting close! Move to the positive buffer and flood it with
            increments
<[[+]+]     That didn't work! Protect the flag!

```

Does manage to get a draw against many opponents under many conditions. It even wins sometimes (usually when the opponent overshoots the tape).
> 1 votes

# Answer
**Stall Bot**

Hope your opponent makes a mistake. The first "-" sets the flag to 127. The flag is odd. If the opponent is changing the flag, then the value is either not changing (opposite my move), or it's moving by 2, which is even. The only way I can hit 0, is if they brings the score to -1 or 1, and let me move back to 0.

```
-[+-]

```

The problem is that the opponent will win at the end of the game because of a bigger flag.
> 1 votes

# Answer
# Roomba

Isn't very intelligent but tries its best at edge detection.

```
((>)*2((<)*2(+)*10)[>(-)*10])*100

```
> 1 votes

# Answer
# PyBot

This bot is actually written in Python using my PyBrainFuck module. Apart from that, it's not much different or better than most bots already posted here.

```
#!/usr/bin/env python

import pybrainfuck, random

bf = pybrainfuck.BrainFuck("pybot.bf")

# DEFEND

# To prevent against the likes of 'GetOffMate'
bf.sub(6)

alternate = False
for i in range(9):
    bf.right()
    if(alternate):
        if(random.randint(0, 5)):
            bf.sub() # set to 128
        else:
            bf.add(random.randint(2, 6))

    alternate = not alternate

# ATTACK
for i in range(21):
    bf.right()
    bf.zeroCell()
    # throw in a quick decoy here and there...
    if(random.randint(0, 3)):
        bf.add(random.randint(1, 3))

bf.end()

```

When run, it produces a output similar to:

```
------>>->>->>->>->>[-]++>[-]>[-]++>[-]>[-]+>[-]+>[-]+++>[-]+>[-]>[-]>[-]>[-]+++>[-]++>[-]+>[-]++>[-]>[-]+>[-]>[-]>[-]+>[-]++

```

Feel free to use the example above if you don't want to integrate the python script somehow into the arena system.
> 1 votes

# Answer
# EndTitled - (last score 187, f\***ing murder)

Sacrifices fine motor skills for aesthetics.

```
[[>>>>>>>+++++++<<<<<<<>------     --------        ---->>>+++++++++++++++    +++++++
++++++++++++++++++++++++>-----     --------     --------->>>+++++++++++++    +++++++
++++++++++++++++++++++>-------     --------   ------->>>+++++++++++++++++    +++++++
+++++++++++++++++>------------     ----->>>  +++++++++++++++++++++>[+++++   >-------
  --+++++       >----- -++>---     ----+++  ++>----       -----[-]]>[++++[-]>-------
  ----+++              ++>----     ------- +++++[-]>-                ------- -++++++
  ---------[-]]>[++    +[-]>--     ------- -++[-]>                -----------+++
  +-----------+++++   [-]>----     ---[-]] [+++++                ------------+
  +++-------------+    [-]>--      ------- +++++[-]>-                --------[-]]>
  [++[-]>----------    -++[-]>     ------- ----+++                ++[-]>---------++
  [-]>---              ------[     -]]>[++ +++[-]>---                ------ -+++++[-]>
  -------              ---+++++   +[-]>--  ---++++       +[-]>---------[-]]   [-]>[++>-
----------+            ++++[-]>-----------+++   ++[-]>---------+++++[-]>--[   -]]>[+++
[+]>-------             ---++++++--------     ---+++++[-]>---------++[-]>---    ------[
-]]>[++++++               -----------++         +++[-]>-------+++++[-]>----    -----++
+++[-]>---                 --[-]]>[+              ++++[-]>-++[-]>    -------   ----[-]]>

----+++++[-]>-               --------+++++        [-]>---------[-]]>+++++++++[   [-]>[-]>[-]]]

```

Goodluck to all.
> 1 votes

# Answer
# DecoyMaster

A bot that loves decoys. Sets 4 larger decoys backwards, then starts clearing the tape while leaving a trail of decoys. It can solve smaller decoys easily.

```
(>)*4(+)*10<(-)*10<(+)*30<(-)*30(>)*3(>+)*2(>-)*2(>[-[++[(+)*10[-]]]]+)*21

```

Explained:

```
(>)*4
(+)*10          Set some decoys backwards
<
(-)*10
<
(+)*30
<
(-)*30
(>)*3
(>+)*2          Small decoys while moving
(>-)*2
(>
  [
    -           Detect small decoys
    [
      ++
      [
        (+)*10  Clear
        [-]
      ]
    ]
  ]
  +             Set decoy and move
)*21

```
> 1 votes

# Answer
# ScribeBot

The scribe bot makes the tough choice: to take down the small decoys efficiently or the large ones? He assumes that a majority of the decoys he encounters are similar to the first. He tries to take down the first decoy using the swing method and if he fails, he leaves a note for himself. He then checks his note to see if he should continue to use this method.

```
---      Small offset
>
(-)*128  Large neg decoy
>
(-)*19   Small neg decoy
>
(+)*128  Large pos decoy
>
(+)*19   Small pos decoy
(>)*5    Move to 10th pos
([      Keep moving until we hit something

    <[-]>    Incase we're at the 10th pos and 9th is not empty

    Take down using swing method
    (-[)*20  Remove 20 and jump if 0
    (+)*20   Revert
    (+[)*20  Add 20 and jump if 0
    <+>      Take a note
    [+]      Kill it
    (])*20   End Conditional
    (])*20   End Conditional

    <[  if note exists, use brute force method
    >>
    (   While we haven't reached the end
        [-]  Brute force kill
        >    Next
        [+]  Brute force kill
        >    Next
    )*10
    ]

    >>  else continue using swing method
    (   While we haven't reached the end
        (-[)*20  Remove 20 and jump if 0
        (+)*20   Revert
        (+[)*20  Add 20 and jump if 0
        [+]      Kill it
        (])*20   End Conditional
        (])*20   End Conditional
        >       Next
    )*20
]>)*20  Empty space, move next

```

## Non-annotated Version:

```
---> (-)*128>(-)*19> (+)*128>(+)*19(>)*5([<[-]>(-[)*20(+)*20(+[)*20<+>[+](])*20(])*20<[>>([-]>[+]>)*10]>>((-[)*20(+)*20(+[)*20[+](])*20(])*20>)*20]>)*20

```
> 1 votes

# Answer
# ParanoidBot

ParanoidBot is paranoid. It wants to do a full tape clear, but thinks you could be attacking its base at any time. Hence every so often, it runs back home and checks the house - if it finds you, then it has a chance of successfully tying you to a chair while it continues clearing.

(Half serious submission - am curious as to how this will go. Typically loses to bots that hide in their base.)

```
>-
(
  (>)*8
  (+.)*108
  (<)*8
  +[
    <+
    ((+)*128 (>)*9 (+.)*55 (<)*9)*5
    ((+)*128 (>)*10 (+.)*54 (<)*10)*5
    ((+)*128 (>)*11 (+.)*53 (<)*11)*5
    ((+)*128 (>)*12 (+.)*52 (<)*12)*5
    ((+)*128 (>)*13 (+.)*51 (<)*13)*6
    ((+)*128 (>)*14 (+.)*50 (<)*14)*6
    ((+)*128 (>)*15 (+.)*49 (<)*15)*6
    ((+)*128 (>)*16 (+.)*48 (<)*16)*6
    ((+)*128 (>)*17 (+.)*47 (<)*17)*6
    ((+)*128 (>)*18 (+.)*46 (<)*18)*6
    ((+)*128 (>)*19 (+.)*45 (<)*19)*6
    ((+)*128 (>)*20 (+.)*44 (<)*20)*6
    ((+)*128 (>)*21 (+.)*43 (<)*21)*6
    ((+)*128 (>)*22 (+.)*42 (<)*22)*7
    ((+)*128 (>)*23 (+.)*41 (<)*23)*7
    ((+)*128 (>)*24 (+.)*40 (<)*24)*7
    ((+)*128 (>)*25 (+.)*39 (<)*25)*7
    ((+)*128 (>)*26 (+.)*38 (<)*26)*7
    ((+)*128 (>)*27 (+.)*37 (<)*27)*7
    ((+)*128 (>)*28 (+.)*36 (<)*28)*8
    ((+)*128 (>)*29 (+.)*35 (<)*29)*8
  ]-
)*3
(
  (>)*9
  (+.)*106
  (<)*9
  +[
    <+
    ((+)*128 (>)*9 (+.)*55 (<)*9)*5
    ((+)*128 (>)*10 (+.)*54 (<)*10)*5
    ((+)*128 (>)*11 (+.)*53 (<)*11)*5
    ((+)*128 (>)*12 (+.)*52 (<)*12)*5
    ((+)*128 (>)*13 (+.)*51 (<)*13)*6
    ((+)*128 (>)*14 (+.)*50 (<)*14)*6
    ((+)*128 (>)*15 (+.)*49 (<)*15)*6
    ((+)*128 (>)*16 (+.)*48 (<)*16)*6
    ((+)*128 (>)*17 (+.)*47 (<)*17)*6
    ((+)*128 (>)*18 (+.)*46 (<)*18)*6
    ((+)*128 (>)*19 (+.)*45 (<)*19)*6
    ((+)*128 (>)*20 (+.)*44 (<)*20)*6
    ((+)*128 (>)*21 (+.)*43 (<)*21)*6
    ((+)*128 (>)*22 (+.)*42 (<)*22)*7
    ((+)*128 (>)*23 (+.)*41 (<)*23)*7
    ((+)*128 (>)*24 (+.)*40 (<)*24)*7
    ((+)*128 (>)*25 (+.)*39 (<)*25)*7
    ((+)*128 (>)*26 (+.)*38 (<)*26)*7
    ((+)*128 (>)*27 (+.)*37 (<)*27)*7
    ((+)*128 (>)*28 (+.)*36 (<)*28)*8
    ((+)*128 (>)*29 (+.)*35 (<)*29)*8
  ]-
)*3

... etc

```

(full code here)
> 1 votes

# Answer
# MetalDetector

```
(-------->)*9
([+]>)*21

```
> 1 votes

# Answer
# Twitcher, Stitcher, Wut, and 99BottlesOfBats

I haven't coded in BF before, but with a language so minimalistic, the challenge isn't really in knowing all the operations, but knowing how to combine them. Thought that I would put my two cents in. I started out with seven untested bots based on no real strategy, and ended up with four tested bots employing various strategies. I will include them all in this one post, for the sake of convenience.

## Twitcher

Twitcher builds a pyramid of alternating polarity with the metaphorical capstone as a tripwire. Twitcher goes back and forth, incrementing all decoys in the pyramid, and returning to the top to test whether the tripwire has the same value as it had initially. If it does, Twitcher goes back to building the pyramid, and extends the tripwire as far as cell 9, at which point it builds the pyramid more and keeps checking. Once the tripwire has been sprung, Twitcher rushes back and builds all of the decoys by 20 in the correct polarity, then rushes ahead and begins to clear, by first incrementing all non-zero cells by positive 27 and then fast-clearing them in the negative direction.

```
(>)*4-<+<-<+>>
+(<-<+)*1(>)*3+[<<(-)*20<(+)*20(>)*8(>[(+)*27[-]])*10000]->+
(<-<+)*2(>)*4-[<<(+)*20<(-)*20<(+)*20(>)*8(>[(+)*27[-]])*10000]+>-
<+(<-<+)*2(>)*5+[<<(-)*20<(+)*20<(-)*20<(+)*20(>)*8(>[(+)*27[-]])*10000]->+
(<-<+)*3(>)*6-[<<(+)*20<(-)*20<(+)*20<(-)*20<(+)*20(>)*8(>[(+)*27[-]])*10000]+>-
<+(<-<+)*3(>)*7+[<<(-)*20<(+)*20<(-)*20<(+)*20<(-)*20<(+)*20(>)*8(>[(+)*27[-]])*10000]->+
((<-<+)*4(>)*8-[<<(+)*20<(-)*20<(+)*20<(-)*20<(+)*20<(-)*20<(+)*20(>)*8(>[(+)*27[-]])*10000]+)*10000

```

Twitcher is named for its 'twitchy' behavior as it builds its pyramid and checks its tripwire.

## Stitcher

Stitcher creates a quick series of size-one decoys of alternating polarity, then rushes ahead to the ninth square and begins clearing non-zero cells with a positive increment of 18 followed by a fast negative clear.

```
(>+>-)*2(>)*4(>[(+)*18[-]])*30

```

Stitcher is named for the pattern of +1/-1 decoys it leaves, similar in appearance to stitched thread. Also, it rhymes with Twitcher.

## Wut

Wut first places a -1 decoy at cell 1, followed by +2 decoys at 2, 3, and 4. It then returns to 1 and changes the -1 decoy to a -21 decoy, then rushes to cell 9 and clears with a positive increment of 18 followed by a fast negative clear.

```
>-(>++)*3(<)*3(-)*20(>)*7(>[(+)*18[-]])*30

```

Wut has no particular motivation for its name.

## 99BottlesOfBats

99BottlesOfBats creates a +--++--+ decoy pattern of height 1 before performing a two-stage clear, with a nested decrement of 9 followed by a positive clear, and then a nested increment of 9 followed by a negative clear, which it performs only on cells that were initially non-zero.

```
(>+>->->+)*2(>[[-[-[-[-[-[-[-[-[-[+]]]]]]]]]][+[+[+[+[+[+[+[+[+[-]]]]]]]]]]])*9999

```

99BottlesOfBats is named after the popular song (and programming challenge) "99 Bottles," combined with the term 'BattleBots' with a vowel swap. The 99 comes from the two 9-depth clears, and the 9999 loop at the end (which is mostly to fit with the theme).

# Performances

In tournaments excluding LethalLokev2.1 (which required more computation than other opponents), all of these bots achieved a score between 400 and 500, with the following relative ranking: 1. Wut 2. 99BottlesOfBats 3. Twitcher 4. Stitcher

According to the most recent tournament results and the results from the tournament I ran with additional bots I later abandoned, I estimate that all of these four bots will place in the top 25.
> 1 votes

# Answer
# MultiVAC

*I wish it would also generate better versions of itself :(*

Builds a big defensive wall, then attacks. Also tries to clear smaller decoys faster.

```
>                     # Build 9 big decoys
(-)*4>(+)*4>          # A few small ones
(>)*6

(<(-)*80<(+)*80)*3    # And more big ones
<(+)*76               # For Confusion :)
<(-)*76

<(-)*28               # Just for you, Wall E

(>)*10

(                     # Walk forwards and clear everything
  ([+                 # is it 0 ~ 14 ?
  {
    (-)*16
    (-[               # Is it neg(14) ~ 0 ?
    {
      (-)*112         # Big decoy / flag clearen (128~16=113)
      [+]
    }
    ])%16
  }
  ])%16
  [-]                 # Counter DecoyBot ~_~
  (+)*2               # Leave a small trail behind
  >

  ([-                 # The same thing with reversed polarity
  {
    (+)*16
    (+[
    {
      (+)*112
      [-]
    }
    ])%16
  }
  ])%16
  [+]
  (-)*2
  >

)*11

```

This is practically only a test program for my bfjoust online-toolset, but it performs not so bad when I tested it.

---

Here is the minified version for the control program:

```
>---->++++(>)*7(<(-)*80<(+)*80)*3<(+)*76<(-)*76<(-)*28(>)*10([+[+[+[+[+[+[+[+[+
[+[+[+[+[+[+[+(-)*17[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[(-)*112[+]]]]]]]]]]]]]]]]]]]]]]
]]]]]]]]]]][-]++>[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-[-(+)*17[+[+[+[+[+[+[+[+[+[+[+[+
[+[+[+[(+)*112[-]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]][+]-->)*11

```
> 0 votes

# Answer
# The Wallmaster

Partially based on other walling bots, working on the concept that it's faster to build a wall than to clear one. Therefore, it'll be much faster to build 9 walls than to break 'em all...

```
+             Flip the flag to mess with people
(>)*9
[+](+)*78     First wall
(
  <[-](-)*78  Build those walls
  <[+](+)*78  And build them tall
)*4
(>)*9
[+]
(
  [+[+[+[+[+[-]]]]]]>  Test the waters with 5 then clear
  [-[-[-[-[-[+]]]]]]>
)*10

```
> 0 votes

---
Tags: king-of-the-hill, brainfuck
---


title: Manhattan Police

text:
# Question
Title: Manhattan Police
## Introduction

You are the police chief of the NYPD and you have been tasked to position police officers so that all of the streets are patrolled. Your squad is short-staffed, however, meaning that you need to position as little officers as possible.

## Challenge

Given a map of blocks, you must return the smallest number of officers needed to secure the streets.

## Rules

There are three types of police officers: an L cop, a T cop and a cross cop. The T cop can see in three directions only. The L cop can see down two streets which are perpendicular. The cross cop can see down all four streets.

The map will be supplied via argv or STDIN as space separated numbers. The numbers represent the number of blocks in each column. For example:

### Input `2 1` represents the following map:

### Input `3 1 2 4` represents the following map:

A police officer may only be placed at an intersection and its view may only be along the side of a block (cops may not look into uninhabited areas).

A cop can only see for one block and cannot look along a street where another police officer is looking meaning that sight lines must not overlap.

## Examples

Input: `2 1`

Output: `4`

Input: `2 2`

Output: `4`

Input: `3 1 4 1 5 9`

Output: `22`

## Winning

The shortest code wins.

# Answer
> 7 votes
## CJam, ~~68 61 84 ... 59 49 48~~ 79 bytes

```
l~]__,+:+M@{:Ze<:X2/)_2*X-@+@@-\Z}*;[YY]/_,(\R*_,,:)W%{2\2*1a*+2+/_S*\,(@+\}/;+

```

Takes input in the same format as in question.

*UPDATE* : Fixed the algorithm for test cases similar to what pointed out by @nutki. Although it made the code almost double in size, will try to golf it now that its fixed.

**How it works** *(Slightly incomplete, will add the `2 1 2` parity explanation later)*

As soon as I saw this question, I knew that there would be a mathematical formula to get the answer. After trying a couple of combinations, I figured that the formula is `2 * Number of blocks - Number of shared streets`

Lets check is for `2 1` case:

```
2 * 3 - 2 = 4

```

Correct.

Lets check for `3 1 2 4` case:

```
2 * 10 - 10

```

Correct again. Yipee, so the code is

```
l~]:L:+2*L:(:+L(+-[{_@e<}*]:+-

```

Now lets try this on some more examples:

```
3 3

```

Output:

```
2 * 6 - 7 = 5

```

But wait, the actual answer is 6

Lets try another:

```
5 5

2 * 10 - 13 = 7 // Answer is 9 instead.

```

You see the pattern ?

For every `N N` block pair, where N is positive integer greater than `2`, I require `float((N+1)/2)-1` extra cop apart from the formula above. Lets verify it again:

```
5 5 3

2 * 13 - 18 = 8 // Answer is 11

```

In the above example, we have 1 `5 5` pair and 1 `3 3` pair (from the `5 3` blocks)

Lets try another example

```
5 5 4 4

2 * 18 - 27 = 9 // Answer is actually 14

```

You must be thinking that there are only `5 5`, `3 3` and `3 3` pairs (from blocks `5 5`, `5 4` and `4 4` resp.) , thus only 4 extra cops required, but there is one more pair.

From the blocks `4 4`, we used up only `3 3` so we have `1 1` free, this makes up another `3 3` block pair which can be visualized using the image below:

The red outlined are the usual pairs, the blue outlined is the perpendicular pair which I am talking about above.

It's kind of hard to explain as while the red outlined are just sharing 1 side of the pair, the blue one is sharing 1 side + 1 block too. But this logic works for all block combinations.

The code now is simply calculating that.

```
l~]__                        "Read the input numbers, convert to array and make two copies";
     ,+                      "Get the number of columns and add that to the block array";
       :+                    "Sum the array elements to get number of blocks + columns";
         M@                  "Push empty array to stack and rotate input array to top";
{                         }* "Run this block for each pair in the block array";
 :Ze<:X                      "Store the later block size in Z, and minimum of two in X";
       @\-                   "Rotate swap and subtract shared sides from total sum";
          X)Y/(:T+           "Increment halve and decrement. Store in T and add to sum";
                  XTY*-      "Find unused blocks from this pair for perpendicular pairs";
                       @+    "Add unused blocks to the array M";
                         Z   "Push Z to stack to be used in next iteration";
           ;[YY]             "Pop the last pushed Z and push array [2 2] to stack";
                /,(+         "Check how many perpendicular pairs exist, add to total sum";

```

*Note that `2 * Number of blocks - Number of shared sides` can also be written as `Number of blocks + Number of columns - Number of shared sides between adjacant columns`*

Try it online here

---
Tags: code-golf
---