Example #1
0
long long int coin(long long int n){
    if(n<12)return n;
    if(n<=9999980)if(a[n]!=0)return a[n];
    { p=max(n,coin(n/2)+coin(n/3)+coin(n/4));
    if(n<9999980){a[n]=p;}
    return p;}
}
Example #2
0
/** recursion solution */
int coin(int p, std::list<int> coins)
{
	if(coins.empty())
		return 0;
	if(p>coins.front())
		return coin(p-coins.front(),coins) + coin(p, [&coins]()->std::list<int>{coins.pop_front();return coins;}());
	else if(p==coins.front())
		return 1;
	else
		return 0;
}
Example #3
0
std::array<float, 2> MapGenerator::getGradient() const {
   std::array<float, 2> gradient;
   gradient[0] = rNDist(rNGen);
   gradient[1] = std::sqrt(1 - gradient[0] * gradient[0]);
   if (coin(rNGen)) gradient[1] = -gradient[1];
   return gradient;
}
Example #4
0
void PrivateCoin::mintCoin(const CoinDenomination denomination) {
	// Repeat this process up to MAX_COINMINT_ATTEMPTS times until
	// we obtain a prime number
	for(uint32_t attempt = 0; attempt < MAX_COINMINT_ATTEMPTS; attempt++) {

		// Generate a random serial number in the range 0...{q-1} where
		// "q" is the order of the commitment group.
		Bignum s = Bignum::randBignum(this->params->coinCommitmentGroup.groupOrder);

		// Generate a Pedersen commitment to the serial number "s"
		Commitment coin(&params->coinCommitmentGroup, s);

		// Now verify that the commitment is a prime number
		// in the appropriate range. If not, we'll throw this coin
		// away and generate a new one.
		if (coin.getCommitmentValue().isPrime(ZEROCOIN_MINT_PRIME_PARAM) &&
		        coin.getCommitmentValue() >= params->accumulatorParams.minCoinValue &&
		        coin.getCommitmentValue() <= params->accumulatorParams.maxCoinValue) {
			// Found a valid coin. Store it.
			this->serialNumber = s;
			this->randomness = coin.getRandomness();
			this->publicCoin = PublicCoin(params,coin.getCommitmentValue(), denomination);

			// Success! We're done.
			return;
		}
	}

	// We only get here if we did not find a coin within
	// MAX_COINMINT_ATTEMPTS. Throw an exception.
	throw ZerocoinException("Unable to mint a new Zerocoin (too many attempts)");
}
Example #5
0
File: coin.c Project: skysbird/alg
//a is the decrease order of coin value
void coin(int d, int coins[],int length,int level){
	if(d==0){
		int i =0;
		for(i = 0;i<level;++i){
			printf("%d ",result[i]);
		}
		printf("\n");
		finded = 1;
		return;
	}

	if(d < coins[length-1]){
		return;
	}

	
	int i = 0;
	while(!finded && i < length ){ 
		result[level] = coins[i];
		coin(d-coins[i],coins,length,level+1);
		++i;
	}

	
	
}
int pointerreference(S2* &s) {
  if (coin()) // expected-note{{Assuming the condition is true}}
              // expected-note@-1{{Taking true branch}}
    return 1; // expected-note{{Returning without writing to 's->x'}}

  s->x = 0;
  return 0;
}
Example #7
0
void testFlipCoin()
{
	FlipCoin coin(0.5);
	int count = 100;
	for (int i = 0; i < count; ++i)
	{
		std::cout<<coin.flipCoinOnce()<<'\t';
	}
}
Example #8
0
void testInlined() {
  extern int coin();
  int cond = coin();
  if (!cond) {
    inlined(0);
    if (cond) {
      foo(5); // expected-warning {{never executed}}
    }
  }
}
// Lucre step 5: mint verifies token when it is redeemed by merchant.
// This function is called by OTToken::VerifyToken.
// That's the one you should be calling, most likely, not this one.
bool OTMint_Lucre::VerifyToken(OTPseudonym & theNotary, OTString & theCleartextToken, int64_t lDenomination)
{
	bool bReturnValue = false;
//	OTLog::Error("%s <bank info> <coin>\n", argv[0]);
    _OT_Lucre_Dumper setDumper;
	
	OpenSSL_BIO bioBank	= BIO_new(BIO_s_mem()); // input
	OpenSSL_BIO bioCoin	= BIO_new(BIO_s_mem()); // input
	
	// --- copy theCleartextToken to bioCoin so lucre can load it
	BIO_puts(bioCoin, theCleartextToken.Get());
		
	// --- The Mint private info is encrypted in m_mapPrivate[lDenomination]. 
	// So I need to extract that first before I can use it.
	OTASCIIArmor theArmor;
	GetPrivate(theArmor, lDenomination);
	OTEnvelope theEnvelope(theArmor);
	
	OTString strContents; // will contain output from opening the envelope.
	// Decrypt the Envelope into strContents    
	if (theEnvelope.Open(theNotary, strContents))
	{
		// copy strContents to a BIO
		BIO_puts(bioBank, strContents.Get());
		
		// ---- Now the bank and coin bios are both ready to go... 
		
		Bank bank(bioBank);
		Coin coin(bioCoin);
		
		if (bank.Verify(coin))  // Here's the boolean output: coin is verified!
		{
			bReturnValue = true;
			
			// (Done): When a token is redeemed, need to store it in the spent token database.
			// Right now I can verify the token, but unless I check it against a database, then 
			// even though the signature verifies, it doesn't stop people from redeeming the same
			// token again and again and again.
			//
			// (done): also need to make sure issuer has double-entries for total amount outstanding.
			//
			// UPDATE: These are both done now.  The Spent Token database is implemented in the transaction server,
			// (not OTLib proper) and the same server also now keeps a cash account to match all cash withdrawals.
			// (Meaning, if 10,000 clams total have been withdrawn by various users, then the server actually has
			// a clam account containing 10,000 clams. As the cash comes in for redemption, the server debits it from
			// this account again before sending it to its final destination. This way the server tracks total outstanding
			// amount, as an additional level of security after the blind signature itself.)
		}
	}

	return bReturnValue;
}
Example #10
0
void convert_p(stack *s)
{
   printf("\n 1: Infix ");
   printf("\n 2: Postfix ");
   printf("\n 0: Back ");

  scanf(" \t %d",&i) ;
  
  switch(i)
 {
   case 1:   coin(s);      break;
   case 2:   copos(s);     break;
   case 0:   options_p(s);
  }
 }  
Example #11
0
void testBranchReversed(void *p) {
  int *casted;

  // Although the report will be suppressed on one branch, it should still be
  // valid on the other.
  if (coin()) {
    if (p)
      return;
    casted = (int *)p;
  } else {
    casted = dynCastToInt(p);
  }

  *casted = 1; // expected-warning {{Dereference of null pointer}}
}
Example #12
0
Move MainPlayer::recursion(const GameBoard &gameBoard, Tile tile,
                           size_t depth, size_t maxDepth) const {
//    gameBoard.print(std::cerr);
    auto now = std::chrono::steady_clock::now();
    std::chrono::time_point<std::chrono::system_clock> nowTime;
    nowTime = std::chrono::system_clock::now();

    std::chrono::duration<double> elapsed_seconds = nowTime - startWorking;
    /*if (elapsed_seconds.count() > 2.7) {
        std::cerr << "TL\n";
    }*/
    if (depth > maxDepth || gameBoard.isGameOver() || elapsed_seconds.count() > 2.7) {
        Move stop({0, 0},
                  evaluateGameBoard(gameBoard, WHITE),
                  evaluateGameBoard(gameBoard, BLACK));
        return stop;
    }
    auto enemyTile = gameBoard.getEnemyTile(tile);
    auto gameSize = gameBoard.getGameSize();
    std::bernoulli_distribution coin(0.5);
//    randomGenerator.seed(time(NULL));
    Move current, max;
    bool first = true;
    for (size_t row = 0; row < gameSize; ++row) {
        for (size_t column = 0; column < gameSize; ++column) {
            Cell here(row, column);
            if (gameBoard.canPutTile(here, tile)) {
                GameBoard newGameBoard = gameBoard;
                newGameBoard.putTile(here, tile);
//                newGameBoard.print(std::cerr);
                current = recursion(newGameBoard, enemyTile, depth + 1, maxDepth);
                if (first || current.isBetterForThan(tile, max)) {
                    max = current;
                    max.cell = here;
                    first = false;
                }
            }
        }
    }
    // У текущего игрока нет ходов. Пропуск хода.
    if (first) {
        return recursion(gameBoard, enemyTile, depth, maxDepth);
    }
    return max;
}
Example #13
0
int main(){
	int i;
	int T,money,n;
	int arr[MAX];
	long cnt;

	scanf("%d",&T);

	while(T--){
		scanf("%d %d",&money,&n);
		for(i=0;i<n;i++){
			scanf("%d",&arr[i]);
		}
		cnt = coin(money,n,arr);
		if(cnt>1000000007)
			printf("%ld\n", cnt%1000000007);
		else
			printf("%ld\n", cnt);
	}
}
Example #14
0
void World::generateLevel()
{
	float y = Platform::PLATFORM_HEIGHT / 2;
	float maxJumpHeight = Bob::BOB_JUMP_VELOCITY * Bob::BOB_JUMP_VELOCITY / (2 * -gravity.y);
	while(y < WORLD_HEIGHT - WORLD_WIDTH / 2)
	{
		int type = MathUtils::randomFloat() > 0.8f ? Platform::PLATFORM_TYPE_MOVING : Platform::PLATFORM_TYPE_STATIC;
		float x = MathUtils::randomFloat() * (WORLD_WIDTH - Platform::PLATFORM_WIDTH) + Platform::PLATFORM_WIDTH / 2;

		Platform platform(type, x, y);
		platforms.push_back(platform);

		if(MathUtils::randomFloat() > 0.9f && type != Platform::PLATFORM_TYPE_MOVING)
		{
			Spring spring(platform.position.x, platform.position.y + Platform::PLATFORM_HEIGHT / 2
				+ Spring::SPRING_HEIGHT / 2);
			springs.push_back(spring);
		}

		if(y > WORLD_HEIGHT / 3 && MathUtils::randomFloat() > 0.8f)
		{
			Squirrel squirrel(platform.position.x + MathUtils::randomFloat(), platform.position.y
				+ Squirrel::SQUIRREL_HEIGHT + MathUtils::randomFloat() * 2);
			squirrels.push_back(squirrel);
		}

		if(MathUtils::randomFloat() > 0.6f)
		{
			Coin coin(platform.position.x + MathUtils::randomFloat(), platform.position.y + Coin::COIN_HEIGHT
				+ MathUtils::randomFloat() * 3);
			coins.push_back(coin);
		}

		y += (maxJumpHeight - 0.5f);
		y -= MathUtils::randomFloat() * (maxJumpHeight / 3);
	}
	castle = Castle(WORLD_WIDTH / 2, y);
}
int test_multi_decl(int *paramA, int *paramB) {
  char *param1 = DYN_CAST(paramA), *param2 = DYN_CAST(paramB);
  if (coin())
    return *param1;
  return *param2;
}
Example #16
0
int main(){
    long long int t,n=2;
    while(scanf("%lld",&n)!=EOF){
    printf("%lld\n",coin(n));
}return 0;}
Example #17
0
/** answer is 73682 */
int main(int argc, char* argv[])
{
	std::list<int> coins{1,2,5,10,20,50,100,200};
	std::cout<<coin(200,coins)<<std::endl;
}
int *maybeNull() {
	extern bool coin();
	static int x;
	return coin() ? &x : 0;
}
Example #19
0
void testCacheOut(PtrWrapper w) {
  extern bool coin();
  if (coin())
    w.x = 0;
  new (&w.x) (int*)(0); // we cache out here; don't crash
}
Example #20
0
Ultra1::StateNumber Ultra1::HelpState::Run( )
{
	Sim::Image bg( UBD_PREFIX "/images/mountains.jpg" );	
	Sim::Image but( UBD_PREFIX "/images/button.png", 255, 0, 0 );
		
	Sim::Button menu( 0, 480, 450, 50, 3, 0, 0, 0, 40, 7, true );
	menu.SetBackGround( but.image );
	menu.SetForeGround( "Main Menu", app->text_writer.GetFont( GALAPOGO_36 ), 0, 0, 0 );
	
	Sim::Button quit( 0, 540, 450, 50, 3, 0, 0, 0, 40, 7, true );
	quit.SetBackGround( but.image );
	quit.SetForeGround( "Quit", app->text_writer.GetFont( GALAPOGO_36 ), 0, 0, 0 );

	Sim::Image bear_i( UBD_PREFIX "/images/bear.png", 0, 0, 255 );
	Sim::Sprite bear( 10, 130, 20, 40, 1 );
	bear.AddAnimation( 0, 0, 3, true, bear_i.image, 200, true );

	Sim::Image armor_i( UBD_PREFIX "/images/armor.png", 0, 0, 255 );
	Sim::Sprite armor( 10, 190, 20, 20, 1 );
	armor.AddAnimation( 0, 0, 2, true, armor_i.image, 125, false );

	Sim::Image force_i( UBD_PREFIX "/images/force.png", 0, 0, 255 );
	Sim::Sprite force( 10, 230, 20, 20, 1 );
	force.AddAnimation( 0, 0, 2, true, force_i.image, 125, false );

	Sim::Image life_i( UBD_PREFIX "/images/extralife.png", 0, 0, 255 );
	Sim::Sprite life( 10, 270, 20, 20, 1 );
	life.AddAnimation( 0, 0, 2, true, life_i.image, 125, false );

	Sim::Image coin_i( UBD_PREFIX "/images/coin.png", 0, 0, 255 );
	Sim::Sprite coin( 10, 310, 20, 20, 1 );
	coin.AddAnimation( 0, 0, 3, true, coin_i.image, 125, false );

	SDL_Event event;
	while( true )
	{
		while( SDL_PollEvent(&event) )
		{
			if( event.type == SDL_QUIT )
			{
				app->FadeTo( 100 );
				return QUIT_STATE;
			}
			else if( event.type == SDL_KEYDOWN )
			{
				if( event.key.keysym.sym == SDLK_ESCAPE )
				{
					app->FadeTo( 100 );
					return MENU_STATE;
				}
			}
			else if( event.type == SDL_MOUSEBUTTONDOWN )
			{
				menu.HandleMouseDown( event.button.x, event.button.y );
				quit.HandleMouseDown( event.button.x, event.button.y );
			}
			else if( event.type == SDL_MOUSEBUTTONUP )
			{
				if( menu.HandleMouseUp( event.button.x, event.button.y ) )
				{
					app->PlaySound( BUTTON_NOISE );
					app->FadeTo( 100 );
					return MENU_STATE;
				}
				
				if( quit.HandleMouseUp( event.button.x, event.button.y ) )
				{
					app->PlaySound( BUTTON_NOISE );
					app->FadeTo( 100 );
					return QUIT_STATE;
				}
			}
		}

		bear.Update( );
		armor.Update( );
		force.Update( );
		life.Update( );
		coin.Update( );

		app->Clear( 0, 0, 0 );
		SDL_BlitSurface( bg.image, NULL, app->screen, NULL );

		app->text_writer.WriteText( app->screen, GALAPOGO_72, "Help", 10, 0, 0, 0, 0 );

		// Write basic info at top...
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "In this game, you must guide Ultra Bear to the South Pole by working through every level on the map.", 10, 65, 0, 0, 0 );
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "To beat a level, you must move Ultra Bear to the right while avoiding all of the enemies. You can kill", 10, 82, 0, 0, 0 );
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "enemies by bouncing on their heads. Here are a few things that you will encounter:", 10, 99, 0,0,0 );

		// Info beside UB and crew...
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Ultra Bear. This is the bear you must guide south. He is very Ultra.", 50, 139, 0, 0, 0 );
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Armor. This pickup will protect Ultra Bear from one blow by an enemy.", 50, 190, 0, 0, 0 );
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Force. This magic force field will eliminate all enemies Ultra Bear touches. It will wear off though.", 50, 230, 0, 0, 0 );
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Extra Life. This pickup will credit Ultra Bear with one extra life.", 50, 270, 0, 0, 0 );
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Coin. This pickup deposits one coin in Ultra Bear's account. Once he has 100, he can trade them in for an extra life.", 50, 310, 0, 0, 0 );
		app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "The controls can be configured by clicking Options from the Main Menu", 10, 380, 0, 0, 0 );



		menu.Draw( app->screen );
		quit.Draw( app->screen );
		bear.Draw( app->screen );
		armor.Draw( app->screen );
		force.Draw( app->screen );
		life.Draw( app->screen );
		coin.Draw( app->screen );

		app->Flip( );
	}
}
Example #21
0
int main()
{
    sf::RenderWindow window(sf::VideoMode(screen_x, screen_y), "GameWindow");
    window.setMouseCursorVisible(false);

    new EntityManager;
    new AssetManager;

    std::vector<Entity*> baddies;

    sf::Clock clock;

    Entity& player(EntityManager::addEntity());
    player.addComponent<Position>(sf::Vector2f(200,200));
    player.addComponent<Velocity>(80.f);
    player.addComponent<KeyboardControl>();
    player.addComponent<Rotation>();
    player.addComponent<Sprite>(AssetManager::getTexture("assets/player.png"));
    player.addComponent<Health>(100);
    player.addComponent<HealthBar>(50);
    player.addComponent<AttachToMouse>(window);

    Entity& coin(EntityManager::addEntity());
    coin.addComponent<Position>(sf::Vector2f(400,300));
    coin.addComponent<Sprite>(AssetManager::getTexture("assets/coin.png"));
    coin.addComponent<Animated>();
    coin.addComponent<Health>(100, 20);
    coin.addComponent<HealthBar>(30);
    coin.zindex = 10;

    Animator::Animation& coin_spin = coin.getComponent<Animated>().createAnimation("spinning", "assets/coin.png", sf::Vector2i(32,32), sf::seconds(.75), true);
    coin_spin.addFrames(sf::Vector2i(0,0), 8);

    baddies.push_back(&coin);

    while (window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
            player.getComponent<Health>().reduceHealth(1);

        sf::Time delta = clock.restart();

        window.clear(sf::Color(64,64,64));

        EntityManager::refresh();
        EntityManager::update(delta);
        EntityManager::draw(&window);

        window.display();
    }

    delete AssetManager::getInstancePtr();
    delete EntityManager::getInstancePtr();

}
Example #22
0
int *lookUpInt(int unused) {
  if (coin())
    return 0;
  static int x;
  return &x;
}