Beispiel #1
0
/** Convert an integer into a string representing its hexadecimal value
  *
  * \param vInt  The integer to stringify
  * \param vBase How many characters in the binary string.
  *              Should be 1, 2, 4 or 8
  *
  */
std::string RainbruRPG::Core::StringConv::
itobin(int vInt, const int vBase){
  string out;

  // Using if...else statemenst instead of case to avoid cross 
  // initializations

  // We also need to use a different bitset for each case because
  // the argument of a template cannot be a variable

  if (vBase==1){
     bitset<1> num1(vInt);
     out+=BITSET_STR(num1);
  }
  else if (vBase==2){
     bitset<2> num2(vInt);
     out+=BITSET_STR(num2);
  }
  else if (vBase==4){
     bitset<4> num4(vInt);
     out+=BITSET_STR(num4);
  }
  else if (vBase==8){
     bitset<8> num8(vInt);
     out+=BITSET_STR(num8);
  }
  else{
    LOGW(_("StringConv::itobin base parameter unrecognized"));

  }

  return out;
}
Beispiel #2
0
static void valueFlowForLoop(TokenList *tokenlist, ErrorLogger *errorLogger, const Settings *settings)
{
    for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
        if (!Token::simpleMatch(tok, "for (") ||
            !Token::simpleMatch(tok->next()->astOperand2(), ";") ||
            !Token::simpleMatch(tok->next()->astOperand2()->astOperand2(), ";"))
            continue;

        Token * const bodyStart = tok->linkAt(1)->next();

        unsigned int varid(0);
        MathLib::bigint num1(0), num2(0);

        if (valueFlowForLoop1(tok, &varid, &num1, &num2)) {
            valueFlowForLoopSimplify(bodyStart, varid, num1, tokenlist, errorLogger, settings);
            valueFlowForLoopSimplify(bodyStart, varid, num2, tokenlist, errorLogger, settings);
        } else {
            std::map<unsigned int, MathLib::bigint> mem1, mem2;
            if (valueFlowForLoop2(tok, &mem1, &mem2)) {
                std::map<unsigned int, MathLib::bigint>::const_iterator it;
                for (it = mem1.begin(); it != mem1.end(); ++it)
                    valueFlowForLoopSimplify(bodyStart, it->first, it->second, tokenlist, errorLogger, settings);
                for (it = mem2.begin(); it != mem2.end(); ++it)
                    valueFlowForLoopSimplify(bodyStart, it->first, it->second, tokenlist, errorLogger, settings);
            }
        }
    }
}
int solve_104()
{
	Pair num0(1, 1), num1(1, 1);
	int result = 2;

#ifdef ApproachOne
	const Pair::Number Max = (~((Pair::Number)0)) / 10;	// UINT64_MAX / 10
	for(; !Pandigital(num1); ++result)
	{
		// It's easy to handle the low-9 digits.
		Pair::Number t_low = num1.low;
		num1.low = (num1.low + num0.low) % Sieve;
		num0.low = t_low;

		Pair::Number t_high = num1.high + num0.high;

		// dig_count(x) + dig_count(y) <= 1 + max(dig_count(x), dig_count(y)).
		if(t_high > Max)
		{
			// num1.high is a little too big, shrink it.
			t_high /= 10;
			num1.high /= 10;
		}

		num0.high = num1.high;
		num1.high = t_high;
	}
#else	// Another approach, amazing.
	for(; ; )
	{
		++result;
		// It's easy to handle the low-9 digits.
		Pair::Number t_low = num1.low;
		num1.low = (num1.low + num0.low) % Sieve;
		num0.low = t_low;

		if(PanHelper(num1.low))
		{
			// F(n) = ((phi ^ n) / sqrt(5.0)).
			// phi = (1 + sqrt(5)) / 2, 黄金分割.
			// 设 l_10 = log10(F(n))
			// 然后计算
			// pow(10, 8.0 + (l_10的小数部分)).
			// 因为是10的乘方,所以非000项都是由10的小数次方产生的.
			// 当n足够大时,这个值非常接近F(n).
			// log(pi) = 0.20898764024997873.
			// log(sqrt(5)) = 0.3494850021680094.
			const double t = (result * 0.20898764024997873 - 0.3494850021680094);
			num1.high = (Pair::Number)pow(10, t - (Pair::Number)t + 8.0);
			if(PanHelper(num1.high))
				break;
		}
	}
#endif
	return result;
}
Beispiel #4
0
int main()
{
   pk_int num1(5);
   pk_int num2(18);
   pk_int num3;

   num3 = num1 + num2;

   std::cout << num3.dump() << std::endl;
   return 0;
}
Beispiel #5
0
const char* CTextPath::num(double v)
{
	switch(m_number_format)
	{
	case 1:
		num1(v);
		break;

	default:
		sprintf(str_for_num, "%g", v);
		break;
	}

	return str_for_num;
}
int main(int argc, char* argv[]) {
    string num1("9");
    string num2("0019");
    if(argc == 3) {
        num1 = argv[1];
        num2 = argv[2];
    }
    eliminateHeadZeros(num1);
    eliminateHeadZeros(num2);
    cout << "num1: " << num1 << endl;
    cout << "num2: " << num2 << endl;
    if(num1 == "" || num2 == "" || num1 == "+" || num1 == "-" || num2 == "+" || num2 == "-") {
        cout << "num1 == \"\" or num2 == \"\"" << endl;
        return -1;
    }
    if(checkNum(num1) || checkNum(num2)) {
        cout << "Num1 or Num2 illegal" << endl;
        return -1;
    }
    //Add
    string addResult = addBigNum(num1, num2);
    cout << num1 << " + " << num2 << " = " << addResult << endl;

    //Compare
    cout << num1;
    int compare = compareBigNum(num1, num2);
    if(compare == 0) {
        cout << " = ";
    }
    else if(compare < 0) {
        cout << " < ";
    }
    else {
        cout << " > ";
    }
    cout << num2 << endl;

    //Sub
    string subResult = subBigNum(num1, num2);
    eliminateHeadZeros(subResult);
    cout << num1 << " - " << num2 << " = " << subResult << endl;
    return 0;
}
Beispiel #7
0
    //*******************************************************************
    // The following visitor functions deal with detecting Z's in the
    // logic, stripping the Z's out and creating an __en signal and its
    // logic.
    //*******************************************************************
    virtual void visit(AstPull* nodep, AstNUser*) {
        // replace any pullup/pulldowns with assignw logic and an __en
        // signal just like it is any other tristate signal.  The only
        // difference is that the user2() variable on the __en signal
        // will be given a pull direction--i.e. pulldown=1, pullup=2.
        // This will signal the driver exansion logic to put a default
        // pullup or pulldown state on the tristate bus under the high-Z
        // condition when no one is driving the bus.  Given the complexity
        // of merging tristate drivers at any level, the current limitation
        // of this implementation is that a pullup/down gets applied
        // to all bits of a bus and a bus cannot have drivers in opposite
        // directions on indvidual pins.
        AstNode* outp = nodep->lhsp()->unlinkFrBack();;
        AstVarRef* outrefp = NULL;
	int width=-1;
	if (outp->castVarRef()) {
	    outrefp = outp->castVarRef();
	} else if (outp->castSel()) {
	    outrefp = outp->castSel()->fromp()->castVarRef();
	    width = outp->castSel()->widthConst();
	} else {
	    nodep->v3error("Can't find LHS varref");
	}
	outrefp->lvalue(true);
	AstVar* varp = outrefp->varp();
	if (width==-1) width=varp->width();

        V3Number num0 (nodep->fileline(), width);
	num0.setAllBits0();
	V3Number num1 (nodep->fileline(), width);
	num1.setAllBits1();

	AstConst* enrhsp = new AstConst(nodep->fileline(), num0);
	AstVar* enp = createEnableVar(outp, outrefp, enrhsp, width, "pull");
	enp->user2(nodep->direction()+1); // record the pull direction

	AstAssignW* newassp = new AstAssignW(nodep->fileline(), outp,
					     new AstConst(nodep->fileline(), nodep->direction() ? num1 : num0));
	nodep->replaceWith(newassp);
	nodep->deleteTree(); nodep=NULL;
	newassp->iterateChildren(*this);
    }
TContactItemId CFilteredViewTester::DoAddContactL(TInt aOrdinal)
	{
	TBuf<KTestBufSize> name(_L("MyContact"));
	TBuf<KTestBufSize> num1(_L("123456"));
	TBuf<KTestBufSize> num2(_L("123457"));
	name.AppendNum (aOrdinal);
	num1.AppendNum (aOrdinal);
	num2.AppendNum (aOrdinal);

	CContactCard* card = CContactCard::NewLC();

	card->AddFieldL(*CreateFieldLC(KUidContactFieldVCardMapUnusedN,	KUidContactFieldGivenName, _L("ContactField")));
	CleanupStack::Pop();
	card->AddFieldL (*CreateFieldLC(KUidContactFieldVCardMapUnusedN, KUidContactFieldFamilyName, name));
	CleanupStack::Pop();
	card->AddFieldL (*CreateFieldLC(KUidContactFieldVCardMapTEL, KUidContactFieldPhoneNumber, num1));
	CleanupStack::Pop();
	card->AddFieldL (*CreateFieldLC(KUidContactFieldVCardMapTELFAX, KUidContactFieldPhoneNumber, num2));
	CleanupStack::Pop();

	TContactItemId id = iContactDb->AddNewContactL(*card);
	CleanupStack::PopAndDestroy(card);
	return id;
	}
Beispiel #9
0
string add(int a,int b) {
    Bint num1(a);
    Bint num2(b);
    Bint ans = num1 + num2;
    return Bint::write(ans);
}
Beispiel #10
0
string multiple(int a,int b) {
    Bint num1(a);
    Bint num2(b);
    Bint ans = num1 * num2;
    return Bint::write(ans);
}
Beispiel #11
0
    static void test_interval_relation() {
        smt_params params;
        ast_manager ast_m;
        register_engine re;
        context ctx(ast_m, re, params);    
        arith_util autil(ast_m);
        relation_manager & m = ctx.get_rel_context()->get_rmanager();
        m.register_plugin(alloc(interval_relation_plugin, m));
        interval_relation_plugin& ip = dynamic_cast<interval_relation_plugin&>(*m.get_relation_plugin(symbol("interval_relation")));
        SASSERT(&ip);
        
        relation_signature sig;
        sort* int_sort = autil.mk_int();
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);

        interval_relation& i1 = dynamic_cast<interval_relation&>(*ip.mk_empty(sig));
        interval_relation& i2 = dynamic_cast<interval_relation&>(*ip.mk_full(0, sig));

        i1.display(std::cout);
        i2.display(std::cout);
        SASSERT(i1.empty());
        SASSERT(!i2.empty());

        app_ref cond1(ast_m), cond2(ast_m), cond3(ast_m);
        app_ref cond4(ast_m), cond5(ast_m), cond6(ast_m);
        app_ref num1(ast_m);
        cond1 = autil.mk_le(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond2 = autil.mk_le(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(1), true));
        cond3 = autil.mk_le(ast_m.mk_var(2, int_sort), autil.mk_numeral(rational(2), true));
        cond4 = autil.mk_ge(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond5 = autil.mk_ge(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(0), true));
        cond6 = autil.mk_ge(ast_m.mk_var(2, int_sort), autil.mk_numeral(rational(5), true));
        num1 = autil.mk_numeral(rational(4), true);
        i2.filter_interpreted(cond1);
        i2.display(std::cout);
        // x0 <= 0
        
        unsigned cols1[2] = { 1, 2};
        unsigned cols2[2] = { 2, 3};
        relation_join_fn* join1 = ip.mk_join_fn(i1, i2, 2, cols1, cols2);        
        relation_transformer_fn* proj1 = ip.mk_project_fn(i1, 2, cols2);
        relation_transformer_fn* ren1  = ip.mk_rename_fn(i1, 2, cols2);
        relation_union_fn*       union1 = ip.mk_union_fn(i1, i2, &i1);
        relation_mutator_fn*     filterId1 = ip.mk_filter_identical_fn(i1, 2, cols1);
        relation_mutator_fn*     filterEq1 = ip.mk_filter_equal_fn(i1, num1, 2);               
        relation_mutator_fn*     filterCond1 = ip.mk_filter_interpreted_fn(i1, cond2);

        relation_base* i3 = (*join1)(i2, i2);
        i3->display(std::cout);       
 
        relation_transformer_fn* proj2 = ip.mk_project_fn(*i3, 2, cols2);

        (*filterEq1)(i2);
        i2.display(std::cout);
        // x0 <= 0
        // x2 = 4

        (*filterId1)(i2);
        i2.display(std::cout);
        // x0 <= 0
        // x1 = x2 = 4       
        relation_fact fact1(ast_m);
        fact1.push_back(autil.mk_numeral(rational(0), true));
        fact1.push_back(autil.mk_numeral(rational(4), true));
        fact1.push_back(autil.mk_numeral(rational(4), true));
        fact1.push_back(autil.mk_numeral(rational(5), true));
        SASSERT(i2.contains_fact(fact1));
        fact1[0] = autil.mk_numeral(rational(-1), true);
        SASSERT(i2.contains_fact(fact1));
        fact1[0] = autil.mk_numeral(rational(1), true);
        SASSERT(!i2.contains_fact(fact1));

        relation_base* i5 = (*ren1)(i2);
        i2.display(std::cout << "Orig\n");
        i5->display(std::cout << "renamed 2 |-> 3 |-> 2\n");

        (*filterCond1)(i2);
        i2.display(std::cout);
        // empty
        SASSERT(i2.empty());

        relation_base* i4 = (*proj2)(*i3);
        i4->display(std::cout);      
        
        i1.deallocate();
        i2.deallocate();
        i3->deallocate();
        i4->deallocate();
        i5->deallocate();
        dealloc(join1);
        dealloc(proj1);
        dealloc(ren1);
        dealloc(union1);
        dealloc(filterId1);
        dealloc(filterEq1);
        dealloc(filterCond1);
    }
Beispiel #12
0
    static void test_bound_relation() {

        std::cout << "bound relation\n";

        smt_params params;
        ast_manager ast_m;
        register_engine re;
        context ctx(ast_m, re, params);    
        arith_util autil(ast_m);
        relation_manager & m = ctx.get_rel_context()->get_rmanager();
        m.register_plugin(alloc(bound_relation_plugin, m));
        bound_relation_plugin& br = dynamic_cast<bound_relation_plugin&>(*m.get_relation_plugin(symbol("bound_relation")));
        SASSERT(&br);
        
        relation_signature sig;
        sort* int_sort = autil.mk_int();
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);

        bound_relation& i1 = dynamic_cast<bound_relation&>(*br.mk_empty(sig));
        bound_relation& i2 = dynamic_cast<bound_relation&>(*br.mk_full(0, sig));

        i1.display(std::cout << "empty:\n");
        i2.display(std::cout << "full:\n");
        SASSERT(i1.empty());
        SASSERT(!i2.empty());

        app_ref cond1(ast_m), cond2(ast_m), cond3(ast_m);
        app_ref cond4(ast_m), cond5(ast_m), cond6(ast_m);
        app_ref num1(ast_m);
        cond1 = autil.mk_lt(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond2 = autil.mk_lt(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(1), true));
        cond3 = autil.mk_lt(ast_m.mk_var(2, int_sort), ast_m.mk_var(3, int_sort));
        cond4 = autil.mk_ge(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond5 = autil.mk_ge(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(0), true));
        cond6 = autil.mk_ge(ast_m.mk_var(2, int_sort), autil.mk_numeral(rational(5), true));

        app_ref lt_x0x1(ast_m), lt_x1x2(ast_m), lt_x0x3(ast_m), lt_x0x2(ast_m);
        lt_x0x1 = autil.mk_lt(ast_m.mk_var(0, int_sort), ast_m.mk_var(1, int_sort));
        lt_x1x2 = autil.mk_lt(ast_m.mk_var(1, int_sort), ast_m.mk_var(2, int_sort));
        lt_x0x2 = autil.mk_lt(ast_m.mk_var(0, int_sort), ast_m.mk_var(2, int_sort));
        lt_x0x3 = autil.mk_lt(ast_m.mk_var(0, int_sort), ast_m.mk_var(3, int_sort));

        num1 = autil.mk_numeral(rational(4), true);
        
        unsigned cols1[2] = { 1, 2};
        unsigned cols2[2] = { 2, 3};
        unsigned cols3[3] = { 0, 2, 3 };
        relation_join_fn* join1 = br.mk_join_fn(i1, i2, 2, cols1, cols2);        
        relation_transformer_fn* proj1 = br.mk_project_fn(i1, 2, cols2);
        relation_transformer_fn* ren1  = br.mk_rename_fn(i1, 3, cols3);
        relation_union_fn*       union1 = br.mk_union_fn(i1, i2, &i1);
        relation_mutator_fn*     filterId1 = br.mk_filter_identical_fn(i1, 2, cols1);
        relation_mutator_fn*     filterEq1 = br.mk_filter_equal_fn(i1, num1, 2);               
        relation_mutator_fn*     filterCond1 = br.mk_filter_interpreted_fn(i1, cond3);

        relation_base* i3 = (*join1)(i2, i2);
        i3->display(std::cout);       
 
        relation_transformer_fn* proj2 = br.mk_project_fn(*i3, 2, cols2);

        (*filterEq1)(i2);
        i2.display(std::cout << "no-op still full\n");
        // no-op
        
        (*filterCond1)(i2);
        i2.display(std::cout << "x2 < x3\n");
        // x2 < x3

        (*filterId1)(i2);
        i2.display(std::cout << "id\n");
        // x1 = x2 < x3    
        relation_fact fact1(ast_m);

        i2.display(std::cout << "Orig\n");
        std::cout << "renamed ";
        for (unsigned i = 0; i < 3; ++i) {
            std::cout << cols3[i] << " ";
        }
        std::cout << "\n";
        relation_base* i5 = (*ren1)(i2);
        i5->display(std::cout);

        //SASSERT(i2.empty());

        relation_base* i4 = (*proj2)(*i3);
        i4->display(std::cout);      

        // test that equivalence classes are expanded.
        // { x1 = x3, x0 < x1 x1 < x2} u { x2 = x3, x0 < x3 } = { x0 < x3 }
        {
            relation_base* b1 = br.mk_full(0, sig);
            relation_base* b2 = br.mk_full(0, sig);
            unsigned x1x3[2] = { 1, 3 };
            unsigned x2x3[2] = { 2, 3 };
            scoped_ptr<relation_mutator_fn> id1 = br.mk_filter_identical_fn(*b1, 2, x1x3);
            scoped_ptr<relation_mutator_fn> ltx0x1 = br.mk_filter_interpreted_fn(*b1, lt_x0x1);
            scoped_ptr<relation_mutator_fn> ltx1x2 = br.mk_filter_interpreted_fn(*b1, lt_x1x2);
            scoped_ptr<relation_mutator_fn> ltx0x3 = br.mk_filter_interpreted_fn(*b2, lt_x0x3);
            scoped_ptr<relation_mutator_fn> id2 = br.mk_filter_identical_fn(*b2, 2, x2x3);
            (*id1)(*b1);
            (*ltx0x1)(*b1);
            (*ltx1x2)(*b1);
            b2->display(std::cout << "b2:\n");
            (*id2)(*b2);
            b2->display(std::cout << "b2:\n");
            (*ltx0x3)(*b2);
            b2->display(std::cout << "b2:\n");
            scoped_ptr<relation_union_fn> u = br.mk_union_fn(*b1, *b2, 0);
            b1->display(std::cout << "b1:\n");
            b2->display(std::cout << "b2:\n");
            (*u)(*b1, *b2, 0);

            b1->display(std::cout << "b1 u b2:\n");

            // TBD check property;
            
            b1->deallocate();
            b2->deallocate();
        }

        // test that equivalence classes are expanded.
        // { x1 = x2 = x3, x0 < x1} u { x1 = x3, x0 < x3, x0 < x2 } = { x0 < x2, x0 < x3 }
        {
            relation_base* b1 = br.mk_full(0, sig);
            relation_base* b2 = br.mk_full(0, sig);
            unsigned x0x3[2] = { 0, 3 };
            unsigned x1x3[2] = { 1, 3 };
            unsigned x2x3[2] = { 2, 3 };
            scoped_ptr<relation_mutator_fn> id1 = br.mk_filter_identical_fn(*b1, 2, x1x3);
            scoped_ptr<relation_mutator_fn> id2 = br.mk_filter_identical_fn(*b1, 2, x2x3);
            scoped_ptr<relation_mutator_fn> ltx0x1 = br.mk_filter_interpreted_fn(*b1, lt_x0x1);
            scoped_ptr<relation_mutator_fn> ltx0x2 = br.mk_filter_interpreted_fn(*b2, lt_x0x2);
            scoped_ptr<relation_mutator_fn> ltx0x3 = br.mk_filter_interpreted_fn(*b2, lt_x0x3);
            scoped_ptr<relation_mutator_fn> id3 = br.mk_filter_identical_fn(*b2, 2, x1x3);
            (*id1)(*b1);
            (*id2)(*b1);
            (*ltx0x1)(*b1);
            (*id3)(*b2);
            (*ltx0x2)(*b2);
            (*ltx0x3)(*b2);
            scoped_ptr<relation_union_fn> u = br.mk_union_fn(*b1, *b2, 0);
            b1->display(std::cout << "b1:\n");
            b2->display(std::cout << "b2:\n");
            (*u)(*b1, *b2, 0);
            b1->display(std::cout << "b1 u b2:\n");

            // TBD check property;
            
            b1->deallocate();
            b2->deallocate();
        }
        
        i1.deallocate();
        i2.deallocate();
        i3->deallocate();
        i4->deallocate();
        i5->deallocate();
        dealloc(join1);
        dealloc(proj1);
        dealloc(ren1);
        dealloc(union1);
        dealloc(filterId1);
        dealloc(filterEq1);
        dealloc(filterCond1);
    }
Beispiel #13
0
int main()      // runs code that makes dummy assignments put them into a vector list 'test' and creates matrix from given info
{

  std::vector<std::string> studs = * new std::vector<std::string>();
	studs.push_back("Tana");
	studs.push_back("Aubree");
	studs.push_back("Jacob");
	
	assgn num1("Assgn1", "Project", 50,"11-05",studs);    

	assgn num2("Assgn2", "HW", 15,"11-05",studs);  

	/* assgn num3("Assgn3", "HW", 15,"11-05",studs);  

	assgn num4("Assgn4", "Test", 50,"11-05",studs);  

	assgn num5("Assgn5", "Test", 50,"11-05",studs);  

	assgn num6("Assgn6", "Quiz", 25,"11-05",studs);  

	assgn num7("Assgn7", "Quiz", 25,"11-05",studs);  

	assgn num8("Assgn8", "Classwork", 20,"11-05",studs);  

	assgn num9("Assgn9", "Classwork", 15,"11-05",studs);  

	assgn num10("Assgn10", "Atten", 5,"11-05",,studs);  

	assgn num11("Assgn11", "Atten", 5,"11-05",studs);   */

	std::vector<assgn> test;

	test.push_back(num1);

	test.push_back(num2);

	/* test.push_back(num3);

	test.push_back(num4);

	test.push_back(num5);

	test.push_back(num6);

	test.push_back(num7);

	test.push_back(num8);

	test.push_back(num9);

	test.push_back(num10);

	test.push_back(num11); */
	
	float studgrade[20] = {0};

	for(int i = 0; i<numofstud; i++)
	{
		studgrade[i] = gradecalc(test,i);
		courseavg+= studgrade[i];
	}

	courseavg = (courseavg/numofstud);
	
	/* Print out everything. */

	Print(test,studgrade);

	return 0;
}
Beispiel #14
0
int juego()
{
    /*Generamos el numero misterioso*/
    int numero = aleatorio();
    int intentos = 0;

    char talvezs[128];
    int talvez = 0;
    char qidn;
    int np_1 = numero - num1(1);
    int np_2 = numero + num1(2);


    if (np_1 < 0) {
	np_1 = 0;
    }
    if (np_2 > 100) {
	np_2 = 100;
    }

    do
    {
        limpiar();
        printf("Has hecho %d intentos.\n", intentos);
        printf("El numero misterioso esta entre %d y %d.\n\n", np_1, np_2);
	printf("Escribe 'e' para cerrar\n");

        printf("Tu propuesta: ");
	/* gets_s() es un fork de gets() que arregla sus fallos de seguridad */
        gets_s(talvezs, 128);
	if (talvezs[0] == 'e') {
	  limpiar();
    	  printf("Bye !\n");
	  return 0;
	}
	talvez = atoi(talvezs);
	

        intentos = intentos + 1;
    }while(talvez != numero);

    /*Adivino el numero !*/

    limpiar();
    printf("=== FELICIDADES ===\n");
    printf("  === GANASTE ===\n\n");
    printf("El numero era: %d\n\n", numero);
    printf("Lo intentaste: %d veces\n", intentos);
    printf("Quieres volver a jugar ? (S/n): ");
    qidn = getchar();
    putchar(qidn);

    if(qidn == 'S' || qidn == 's')
    {
        limpiar();
        juego();
    }
    else if(qidn == 'N' || qidn == 'n')
    {
        limpiar();
        menu();
    }
    else
    {
        limpiar();
        menu();
    }
    return 0;
}