Пример #1
0
int functions(int a,int b)
{
   if(b==1 || a==1)
        return 1;
    if(a<b)
        return functions(a,a);
    if(a==b)
        return functions(a,b-1)+1;
    if(b>1&&a>b)
	return functions(a-b,b)+functions(a,b-1);
}
Пример #2
0
void serialize_to(OutputIterator output, BombermanGame& gamestate)
{
	serialize_to(output, static_cast<uint32_t>(gamestate.remaining_time()));
	for(auto& x : gamestate.current_level)
	{
		char deserialized_entity;
		dispatch(functions(
		[&](const EmptySpace&){ deserialized_entity = 0; },
		[&](const DestructibleWall&){ deserialized_entity = 1; },
		[&](const NondestructibleWall&){ deserialized_entity = 2; },
		[&](const Bomb&){ deserialized_entity = 3; }), x);
		*output++ = deserialized_entity;
	}
	for(auto& player : gamestate.players)
	{
		Point pos = player.position();
		assert(in_range(pos.x(), std::numeric_limits<uint16_t>::min(), std::numeric_limits<uint16_t>::max()));
		assert(in_range(pos.y(), std::numeric_limits<uint16_t>::min(), std::numeric_limits<uint16_t>::max()));
		serialize_to(output, static_cast<uint16_t>(pos.x()));
		serialize_to(output, static_cast<uint16_t>(pos.y()));
		// przerobione pola
		serialize_to(output, static_cast<uint8_t>(player.move_progress_percent()));
		assert(in_range(player.direction(), -4, 4));
		serialize_to(output, static_cast<uint8_t>(player.direction()));
		// TODO: bomby
		serialize_to(output, static_cast<uint8_t>(0));
		serialize_to(output, static_cast<uint8_t>(!player.is_hurt()));
	}
}
Пример #3
0
void VCSpeedDialProperties::accept()
{
    /* Name */
    m_dial->setCaption(m_nameEdit->text());

    /* Functions */
    m_dial->setFunctions(functions());

    /* Speed types */
    VCSpeedDial::SpeedTypes types = 0;
    if (m_fadeInCheck->isChecked() == true)
        types |= VCSpeedDial::FadeIn;
    if (m_fadeOutCheck->isChecked() == true)
        types |= VCSpeedDial::FadeOut;
    if (m_durationCheck->isChecked() == true)
        types |= VCSpeedDial::Duration;
    m_dial->setSpeedTypes(types);

    /* Input sources */
    m_dial->setAbsoluteValueRange(m_absoluteMinSpin->value() * 1000,
                                  m_absoluteMaxSpin->value() * 1000);
    m_dial->setInputSource(m_absoluteInputSource, VCSpeedDial::absoluteInputSourceId);
    m_dial->setInputSource(m_tapInputSource, VCSpeedDial::tapInputSourceId);

    QDialog::accept();
}
Пример #4
0
void dumpGlInfo(QTextStream &str, bool listExtensions)
{
    QOpenGLContext context;
    if (context.create()) {
#  ifdef QT_OPENGL_DYNAMIC
        str << "Dynamic GL ";
#  endif
        switch (context.openGLModuleType()) {
        case QOpenGLContext::LibGL:
            str << "LibGL";
            break;
        case QOpenGLContext::LibGLES:
            str << "LibGLES";
            break;
        }
        QWindow window;
        window.setSurfaceType(QSurface::OpenGLSurface);
        window.create();
        context.makeCurrent(&window);
        QOpenGLFunctions functions(&context);

        str << " Vendor: " << reinterpret_cast<const char *>(functions.glGetString(GL_VENDOR))
            << "\nRenderer: " << reinterpret_cast<const char *>(functions.glGetString(GL_RENDERER))
            << "\nVersion: " << reinterpret_cast<const char *>(functions.glGetString(GL_VERSION))
            << "\nShading language: " << reinterpret_cast<const char *>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION))
            <<  "\nFormat: " << context.format();

        if (listExtensions) {
            QList<QByteArray> extensionList = context.extensions().toList();
            std::sort(extensionList.begin(), extensionList.end());
            str << " \nFound " << extensionList.size() << " extensions:\n";
            foreach (const QByteArray &extension, extensionList)
                str << "  " << extension << '\n';
        }
    } else {
Пример #5
0
quint32 Collection::totalDuration()
{
    quint32 totalDuration = 0;

    foreach(QVariant fid, functions())
    {
        Function* function = doc()->function(fid.toUInt());
        totalDuration += function->totalDuration();
    }
Пример #6
0
int main()
{
    int c;
    while(scanf("%d",&c)!=EOF)
    {
    printf("%d\n",functions(c,c));
    }
   return 0;
}
/**
 *  Constructor
 *  @param  zval            The object that is being iterated
 *  @param  iterator        The iterator that is implemented by the extension
 */
IteratorImpl::IteratorImpl(zval *object, Iterator *iterator) : _userspace(iterator)
{
    // initialize the iterator
    zend_iterator_init(&_iterator);

    // copy the object to the iterator, and set the callbacks
	ZVAL_COPY(&_iterator.data, object);
	_iterator.funcs = functions();
}
Пример #8
0
void UberShaderFactory::load_custom_functions(std::shared_ptr<ShadingModel> const& model) {

    std::string functions(model->get_stages()[stage_].get_functions());

    // get signature of each custom function
    // ...

    custom_functions_.push_back(functions);

}
Пример #9
0
void Doc::postLoad()
{
    QListIterator <Function*> functionit(functions());
    while (functionit.hasNext() == true)
    {
        Function* function(functionit.next());
        Q_ASSERT(function != NULL);
        function->postLoad();
    }
}
Пример #10
0
void VCSpeedDialProperties::slotAddClicked()
{
    FunctionSelection fs(this, m_doc);
    fs.setMultiSelection(true);
    fs.setDisabledFunctions(functions().toList());
    if (fs.exec() == QDialog::Accepted)
    {
        foreach (quint32 id, fs.selection())
            createFunctionItem(id);
    }
}
Пример #11
0
VectorialFunction::VectorialFunction( const std::string& funcs, const std::string& vars)
  : m_is_parsed(false),
    m_vars(""),
    m_nbvars(0),
    m_functions(0),
    m_parsers(),
    m_result()
{
  functions( funcs );
  variables( vars );
  parse();
}
Пример #12
0
void XYFitCurveDock::showFunctions() {
	QMenu menu;
	FunctionsWidget functions(&menu);
	connect(&functions, SIGNAL(functionSelected(QString)), this, SLOT(insertFunction(QString)));
	connect(&functions, SIGNAL(functionSelected(QString)), &menu, SLOT(close()));

	QWidgetAction* widgetAction = new QWidgetAction(this);
	widgetAction->setDefaultWidget(&functions);
	menu.addAction(widgetAction);

	QPoint pos(-menu.sizeHint().width()+uiGeneralTab.tbFunctions->width(),-menu.sizeHint().height());
	menu.exec(uiGeneralTab.tbFunctions->mapToGlobal(pos));
}
Пример #13
0
void AddVCButtonMatrix::slotAddClicked()
{
    FunctionSelection fs(this, m_doc);
    fs.setDisabledFunctions(functions());
    if (fs.exec() == true)
    {
        QListIterator <quint32> it(fs.selection());
        while (it.hasNext() == true)
            addFunction(it.next());
    }

    setAllocationText();
}
Пример #14
0
int main() {
  functions();
  multi_variable_functions();
  derivation();
  more_about_derivation();
  higher_level_derivatives();
  more_functions();
  higher_order_functions();
  simplifications();
  integers();
#ifdef AUTO_DERIVE_COMPLEX_TESTS
  complex_variables();
#endif
}
Пример #15
0
void charmaking (int linesNum) {
    char a [linesNum][60];
    char *text [linesNum];
    int i, curX, curY;
    int white_text = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
    int blue_text = FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
    int blueB_text = FOREGROUND_BLUE | FOREGROUND_INTENSITY;
    int red_text = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_INTENSITY;
    for (i = 0; i < linesNum; i++) {
    PosColor  (3, (7 + linesNum), white_text);
    printf (" Enter a string number ");
    printf ("%i", i + 1);
    printf ( " \n\n             HERE>> ");
    PosColor ( 20, 9 + linesNum, white_text);
    gets(a[i]);
    if (strlen(a[0]) == 0)
        i = -1; else {
    if (strlen(a[i]) > 59 ) {
       PosColor (5, 12 + linesNum, white_text);
       printf ("The line is too long!");
       i--;
       getch();
       for (curX = 5; curX < 26; curX++){
        PosColor (curX, 12 + linesNum, 0);
        printf (" ");
       }
        for (curX = 0; curX < 81; curX++){
        PosColor (curX, 10 + linesNum, 0 );
        printf (" ");
        PosColor(0, 0, blue_text);
    }
       }
    else {
       PosColor(10, 4 + i, blue_text);
       text[i] = &a[i][0];
       puts(a[i]);
    }
    for (curX = 20; curX < 81; curX++){
        PosColor (curX, 9 + linesNum, 0 );
        printf (" ");
    }
    if (i != 0 && strlen(a[i]) == 0)
        i--;
    PosColor(0, 0, blue_text);
    }
    }
    clearaftertable (linesNum);
    PosColor (0, 7 + linesNum, white_text);
    functions(text, linesNum);
}
Пример #16
0
QString openGlContext()
{
    QString result;
    QTextStream str(&result);

    QOpenGLContext context;
    if (context.create()) {
#  ifdef QT_OPENGL_DYNAMIC
        str << "Dynamic GL ";
#  endif
        switch (context.openGLModuleType()) {
        case QOpenGLContext::LibGL:
            str << "LibGL";
            break;
        case QOpenGLContext::LibGLES:
            str << "LibGLES";
            break;
        }

        QWindow window;
        if (QGuiApplication::platformName() == QLatin1String("greenisland"))
            window.setFlags(Qt::Desktop);
        window.setSurfaceType(QSurface::OpenGLSurface);
        //window.setScreen(QGuiApplication::primaryScreen());
        window.create();
        if (context.makeCurrent(&window)) {
            QOpenGLFunctions functions(&context);

            str << " Vendor: " << reinterpret_cast<const char *>(functions.glGetString(GL_VENDOR))
                << "\nRenderer: " << reinterpret_cast<const char *>(functions.glGetString(GL_RENDERER))
                << "\nVersion: " << reinterpret_cast<const char *>(functions.glGetString(GL_VERSION))
                << "\nGLSL version: " << reinterpret_cast<const char *>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION))
                << "\nFormat: " << context.format();

            QList<QByteArray> extensionList = context.extensions().toList();
            std::sort(extensionList.begin(), extensionList.end());
            QByteArray extensions = extensionList.join(' ');
            str << " \nFound " << extensionList.size() << " extensions:\n";
            str << wordWrap(extensions, 78);

            context.doneCurrent();
        }
        window.destroy();
    } else {
        str << "Unable to create an Open GL context.\n";
    }

    return result;
}
Пример #17
0
int main()
{
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	int k = 50;
	background();
	pos.X = 39;
	pos.Y = 12;
	axisPrinter(pos);
	functions();
	fGraph2(pos, k);
	fGraph1(pos, k/10);
	moving(pos, k);
	return EXIT_SUCCESS;
}
Пример #18
0
static int compile(std::string path, std::ostream &dest)
{
	ErrorLog log;
	DummyImporter modules;
	std::ifstream in(path);
	std::stringstream ss;
	ss << in.rdbuf();
	Scanner tokens(ss.str(), path);
	ParserStack ast(tokens, log, path);
	Semantics::Program functions(ast, log, modules, path);
	while (functions.Next()) {
		// emit(functions.Current(), dest);
	}
	return log.HasReceivedReport();
}
Пример #19
0
/** Makes sure that the function is consistent.
 */
void CompositeFunction::checkFunction() {
  m_nParams = 0;
  m_paramOffsets.clear();
  m_IFunction.clear();

  std::vector<IFunction_sptr> functions(m_functions.begin(), m_functions.end());
  m_functions.clear();

  for (auto &f : functions) {
    CompositeFunction_sptr cf =
        boost::dynamic_pointer_cast<CompositeFunction>(f);
    if (cf)
      cf->checkFunction();
    addFunction(f);
  }
}
/*!
    \fn bool QOpenGLFramebufferObject::bindDefault()

    Switches rendering back to the default, windowing system provided
    framebuffer.
    Returns \c true upon success, false otherwise.

    \sa bind(), release()
*/
bool QOpenGLFramebufferObject::bindDefault()
{
    QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
    QOpenGLFunctions functions(ctx);

    if (ctx) {
        ctx->d_func()->current_fbo = ctx->defaultFramebufferObject();
        functions.glBindFramebuffer(GL_FRAMEBUFFER, ctx->d_func()->current_fbo);
#ifdef QT_DEBUG
    } else {
        qWarning("QOpenGLFramebufferObject::bindDefault() called without current context.");
#endif
    }

    return ctx != 0;
}
Пример #21
0
  virtual bool runOnModule(Module &M) {
    
    std::vector<Function*> Fs = functions(M);
    
    
    for (std::vector<Function*>::iterator I = Fs.begin(), E = Fs.end(); I != E; ++I) {

      Function *F = (*I);
      
      if (F->isDeclaration()) {
        replaceWithLoweredDeclaration(M, F);
      } else {
        replaceWithLoweredImplementation(M, F);
      }
    }

    linkLibrary(M);
    
    return false;
  }
/**
 * Function representing the <prg> productions
 */
void RecursiveDescentParser::prg() {
	if(errorCondition) return;
	
	if(token == TK_VOID || token == TK_INT ||
			token == TK_CHAR) 
	{
#if DEBUG_PARSER
		std::cout << "<prg> --> <functions>eoft\n";
#endif
		mainLabel = iCode.getNextLabel();
		iCode.threeAddressCode(0, TAC_CALL, mainLabel, 0);
		iCode.threeAddressCode(TAC_HALT);
		
		functions();
		match(TK_EOF);
	}
	else 
	{
		errorHandler();
	}
}
Пример #23
0
		const AST::MethodSet*
		getMethodSetForObjectType(Context& context, const AST::Type* const objectType) {
			assert(objectType->isObject());
			
			AST::MethodSet::ElementSet elements;
			
			const auto typeInstance = objectType->getObjectType();
			const auto templateVarMap = objectType->generateTemplateVarMap();
			
			for (const auto& function: typeInstance->functions()) {
				auto constPredicate = function->constPredicate().substitute(templateVarMap,
				                                                            /*selfconst=*/AST::Predicate::SelfConst());
				auto noexceptPredicate = function->type().attributes().noExceptPredicate().substitute(templateVarMap,
				                                                                                      /*selfconst=*/AST::Predicate::SelfConst());
				auto requirePredicate = function->requiresPredicate().substitute(templateVarMap,
				                                                                 /*selfconst=*/AST::Predicate::SelfConst());
				const auto functionType = function->type().substitute(templateVarMap,
				                                                      /*selfconst=*/AST::Predicate::SelfConst());
				const bool isStatic = function->isStaticMethod();
				
				AST::MethodSetElement functionElement(
					function->templateVariables().copy(),
					std::move(constPredicate),
					std::move(noexceptPredicate),
					std::move(requirePredicate),
					isStatic,
					functionType.returnType(),
					functionType.parameterTypes().copy());
				
				elements.push_back(std::make_pair(function->canonicalName(), std::move(functionElement)));
			}
			
			// Sort the elements.
			std::sort(elements.begin(), elements.end(), comparePairKeys<AST::MethodSet::Element>);
			
			auto constObjectPredicate = objectType->constPredicate().substitute(templateVarMap,
			                                                                    /*selfconst=*/AST::Predicate::SelfConst());
			
			return AST::MethodSet::get(context.astContext(), std::move(constObjectPredicate), std::move(elements));
		}
Пример #24
0
void test()
{
    auto error_func = [] { printf("invalid bitmask"); };
    std::vector<Function<void()>> functions(FlagCount, error_func);

    functions[      0] = [] { printf("no flags"); };
    functions[    SYN] = [] { printf("SYN");      };
    functions[    FIN] = [] { printf("FIN");      };
    functions[    ACK] = [] { printf("ACK");      };
    functions[SYN|ACK] = [] { printf("SYN|ACK"); };
    functions[FIN|ACK] = [] { printf("FIN|ACK"); };
    functions[    RST] = [] { printf("RST");     };

    functions[FIN|SYN|ACK|RST] = [] { printf("FIN|SYN|ACK|RST test"); };

    unsigned index = 0;
    for (auto&& f : functions)
    {
        printf("\n%s\t", binary4[index++]);
        f();
    }
}
Пример #25
0
bool Doc::saveXML(QDomDocument* doc, QDomElement* wksp_root)
{
    QDomElement root;

    Q_ASSERT(doc != NULL);
    Q_ASSERT(wksp_root != NULL);

    /* Create the master Engine node */
    root = doc->createElement(KXMLQLCEngine);
    wksp_root->appendChild(root);

    /* Write fixtures into an XML document */
    QListIterator <Fixture*> fxit(fixtures());
    while (fxit.hasNext() == true)
    {
        Fixture* fxi(fxit.next());
        Q_ASSERT(fxi != NULL);
        fxi->saveXML(doc, &root);
    }

    /* Write functions into an XML document */
    QListIterator <Function*> funcit(functions());
    while (funcit.hasNext() == true)
    {
        Function* func(funcit.next());
        Q_ASSERT(func != NULL);
        func->saveXML(doc, &root);
    }

    QListIterator <FixtureGroup*> grpit(fixtureGroups());
    while (grpit.hasNext() == true)
    {
        FixtureGroup* grp(grpit.next());
        Q_ASSERT(grp != NULL);
        grp->saveXML(doc, &root);
    }

    return true;
}
Пример #26
0
	bool run_test(std::string const &test_name,
				  std::string const &source,
				  ValuePredicate const &check_result,
				  std::ostream &out)
	{
		source_range const source_range((source.data()), source.data() + source.size());
		auto const program = compile_unit(source_range);
		run::default_garbage_collector gc;
		run::interpreter interpreter(gc, nullptr);
		run::value result;
		auto const duration = measure_running_duration([&result, &program, &interpreter, &gc]()
		{
			result = interpreter.call(
				intermediate::function_ref(program, program.functions().front()), {});
			gc.sweep(run::sweep_mode::full);
		});
		out << test_name << " \t";
		bool const is_success = check_result(result);
		out << (is_success ? "succeeded" : "failed") << " in \t";
		print_running_duration(out, duration);
		out << '\n';
		return is_success;
	}
Пример #27
0
void moving(COORD centre, double k){
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	int input = 0;
	while (input != 27){
		input = getch();
		background();
		switch (input)
		{
		case 'w':
			centre.Y--;
			axisPrinter(centre);
			functions();
			break;
		case 's':
			centre.Y++;
			axisPrinter(centre);
			functions();
			break;
		case 'd':
			centre.X++;
			axisPrinter(centre);
			functions();
			break;
		case 'a':
			centre.X--;
			axisPrinter(centre);
			functions();
			break;
		case '-':
			axisPrinter(centre);
			functions();
			if(k > 10)
				k = k - 10;
			break;
		case '+':
			axisPrinter(centre);
			functions();
			k = k + 10;
			break;
		}
		fGraph2(centre, k);
        fGraph1(centre, k/10);
	}
}
Пример #28
0
void test_stochastic_gradient_descent()
{
    const size_t n_functions = 3;
    std::vector<std::function<double(const std::vector<double>&)>> functions(n_functions);
    for(size_t i = 0; i < n_functions; ++i)
        functions[i] = [=](const std::vector<double>& x) -> double
    {
        return std::pow(x[i], 2);
    };

    const std::vector<double> initial_x {1.0, 2.0, 3.0};
    const double step_size {1.0};
    const double tolerance {1e-10};
    const int max_iterations {10000};
    const double delta {0.001};

    std::cout << "Testing stochastic gradient descent..." << std::endl;
    std::vector<double> result {stochastic_gradient_descent(functions, initial_x, step_size, tolerance, max_iterations, delta)};

    std::cout << "These values have to be close to zero: ";
    for(auto& i:result)
        std::cout << i << " ";
    std::cout << std::endl << "Test complete" << std::endl;
}
Пример #29
0
 const WRATHLayerItemNodeBase::node_function_packet&
 node_functions(void) const
 {
   return functions();
 }
Пример #30
0
QList<Section> QsCodeMarker::sections( const InnerNode *inner, SynopsisStyle style, Status status )
{
    QList<Section> sections;

    if (inner->type() != Node::Class)
        return sections;

    const ClassNode *classe = static_cast<const ClassNode *>(inner);

    if ( style == Summary ) {
	FastSection enums(classe, "Enums", "", "enum", "enums");
	FastSection functions(classe, "Functions", "", "function", "functions");
	FastSection readOnlyProperties(classe, "", "Read-Only Properties", "property", "properties");
	FastSection signalz(classe, "Signals", "", "signal", "signals");
	FastSection writableProperties(classe, "", "Writable Properties", "property", "properties");

	QStack<const ClassNode *> stack;
	stack.push( classe );

	while ( !stack.isEmpty() ) {
	    const ClassNode *ancestorClass = stack.pop();

	    NodeList::ConstIterator c = ancestorClass->childNodes().begin();
	    while ( c != ancestorClass->childNodes().end() ) {
		if ( (*c)->access() == Node::Public ) {
		    if ( (*c)->type() == Node::Enum ) {
			insert( enums, *c, style, status );
		    } else if ( (*c)->type() == Node::Function ) {
			const FunctionNode *func = (const FunctionNode *) *c;
			if ( func->metaness() == FunctionNode::Signal ) {
			    insert( signalz, *c, style, status );
			} else {
			    insert( functions, *c, style, status );
			}
		    } else if ( (*c)->type() == Node::Property ) {
			const PropertyNode *property =
				(const PropertyNode *) *c;
			if ( property->setters().isEmpty() ) {
			    insert( readOnlyProperties, *c, style, status );
			} else {
			    insert( writableProperties, *c, style, status );
			}
		    }
		}
		++c;
	    }

	    QList<RelatedClass>::ConstIterator r = ancestorClass->baseClasses().begin();
	    while ( r != ancestorClass->baseClasses().end() ) {
		stack.prepend( (*r).node );
		++r;
	    }
	}
	append( sections, enums );
	append( sections, writableProperties );
	append( sections, readOnlyProperties );
	append( sections, functions );
	append( sections, signalz );
    } else if ( style == Detailed ) {
	FastSection enums( classe, "Enum Documentation", "", "member", "members");
	FastSection functionsAndSignals( classe, "Function and Signal Documentation", "", "member", "members");
	FastSection properties( classe, "Property Documentation", "", "member", "members");

	NodeList::ConstIterator c = classe->childNodes().begin();
	while ( c != classe->childNodes().end() ) {
	    if ( (*c)->access() == Node::Public ) {
		if ( (*c)->type() == Node::Enum ) {
		    insert( enums, *c, style, status );
		} else if ( (*c)->type() == Node::Function ) {
		    insert( functionsAndSignals, *c, style, status );
		} else if ( (*c)->type() == Node::Property ) {
		    insert( properties, *c, style, status );
		}
	    }
	    ++c;
	}
	append( sections, enums );
	append( sections, properties );
	append( sections, functionsAndSignals );
    } else { // ( style == SeparateList )
	FastSection all(classe, "", "", "member", "members");

	QStack<const ClassNode *> stack;
	stack.push( classe );

	while ( !stack.isEmpty() ) {
	    const ClassNode *ancestorClass = stack.pop();

	    NodeList::ConstIterator c = ancestorClass->childNodes().begin();
	    while ( c != ancestorClass->childNodes().end() ) {
		if ( (*c)->access() == Node::Public )
		    insert( all, *c, style, status );
		++c;
	    }

	    QList<RelatedClass>::ConstIterator r = ancestorClass->baseClasses().begin();
	    while ( r != ancestorClass->baseClasses().end() ) {
		stack.prepend( (*r).node );
		++r;
	    }
	}
	append( sections, all );
    }
    return sections;
}