Skip to content

Instantly share code, notes, and snippets.

View lhartikk's full-sized avatar

Lauri Hartikka lhartikk

  • Helsinki, Finland
View GitHub Profile
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;
var calculateHash = (index, previousHash, timestamp, data) => {
return CryptoJS.SHA256(index + previousHash + timestamp + data).toString();
};
pragma solidity >=0.4.21 <0.6.0;
contract Prime {
address public owner = msg.sender;
constructor() public {
}
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
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 calculateBestMove =function(game) {
//generate all the moves for a given position
var newGameMoves = game.ugly_moves();
return newGameMoves[Math.floor(Math.random() * newGameMoves.length)];
};
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 {
/**
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();
}
}
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;
/**
* 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;