Skip to content

Instantly share code, notes, and snippets.

View lhartikk's full-sized avatar

Lauri Hartikka lhartikk

  • Helsinki, Finland
View GitHub Profile
var initHttpServer = () => {
var app = express();
app.use(bodyParser.json());
app.get('/blocks', (req, res) => res.send(JSON.stringify(blockchain)));
app.post('/mineBlock', (req, res) => {
var newBlock = generateNextBlock(req.body.data);
addBlock(newBlock);
broadcast(responseLatestMsg());
console.log('block added: ' + JSON.stringify(newBlock));
var calculateBestMove =function(game) {
//generate all the moves for a given position
var newGameMoves = game.ugly_moves();
return newGameMoves[Math.floor(Math.random() * newGameMoves.length)];
};
var calculateBestMove = function (game) {
var newGameMoves = game.ugly_moves();
var bestMove = null;
//use any negative large number
var bestValue = -9999;
for (var i = 0; i < newGameMoves.length; i++) {
var newGameMove = newGameMoves[i];
game.ugly_move(newGameMove);
var minimax = function (depth, game, isMaximisingPlayer) {
if (depth === 0) {
return -evaluateBoard(game.board());
}
var newGameMoves = game.ugly_moves();
if (isMaximisingPlayer) {
var bestMove = -9999;
for (var i = 0; i < newGameMoves.length; i++) {
game.ugly_move(newGameMoves[i]);
bestMove = Math.max(bestMove, minimax(depth - 1, game, !isMaximisingPlayer));
/*
* The "core" logic of the smart contract.
* Calculates the equation with provided values for Fermat's last theorem.
* Returns the value of a^n + b^n - c^n, n > 2
*/
function solve(int256 a, int256 b, int256 c, int256 n) pure public returns (uint256) {
assert(n > 2);
uint256 aExp = power(a, n);
uint256 bExp = power(b, n);
uint256 cExp = power(c, n);
/**
* The function that is used to claim the bounty.
* If the caller is able to provide satisfying values for a,b,c and n
* the balance of the contract (the bounty) is transferred to the caller
*/
function claim(int256 a, int256 b, int256 c, int256 n) public {
uint256 value = solve(a, b, c, n);
if (value == 0) {
msg.sender.transfer(this.balance);
}
/**
* Allow the owner of the contract to
* withdraw the bounty after the release time has passed
*/
function withdraw() public {
require(msg.sender == owner);
require(now >= releaseTime);
msg.sender.transfer(this.balance);
}
/**
* The release time is set to 8640000 seconds (= 100 days)
* in the future from the timestamp of the contract creation
*/
address public owner = msg.sender;
uint releaseTime = now + 8640000;
pragma solidity ^0.4.18;
/**
* A contract that pays off, if a user is able to produce a valid solution
* for the Fermat's last theorem
*/
contract Fermat {
/**
pragma solidity ^0.4.8;
contract Rubik {
enum Color {Red, Blue, Yellow, Green, White, Orange}
Color[9][6] state;
address public owner = msg.sender;
uint8 constant FRONT = 0;