2
The challenge is to write a brainf*** program that searches sequentially through memory for the first NON-zero cell.
The program should start somewhere in fairly low memory (there will probably be some overhead/counters/etc.). Once the program starts checking cells, it should continue to the right, checking every cell in sequence until it reaches the first non-zero cell, then stop.
Testing will be performed for several random cells and values. Examples might look like: m(13) = 1, or m(144) = 137, or m(983) = 231. The actual values will be randomly generated once and used for all entries. The cell values of 1 and 255 will also be tested.
Scoring - different from the usual
- code golf, lowest score wins
- in the case of a tie, earlier entry wins
- any continuous series of identical commands that changes pointer position or cell value counts as 1 point.
> 1 point
> > 1 point
> > > > > > > > > > > > > > > > > > > > > > > > > > 1 point
< < < < < < < < < < < 1 point
+ + + + + + 1 point
- - 1 point
[ opening a loop = 1 point
] closing a loop required, so 0 points
one point for EACH input or output
. . 2 points
. . . . . . 6 points
, 1 point
, , 2 points (not that anyone would ever do this)
The python 3 program I will use for scoring is found here:
http://pastebin.com/RJi72BHa
4Welcome to PPCG. We tend to prefer challenges that are not language specific. The language restriction means this challenge has a most definite shortest answer, which is rather limiting. Also I'm a little confused by the idea of a brainfuck program searching memory. Brainfuck is normally run as a virtual machine whose memory is set to all zeroes at the start. Do you have or know of a brainfuck interpreter that allows data to be poked into the memory before running? also, where in the memory can the submitted brainfuck program store its own variables? – Level River St – 2015-08-10T16:03:50.677
Thanks for your questions. I knew this one would be a confusing one to ask. So I will try to clarify. This question only makes sense for BF, any other language and it wouldn't be an issue. What got me wondering about this is: you have probably seen the simple example of BF code [>] that is go through memory and stop on the first zero cell. Well I wanted to write the opposite version. Go through memory with an unknown series of zero cells and stop on the first non-zero cell. As for testing programs, I will place a random value (1-255) somewhere in a random cell. All of the cells before it ... – a62 – 2015-08-10T16:16:09.100
...will be zero. So a valid program will start at the first available cell (to the right of the program itself) and if zero, continue checking to the right, maybe for hundreds of cells, until the first non-zero cell is found. – a62 – 2015-08-10T16:17:11.403
Also, this is regular vanilla BF, so where you store your variables? That's what BF is all about. – a62 – 2015-08-10T16:19:49.610
Do you want it to output the first non-zero cell, or just find it? Can it change the value there, or must it remain the same? Does the state of the tape at the end matter at all, or is the position of the pointer the only thing that matters? – BrainSteel – 2015-08-10T16:37:11.413
@BrainSteel the location of the first non-zero cell would be more relevant, but that's a way, way more difficult problem. And it would need some boundaries on how long the memory was. – Level River St – 2015-08-10T16:46:57.077
3
@vihan Consensus is that we do not censor language names. Brainfuck is the correct name for this language, and it is only profane if you insist on viewing it that way. In any case the profane part of the name is not insulting to any particular group, so should not cause offence among adults. http://meta.codegolf.stackexchange.com/q/1136/15599 . This type of censorship makes the questions less searchable. Anyway I have decided not to roll back your edit as it would be yet another pointless edit, but please bear this in mind in future.
– Level River St – 2015-08-11T05:14:53.403@steveverrill Although it is not offensive for humans, entreprises' proxies (word blacklist) happen to find it offensive, which means the page can't be accessed without overpassing security... – Thrax – 2015-08-25T12:11:38.313
1@Thrax that point was mentioned in one of the answers to the meta question I linked. I'm still against censoring it. You shouldn't be using your work computer to access Programming Puzzles and Code Golf anyway. I never do ;-) – Level River St – 2015-08-25T13:13:59.203
Do we just have to move the pointer to the first non-zero cell, or do we have to do something special to it? – ASCIIThenANSI – 2015-08-25T18:06:24.837