C++, 97 95 93 91 86 83 82 81 characters
My strategy is fairly simple - an evolution algorithm that can grow, shrink, swap elements of and mutate valid sequences. My evolution logic is now nearly the same as @Sp3000's, as his was an improvement over mine.
However, my implementation of the maze...
@Sp3000 still had some old code leftover in a condition that kept track of the 'best' so far (which was pure size of the string), and that disallows growing beyond 10 more than the best
Another option to the use of structured arrays is using a view of a void type that joins the whole row into a single item:
a = np.array([[1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 0, 0],
[1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 1, 0]])
b...
Ah k - I took a bit of a different approach, but it should be similar (chuck a thousand random strings at the mazes before beginning and sort by #failures)
def check(string):
for i, maze in enumerate(mazes):
start, finish, walls = maze
cell = start
for c in string:
cell = move(c, cell, walls)
if cell == finish:
t = mazes[i//2]; mazes[i//2] = mazes[i]; mazes[i] = t
return True
return False
A magic square is a square where the rows, columns, and main diagonals all add up to some number n.
Your Task
Create a solver that given an unsolved square as a list and some number n on stdin will print the solved square as a list. You should be able to put any solvable square in it and get a...
Lembik, I think I've figured out a way to get 31. I'm now testing my original function, but instead of starting off at a bunch of zeroes, I'm seeding with a random starting point.
This question brought to you by a game I like to play when stuck in long phone meetings.
Given any two times from a 24 hour clock (from 00:00 to 23:59), how many valid mathematical equations can be generated with all of the times in between using only basic arithmetic operations?
Input: two fou...