This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Prime { | |
function isPrime(uint256 n) public view returns (bool){ | |
if (n < 2) { | |
return false; | |
} | |
if (n == 2) { | |
return true; | |
} | |
return expmod(2, n - 1, n) == 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var calculateHash = (index, previousHash, timestamp, data) => { | |
return CryptoJS.SHA256(index + previousHash + timestamp + data).toString(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.21 <0.6.0; | |
contract Prime { | |
address public owner = msg.sender; | |
constructor() public { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Prime = artifacts.require("./Prime.sol"); | |
contract('Prime', function (accounts) { | |
it('reports correctly primes and composited for miller-rabin test in base2', async function () { | |
const contract = await Prime.new(); | |
const isMillerRabin2Prime = (numberAsString) => contract.probablyPrime.call(numberAsString, '2') | |
// test for a simple prime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Block { | |
constructor(index, previousHash, timestamp, data, hash) { | |
this.index = index; | |
this.previousHash = previousHash.toString(); | |
this.timestamp = timestamp; | |
this.data = data; | |
this.hash = hash.toString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
NewerOlder