예제 #1
0
파일: 36.c 프로젝트: idtirba/Euler-1-50
main() {
   int bits[21], ndx, decimal=0, decimalSize=1, palindromeSum=0;
   int limit=1000000, binarySize=1, temp, decimalLimit=10;

   for(ndx=0;ndx<21;ndx++) {
      bits[ndx]=0;
   }   
   
   while(limit--) {
      bits[0]++;
      decimal++;
      if(decimal==decimalLimit) {
         decimalSize++;
         decimalLimit*=10;
      }
      CarryOver(bits);
      binarySize = GetBinarySize(decimal);
      if(IsBinaryPalindrome(bits, binarySize) && IsDecimalPalindrome(decimal, decimalSize)) {
         printf("%d : ", decimal, decimalSize);
         for(temp=0;temp<binarySize;temp++) {
            printf("%d", bits[temp]);
         }
         printf("\n", binarySize);
         palindromeSum += decimal;
      }
   }
   printf("Sum of Palindromes of both bases: %d\n", palindromeSum);
}
예제 #2
0
sU8 *sDiskItem::Load()
{
  sU8 *mem;
  sInt size;

  mem = 0;
  size = GetBinarySize(sDIA_DATA);
  if(size>0)
  {
    mem = new sU8[size];
    if(!GetBinary(sDIA_DATA,mem,size))
    {
      delete[] mem;
      mem = 0;
    }
  }

  return mem;
}
예제 #3
0
sChar *sDiskItem::LoadText()
{
  sChar *mem;
  sInt size;

  mem = 0;
  size = GetBinarySize(sDIA_DATA);
  if(size>0)
  {
    mem = new sChar[size+1];
    mem[size]=0;
    if(!GetBinary(sDIA_DATA,(sU8 *)mem,size))
    {
      delete[] mem;
      mem = 0;
    }
  }

  return mem;
}
예제 #4
0
//-----------------------------------------------------------------------------
int Builder::Build(bool upload)
{
    config.avrPath = config.arduinoInstall + "/hardware/tools/avr/bin";
    msg.ClearOutput();
    msg.ClearBuildMessages();

    progress = new BuildWindow((QWidget *)(this->parent())); //"Task in progress...", "Cancel", 0, 100, (QWidget *)this->parent());
    progress->setWindowModality(Qt::WindowModal);
    progress->SetPhase(BuildWindowTypes::compiling);
    SetPercentage(0);
    progress->show();
    qApp->processEvents();
    running = true;

    project = workspace.GetCurrentProject();
    if (project == NULL) {
        return -1;
    }

    if (project->rebuild) {
        if (Clean()) {
            project->rebuild = false;
        }
    }

    map <QString, BoardDef>::const_iterator board = config.boards.find(project->boardName);
    if (board == config.boards.end()) {
        msg.Add("Could not find board configuration for project: " + project->name, mtError);
        return false;
    }

    // Create the build directory
    buildPath = config.workspace + "/" + project->name + "/build"; //QDir().tempPath() + "/mariamole/build/" + project->name;
    QDir().mkpath(buildPath);

    // Get core lib filename
    coreLib = buildPath + "/arduino_core_" + board->second.build_variant+".a";

    msg.ClearBuildInfo();

    msg.AddOutput("Detecting undeclared functions in main project file: " + project->name + ".cpp...", false);

    if (config.useAutoGeneratedFile) {
        ImportDeclarations();
    }
    bool ok = true;
    for (unsigned int i=0; i < project->files.size(); i++) {
        QString ext = QFileInfo(project->files.at(i).name).suffix().toUpper();
        if ((ext == "CPP") || (ext == "C")) {
            ok = ok & Compile(i);
            if (GetCancel()) {
                msg.Add("Build cancelled by the user!", mtRegular);
                ok = false;
                break;
            }
            SetPercentage(40 * i / project->files.size());
            //SleepEx(1500, true);
        }
    }

    //QThread::sleep(5);

    if (GetCancel()) {
        msg.Add("Build cancelled by the user!", mtRegular);
        ok = false;
    }

    if (ok) {
        ok = Link();
        if (ok) {
            msg.Add("Project " + project->name + " successfully built!", mtSuccess);
            GetBinarySize();
        } else {
            msg.Add("Error linking project " + project->name, mtError);
        }
    } else {
        msg.Add("Error while building project " + project->name + ".", mtError);
    }

    if(ok && upload) {
        ok = Upload();
        if (ok) {
            msg.Add("Project " + project->name + " binaries successfully uploaded to board", mtSuccess);
        } else {
            if (project->programmer != "") {
                msg.Add("Error while uploading program to " + project->boardName
                        + " using programmer " +  project->programmer + ". Please check the output window for details", mtError);
            } else {
                msg.Add("Error while uploading program to " + project->boardName
                        + " via USB cable. Please check the output window for details", mtError);
            }
        }

        if (GetCancel()) {
            msg.Add("Build cancelled by the user!", mtRegular);
            ok = false;
        }
    }
    if (ok) {
        lastBuildStatus = 2;
    } else {
        lastBuildStatus = 1;
    }

    running = false;
    progress->hide();
    delete progress;
    return ok;
}