Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - harold

Pages: 1 ... 5 6 [7] 8 9 ... 16
91
Miscellaneous / Re: Religion Discussion
« on: October 03, 2013, 04:33:40 am »
De-evolution makes no sense, really. If that was a pattern, that would mean that "worse" individuals would systematically be more successful (ie has more offspring that is also itself successful), which is a direct contradiction of what it means to be "worse" in evolution. Being systematically more successful by definition means better.

Also, in programming, evolution algorithms are perhaps not used widely, but they have their uses. They work on the same principles as real life evolution, and they do work - which isn't exactly proof that they have to work in real life as well, but at least an indication that it's not completely crazy. Note the step "select the best-fit individuals for reproduction" - that's the crucial part, the entire theory of evolution (and evolutionary algorithms) hinges on that very non-random selection.

92
Math and Science / Re: Algorithm Optimising
« on: September 27, 2013, 09:22:53 am »
Ok, maybe I get it now, if it's roughly similar to this:
Code: [Select]
shl a, 1 ; a is a 0.k fixpoint number (where k is "big enough")
rol string,1 ; doesn't affect carry because I say so
neg.c a ; negate if carry
Do that thing for some number of times that has to do with b.
Right?

93
Miscellaneous / Re: Birthday Posts
« on: September 20, 2013, 02:08:57 pm »
Congratulations, Keoni
(yes I know, my dutchness is obvious)

94
Computer Programming / Re: Addition in the bitfield domain
« on: August 22, 2013, 01:45:34 pm »
Well, I solved it. I'm sure a couple of operations can be shaved off, but this is a proper solution:
Code: [Select]
uint an = ~av & am;
uint bn = ~bv & bm;
uint g0 = an & bn;
uint g1 = av & bv;
uint p0 = an ^ bn;
uint pg1 = av | bv;
uint g0l = ~g0 & ((g0 << 1) | 1);
uint g1f = g1 & ~(g1 << 1);
uint nc = (p0 + g0l & ~p0) - g0l | g0;
uint m1 = ~pg1 | (pg1 & g1f);
uint c = (pg1 + g1f & m1) - g1f;
uint cm = (c | nc) << 1 | 1;
uint m = cm & am & bm;
uint v = av + bv;
The inputs are (am, av) and (bm, bv), the output is (m, v)

The basic idea is that you can use a "known carry" to select a whole "will propagate carry"-block. That's what the (a + b & ~a) - b stuff is about - that's the main breakthrough that led to this algorithm. There are some details that are different on the "carry is known to be 1" and the "carry is known to be 0" sides, but in general it does the same thing for both and then combines the answer. Can't you do it in one go, you may wonder? I'm not sure, but I don't think so. I originally thought so, but a couple of details are different and they mess things up. Anyway, this isn't too bad.

The shitty variable names like g0 are "generates a 0 carry", pg1 = "propagates or generates a 1 carry", p0 = "propagates a 0 carry", g1f = "first of g1" (ie the rightmost bit of every run of 1s), g0l = "last of g0" (one past the last 1 of a run of 1s)

95
Miscellaneous / Re: Random YouTube Videos
« on: August 20, 2013, 03:04:58 pm »
Not a youtube video:


96
Anime and Manga / Re: Bleach
« on: August 20, 2013, 04:15:53 am »
There's a new chapter? I thought they had pretty much stopped..

97
Computer Projects and Ideas / Re: haroldbot (theorem prover / solver)
« on: August 11, 2013, 11:27:16 am »
Update: added custom functions.

98
Computer Projects and Ideas / Re: haroldbot (theorem prover / solver)
« on: August 05, 2013, 03:28:26 pm »
Small update: added ternary operator.

99
Site Feedback and Questions / Re: (Poll) Can anyone access this URL?
« on: August 01, 2013, 03:21:47 pm »
No problems.
http://xlib.mtv-music-generator.com/easter/ is 403 Forbidden, but probably intentional (right?)

100
Lol I have 2900 lines of C#, 500 lines of C++ and 60 lines of assembly, and that's not counting anything that has to do with user interaction (there's not a lot of code there, maybe 200 lines).
About 1300 lines have to do with tutorial mode, but those are also used in puzzle generation (to make sure that lower-level puzzles don't require hard steps, as well as to ensure that higher-level puzzles do require hard steps).
Most of the rest is puzzle generation.

101
Site Feedback and Questions / Re: Signatures & ponies
« on: July 26, 2013, 10:51:36 am »
Wasn't/isn't there some rule against Ridiculously Huge Signatures?

102
Computer Programming / Re: [lua] [ipad] binary puzzle project
« on: July 25, 2013, 05:17:16 pm »
I'd go for showing it automatically - the only good thing about a validation button that I can see is that if you planning to fill in a 1 but it should be a 0, then you click the cell and get a zero first and then you win unexpectedly (if you even use that way of doing input).
However, there is almost no chance of that happening. The last cell is always absolutely trivial to fill in, so the user won't wrongly believe it to be a 1.

103
Computer Programming / Re: [lua] [ipad] binary puzzle project
« on: July 25, 2013, 05:01:30 pm »
about the error thing: yeah for 3 in a row thing i could indicate, but that's about it... like 2 identical rows... should i indicate them as well?
Maybe, up to you, I chose to make the error indicators "stupid" so they wouldn't give you too much information but just help you along when you type a cell in wrong. Whether "identical rows" is stupid enough (in that sense) or not, I don't think there's an objective answer to that anyway. And of course making it indicate more complex errors is a valid choice as well.

104
Computer Programming / Re: [lua] [ipad] binary puzzle project
« on: July 25, 2013, 04:52:32 pm »
Here are two more ideas:
- simple error indicators (that say when a row or column is definitely wrong, for example the no-3-in-a-row or the counting rules are broken)
- a tutorial mode, using next-step suggestions with explanation for why that step can be made (I know my own implementation of it doesn't do an especially good job at the explanation, but it's something, and at least it can get you unstuck)

The first one is trivial to implement, but might not be as useful.
The second is hard to implement, but useful, and when you've implemented it you can build level-select on top of it (by banning hard steps at low levels and by calculating how hard a puzzle is in total so you can "aim" for a certain range of hardness for each level)

105
ASM / Re: Binary Puzzle solving/generating
« on: July 23, 2013, 05:59:06 pm »
Ah yes this thread, I sort of forget to ever update it.

Ok, in a sort of high level overview, the best algorithm I know for generating instances is this:
 - generate a fully filled in board (using that pseudocode algorithm from the opening post, there are some issues)
 - try some random subsets of those bits as instances, try to solve them to find out whether they're solvable instances
 - from all solvable instances, take the hardest one

So, how to select a fully filled board.
In 8x8 puzzles, there are only 4111116 such configurations (much fewer if you don't count symmetric solutions, there are many sorts of symmetry). For other sizes, the number is similarly "unexpectedly low" (compared to the full 2^size)
Select a random number up to the number of possible configurations, generate boards in lexicographical order until you reach that index (alternatively: store them all in the program, that array is pretty small). That's surprisingly fast if you use the following tricks:
 - consider only valid rows. There's no point in doing it bit by bit. Do a whole row at the time. There are only 34 possible rows of length 8.
 - consider only rows that don't immediately violate the no-3-in-a-row rule vertically.
 - consider only rows that don't immediately violate the 4-zeroes-per-column rule, using the column-counting approach from the pseudocode in my first post. The last row is implied by the column counts.
Using those 3 tricks, the only constraint you can violate is no-two-equal-columns, that's why I concentrated on that. That's a pretty annoying check to do.
Tip: you can use (797 * row) >> 8 to map the 34 valid length-8-rows to non-overlapping indexes in [0, 64]. Using that, you can check for duplicate columns by transposing the board and then ORing together 1 << row_to_index(rows in the transposed board). If that has fewer than 8 set bits, at least one column appears twice.
Still it's probably not fast enough (may take a second, or several on slower hardware) and there a big speed difference between high indexes and low indexes. You can cut that time down enormously by storing an array of how many boards there are if you start with a certain row. That array is only 34 (for 8x8) ints long, and is in fact perfectly symmetrical around the middle, so you can store only half of it if you want (not that it matters..)
Changing the indexes of the boards slightly, leaving perfect lexicographical order behind, the symmetry around the middle is due to the fact that the last half of the boards is the same as the first half, but both reversed in order an inverted in its bits. You can cut it in half there, and when generating a random board, choose which half and which index within that half.
Similar trickery can be done with the second row, cutting the time it takes down so much that you can afford to do a binary search over all the boards (you don't need that, I just needed it because I wanted to find the indexes of the rotated and mirrored boards (the index of the inverted board can be found trivially due to the symmetry that I already mentioned) - I was building a database with Very Hard Instances and thought I might as well put all symmetrically equivalent boards in it as well).

Then, how to solve an instance.
Filling the cells implied by the no-3-in-a-row rule is easily done with some bitmath.
The rest is more complicated, but it can still be done iteratively. No need to do a recursive search.
For this, I use a lookup table to handle all cases where cell(s) can be filled in just to do knowledge about the row it's in. That handles everything you can fill in using any combination of no-3-in-a-row and 4-zeroes-per-row.
That doesn't do everything, obviously. First, it disregards columns, but that's easy: just transpose the board and try again.
Second, it disregards things you can know from the no-equal-rows rule. For that I enumerate all possible rows, test them against the currently filled in cells in the row, then against any surrounding rows for the no-3-in-a-row rule, then against the currently already completed rows, and then against the column-counts. If it passes all those tests, then it's possible to fill in this row here. All possible rows for one position are combined to see if they have any bits that are always the same, those bits are "filled in".
Then the board is transposed and the same is done for the columns. Until either there is no change or the board is completely filled. If it's completely filled, then the instance is solvable.

Ok, so now, how to test how hard an instance is.
For this, I actually generate the specific moves that you would play. A "move" is when you have some reason to fill in a cell. Generating actual moves is harder and especially more verbose than implicitly having moves as in the solver. And there's an other problem: when there are multiple moves, not all of them are created equal - some lead to easier total paths to the end. To avoid scoring puzzles too high, I use A* to find the easiest path to the solution (A* yes so it has a heuristic - a very bad one though, the number of cells currently not filled in. That only works if you score the hardness of moves in a certain way. Be very careful that you don't accidentally make a non-admissible heuristic, I spent several days debugging that).

Pages: 1 ... 5 6 [7] 8 9 ... 16