মঙ্গলবার, ২০ ডিসেম্বর, ২০১৬

https://github.com/NarayanChakraborty/Missionaries-and-Cannibals/blob/master/The%20problem.pdf


The problem
Missionaries and Cannibals is a problem where you initially have 3 missionaries, 3 cannibals and a boat on one side of a river. The goal is to move all cannibals and missionaries to the other side of the river given some rules:
  • If any side of the river has more cannibals than missionaries, you loose. The cannibals have a meat fest!
  • The boat only moves if it has one or two passengers, you can choose who’s on it. The boat doesn’t move without anyone on it.

Start and finish states


start([3,3,0,0,east]).
goal([0,0,3,3,west]).
The problem has an initial state where everyone is on the East side of the river and we reach a solution when everyone is on the West side of the river.

Changing states

It’s not hard to see that the state changes when the boat takes passengers across the river. There are 5 possible moves:
  • 2 Cannibals
  • 2 Missionaries
  • 1 Cannibal
  • 1 Missionary
  • 1 Cannibal, 1 Missionary

Valid states

A new state is valid if:
  • there are missionaries present on a given side of the river, there cannot be more cannibals than missionaries.
  • the number of missionaries and cannibals on any given side has to be positive.


Legal States:
legal(CL,ML,CR,MR) :-
            % is this state a legal one?
            ML>=0, CL>=0, MR>=0, CR>=0,
            (ML>=CL ; ML=0),
            (MR>=CR ; MR=0).






move([CL,ML,CR,MR,east],[CL,ML2,CR,MR2,west]):-
            % Two missionaries cross east to west.
            MR2 is MR+2,
            ML2 is ML-2,
            legal(CL,ML2,CR,MR2).

Possible moves:




Solution found:
path([CL,ML,CR,MR,B],[CL,ML,CR,MR,B],_,MovesList):-
            output(MovesList).






output([]) :- nl.
output([[A,B]|MovesList]) :-
            output(MovesList),
            write(B), write(' ------> '), write(A), nl,nl.

Printing Output:








Output:

শনিবার, ৩ সেপ্টেম্বর, ২০১৬

Calculate row value based on previous and actual row values

Assuming that stmnt_date has a UNIQUE constraint, this would be fairly easy with window/analytic functions:

শনিবার, ২৭ আগস্ট, ২০১৬

Automatic Update Your Copyright Section

Necessity of Dynamic Copyright Section:

Ever looked at a website and wondered if it is still in operation? Maybe a thing or two looked like they could have been updated – but when you notice the copyright notice the in the footer. "showing old year. Right, this site must be dead. Let's Go Forward."
This is because,
Sometimes owner may forget to update the copyright section or it is difficult for him to update...
So  To future-proof your footer, it's better to just let computers take care of this. Grab one of these snippets and paste that on your page (or forward this site as a friendly reminder to someone who can do it for you).

JavaScript:
&copy; 2010<script>new Date().getFullYear()>2010&&document.write("-"+new Date().getFullYear());</script>, MyCompany. 
© 2010-2016, Company.
PHP :
&copy; <?php 
  $fromYear = 2008; 
  $thisYear = (int)date('Y'); 
  echo $fromYear . (($fromYear != $thisYear) ? '-' . $thisYear : '');?> MyCompany
© 2008-2016 Company

Insert row or update if it exists(PDO)

$statement1=$db->prepare('select * from tbl_accounting where a_date=?');
$statement1->execute(array($c_date));
$result1=$statement1->fetchColumn();
if($result1>0) //checking existance and update section
{
$statement2=$db->prepare("update tbl_accounting set a_balance=? where a_date=?");
 $statement2->execute(array($todays_balance,$c_date));
}
else{ // insert section
 $statement2=$db->prepare("insert into tbl_accounting(a_balance,a_date) values(?,?) ");
 $statement2->execute(array($todays_balance,$c_date));


}

রবিবার, ২২ মে, ২০১৬

Install Laravel on Windows with Xampp(লারাভেল ইনস্টল )

How To Install Laravel on Windows


Requirments:

  • PHP >= 5.5.9
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension

Install Xampp

First  we need to install Xampp, so we can download it from the official page: Download Xampp 

Composer

After you've downloaded and installed Xampp, we need to install Composer. Composer Download page
After install it, we can open a Windows terminal and write composer for execute the command:

Via Composer Create-Project

You can also see the documentation here
 install Laravel by issuing the Composer create-project command in your terminal:
composer create-project laravel/laravel blog "5.1.*"
When it finishes, it will create following directory schema:
Schema
Finally, start our apache and MySql from Xampp control panel:
Success!
Navigate to localhost/blog/public/ and Laravel it's installed!