<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>bitshift &#8211; JSAlgorithm</title>
	<atom:link href="https://jsalgorithm.com/tag/bitshift/feed/" rel="self" type="application/rss+xml" />
	<link>https://jsalgorithm.com</link>
	<description></description>
	<lastBuildDate>Thu, 21 May 2020 02:47:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.15</generator>
<site xmlns="com-wordpress:feed-additions:1">177240629</site>	<item>
		<title>Game Of Life (Optimized)</title>
		<link>https://jsalgorithm.com/2020/05/21/game-of-life-optimized/</link>
					<comments>https://jsalgorithm.com/2020/05/21/game-of-life-optimized/#respond</comments>
		
		<dc:creator><![CDATA[Ronald]]></dc:creator>
		<pubDate>Thu, 21 May 2020 02:46:57 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[Loop]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[bitshift]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[matrix]]></category>
		<guid isPermaLink="false">http://50.19.13.106/?p=132</guid>

					<description><![CDATA[let gameOfLife = function(board) { if (!board) return []; let LIVE = 1, DEAD = 0, ALIVE_TO_DEAD = 0b01, // [next state, current state] ALIVE_TO_ALIVE = 0b11, DEAD_TO_ALIVE = 0b10, DEAD_TO_DEAD = 0b00, maxRow = board.length - 1, maxCol = board[0].length - 1; function getAdjacentCount(row, col, valueToCompare) { let sum = 0; for (let i [&#8230;]]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-preformatted">let gameOfLife = function(board) {

    if (!board) return [];

    let LIVE = 1,
        DEAD = 0,
        ALIVE_TO_DEAD = 0b01, // [next state, current state]
        ALIVE_TO_ALIVE = 0b11,
        DEAD_TO_ALIVE = 0b10,
        DEAD_TO_DEAD = 0b00,
        maxRow = board.length - 1,
        maxCol = board[0].length - 1;

    function getAdjacentCount(row, col, valueToCompare) {
        let sum = 0;
        for (let i = <strong><em>Math</em></strong>.max(row - 1, 0); i &lt;= <strong><em>Math</em></strong>.min(row + 1, maxRow); i++) {
            for (let j = <strong><em>Math</em></strong>.max(col - 1, 0); j &lt;= <strong><em>Math</em></strong>.min(col + 1, maxCol); j++) {
                if (i === row &amp;&amp; j === col) continue;
                if (board[i][j] &amp; 1 === valueToCompare) sum = sum + 1;
            }
        }
        return sum;
    }

    function getNextValue(row, col) {
        const val = board[row][col];
        let liveNeighbors = getAdjacentCount(row, col, LIVE);
        if (val === LIVE) {

            // Any live cell with fewer than two live neighbors dies, as if caused by under-population.
            // Any live cell with more than three live neighbors dies, as if by over-population..
            if (liveNeighbors &lt; 2 || liveNeighbors > 3) {
                return ALIVE_TO_DEAD;
            }
            // Any live cell with two or three live neighbors lives on to the next generation.
            return ALIVE_TO_ALIVE;
        }
        // cell is DEAD
        else {
            // Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
            if (liveNeighbors === 3) {
                return DEAD_TO_ALIVE;
            }
            // no condition
            return DEAD_TO_DEAD;
        }
    }

    for (let row = 0; row &lt;= maxRow; row++) {
        for (let col = 0; col &lt;= maxCol;col++) {
            board[row][col] = getNextValue(row, col);
        }
    }

    for (let row = 0; row &lt;= maxRow; row++) {
        for (let col = 0; col &lt;= maxCol;col++) {
            board[row][col] = board[row][col] >> 1;
        }
    }

};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://jsalgorithm.com/2020/05/21/game-of-life-optimized/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">132</post-id>	</item>
	</channel>
</rss>
