8 Puzzle, graph tree paths generator - php

I'm looking for 8 Puzzle graphs tree generator, preferable in (php+) html+css+javascript. What i need is something like
3 2 1
6 8
7 5 4
will generate all the possible tree, like
3 1 3 2 1
6 2 8 6 8
7 5 4 7 5 4
and so on, until meet its goal.
Any link or algorithm is appreciated. thanks.

See http://www.8puzzle.com/8_puzzle_algorithm.html for the explanation of the algoritm.
Creating such an efficient application is time-consuming, and requires skills in mathematics (field theory) and JS/PHP.

Even if you lack the mathematical background you can define a set of successor states from a certain state. Then throw all that into a search tree and add a little Zobrist hashing to avoid cycles.

Related

I need either mathematical solution or programming solution in PHP

I am thinking to arrange office room.
Office room is always noisy, and you are thinking to separate each room users as possible as you
can so that they don’t feel uncomfortable.
If they are facing each other, we will add unhappy point as 1.
INPUT
What we can do here is based on given rooms and users, arrange room separately so people don’t
feel uncomfortable.
[row, column, users] -> unhappy points
Example 1: [2, 3, 6]
*2 Rows, 3 Columns, 6 people
Example 2: [3, 3, 8]
*3 Rows, 3 Columns, 8 people
Sample Output
]
Following are some Test Cases :
[5,2,8]-> 7
[3,5,14]-> 18
[1,16,1]-> 0
[3,5,1]-> 0
[8,2,12]-> 10
[16,1,1]-> 0
[3,3,6]-> 3
[2,6,12]-> 16
[15,1,0]-> 0
[5,3,7]-> 0
[4,3,5]-> 0
I need either mathematical solution or programming solution in PHP.
This is not a complete question because how will you determine that two rooms are facing each other and one more thing is that how are you counting 7 unhappy points for first example.
I've observes that if you are taking a matrix lets say 4 by 5 than you can put 4*5=20 peoples there.So how will you count more than 20 points while we have only 20 people?

creating a site for a medical study, need to seperate users into two groups randomly but evenly

I have this problem im trying to figure out. At first i thought about seperating users just by their user id by odds and evens. But my client says it needs to be a little bit more random then that.
if($user_id % 2 == 0) {
$u->add_role( 'control' );
}else{
$u->add_role( 'study' );
}
Users need to be placed into a control group, and a study group, out of 10 there need to be 5 in each, out of 100, 50 etc. But it apperantly something like 1 3 5 7 and 9 cant go in one while 2 4 6 8 10 go in the other. It should be more like
1 3 5 6 7 go in one
2 4 8 9 10 go in the other.
Im having trouble figuring out how to do that in a way that scales
Why don't you make a list of all the users. Then randomly choose an index to select a user, assign it the group and then remove it from the list. Just alternate the type of group as you go. When the list is empty, you've assigned all the users.

Mysql return only items that have n number of property matches

I have a database of items and each item has various number of properties. Is it possible for MySql only to return items that have a certain number of matches (not properties) when a search is run?
Example: I am searching for any item with a wheel that is red and has a tire.
This would return all items with these three matches even if they have more properties and would automatically exclude anything that has less than 3 matches.
I have tried playing with the COUNT + GROUP BY + HAVING but I was unable to put together a meaningful working code. Before I spend more time on this I would like to know if it is possible at all.
TABLE DESIGN
ID ITEM PROPERTY
1 1 red
2 1 wheel
3 1 tire
4 2 red
5 2 wheel
6 2 tire
7 2 lamp
8 3 red
9 3 wheel
10 4 red
I would like it to return ITEM 1 and 2
You would do this with a group by and having. You really provide no information about your data structure, but the basic idea is:
select ip.item
from design ip
where ip.property in ('wheel', 'red', 'tire')
group by ip.item
having count(distinct ip.property) = 3;

`Retrieve a page based on a predefined path using nested set

I am currently building a CMS and intend to use Joe Celko's nest tree set (MPTT) to retrieve hierarchical data such as a nested deep page based on a defined path. e.g.
example.com/products/phone/specs.
I have a categories tables
cat_id name lft rgt
1 products 1 18
2 phone 2 9
3 specs 3 4
4 gallery 5 6
5 price 7 8
6 laptop 10 17
7 specs 11 12
8 gallery 13 14
9 price 15 16
10
and a pages table
page_id name content
1 specs Here is the specification of the chosen phone
2 price the price of chosen phone
3 specs laptop spec
4 price laptop price
This schema can be found on slqfiddle
Unfortunately, i have no idea on how to do this, the closest idea i got from searching online examples even celko's book does assume you only want to "retrieve the single path" to the parent of a node. Whereas, my use case demands that i retrieve the page (and display it) based on the path set by the url as above.
So, i can i achieve this? All valuable suggestions are welcome. thanks.

standard deviation and mode

I have a system that monitors the performance of students. It tabulates the number of students who gained a score of 1,1.25,1.5,....5 (this is our grading system). For example:
grading system number of students
1 12
1.25 10
1.5 15
1.75 15
2 20
2.25 1
2.5 5
2.75 6
3 8
5 0
From this example, I need my system to determine which is the mode and then print it. I also need to get the standard deviation.
I need this in PHP. Can anyone help me with this?
Your ideas, comments, and suggestions are appreciated.
Update:
Here's what I've done so far:
Finished the standard deviation...but there are still discrepancies i can't resolve...when i calculate the standard deviation manually..the answer is different from the output of my system.. >.<
While for the mode I used an array..this is my code:
$sample = array($one[$ctr],$two[$ctr],$three[$ctr],$four[$ctr],$five[$ctr],$six[$ctr],$seven[$ctr],$eight[$ctr],$nine[$ctr],$ten[$ctr],$fda[$ctr]);
rsort($sample);
$holder = $sample[0];
//$holder = $mode;
The sorting is successful and I can the highest number but I need to print the value of $holder to a table using fpdf.
Any ideas, why the value is not visible in the output?
Well, the mode is easy. Just find the grade (2) which has the highest number of students (20) and there you are.
If there's more than one, then it's multi-modal and you should probably allow for that.
For the standard deviation, the method can be found here. It's basically working out the mean of all those numbers (let's simplify this by using 1, 1, 2 and 7):
1 + 1 + 2 + 7 10
------------- = -- = 2.5
4 4
then calculating the square root of the variance of all those samples from that mean:
_____________________________________________
/ (1-2.5)^2 + (1-2.5)^2 + (2-2.5)^2 + (7-2.5)^2
/ ---------------------------------------------
\/ 4
__________________________
/ 2.25 + 2.25 + 0.25 + 20.25
= / --------------------------
\/ 4
= 2.5
If you're asking a beginner-level question like how best to do this in a specific language like PHP, you should investigate the use of arrays and loops.

Categories