예제 #1
0
파일: trhythm.cpp 프로젝트: SeeLook/nootka
QString Trhythm::string() const {
  QString ret = QString::number(weight());
  if (isRest())
    ret.prepend(QStringLiteral("R"));
  if (hasDot())
    ret.append(QStringLiteral("."));
  else if (isTriplet())
    ret.append(QStringLiteral("^3"));
  return ret;
}
예제 #2
0
int main()
{
	int a, b, c;
	for (a = 1; a < 1000; a++) {
		for (b = 1; b < 1000; b++) {
			for (c = 1; c < 1000; c++) {
				if (isTriplet(a,b,c) && a+b+c == 1000) {
					printf("The product of that triplet (%d, %d, %d) is: %d.\n", a, b, c, a*b*c);
					return 0;
				}
			}
		}
	}
	return 0;
}
예제 #3
0
파일: trhythm.cpp 프로젝트: SeeLook/nootka
void Trhythm::split(TrhythmList& twoRhythms) const {
  if (rhythm() == e_none || rhythm() == e_sixteenth)
    return; // nothing to split

  if (hasDot()) {
      twoRhythms << Trhythm(rhythm(), isRest(), false) // no triplet for sure
                << Trhythm(static_cast<Erhythm>(rhythm() + 1), isRest());
          // Also when there is a dot, for sure it is not lowest possible rhythm, so we may add 1 to rhythm value to obtain its half
  } else {
      Trhythm half(static_cast<Erhythm>(rhythm() + 1), isRest(), false, isTriplet());
      twoRhythms << half << half;
  }
  if (!isRest() && twoRhythms.size() == 2) {
    twoRhythms.first().setStemDown(stemDown());
    twoRhythms.last().setStemDown(stemDown());
  }
}
예제 #4
0
파일: 9.cpp 프로젝트: mGreb/projEuler
void main(){
	int product = 0;
	for (int a = 1; a <= 1000; a++){
		for (int b = 1; b <= 1000; b++){
			for (int c = 1; c <= 1000; c++){
				if ((a+b+c) == 1000){
					if (isTriplet(a,b,c)){
						product = a*b*c;
						printf("Result: %d\n", product);
						printf("a=%d, b=%d, c=%d\n", a, b, c);
						_getch();
						return;
					}
				}
			}
		}
	}
}
int main(int argc, char *argv[])
{
    int count = 1000;
    int i = 1;
    int j = 1;
    int k = 1;

    for(i = 1; i < count; i++) {
        for(j = 1; j < count; j++) {
            for(k = 1; k < count; k++) {
                if (isTriplet(i,j,k) == 0) {
                    if ((i+j+k) == count) {
                        printf("%d\n", i*j*k);
                        return(0);
                    }
                }
            }
        }
    }
}
예제 #6
0
파일: trhythm.cpp 프로젝트: SeeLook/nootka
void Trhythm::debug(const char* text) const {
  if (m_r == e_none)
    qDebug() << text << "no rhythm";
  else {
    qDebug() << text << xmlType() << "| rest" << isRest() << "| dot" << hasDot() << "| triplet" << isTriplet() << "| duration" << duration()
             << "| beam" << beam() << "| tie" << tie() << "| stem" << (stemDown() ? "down" : "up")
             << "|" << (m_prefs % 8) << m_prefs;
  }
}
예제 #7
0
파일: trhythm.cpp 프로젝트: SeeLook/nootka
/**
 * In most cases it returns only single element list because subtracting can be resolved with only one rhythm value.
 */
void Trhythm::sub(const Trhythm& r, TrhythmList& remained) const {
  if (r.rhythm() == e_none) {
      remained << *this;
      qDebug() << "[Trhythm] subtracting null rhythm! IS IT REALLY NECESSARY?";
  } else {
      if (r.isTriplet() != isTriplet()) { // TODO: It has to be solved by changing main note
        qDebug() << "[Trhythm] Subtracting triplets and no triplets unsupported";
        return;
      }

      int baseDur = duration();
      int subDur = r.duration();

      if (subDur > baseDur) {
        qDebug() << "[Trhythm] Subtracting rhythm" << r.duration() << "is greater than" << duration();
        return;
      }
      if (baseDur - subDur == 0) { // Return empty (null) rhythm when rhythms are the same
        remained << Trhythm(e_none);
        return;
      }
      Trhythm newR(baseDur - subDur, isRest());
      if (newR.rhythm() != e_none) { // In most cases subtracting returns single rhythm
        remained << newR;
        return;
      }

      if (r.isTriplet() || isTriplet()) // There is no support for subtracting triplets into multiple notes
        return;
      if (baseDur == 4) // 16th triplet - nothing to subtract from
        return;

      // For the rest cases list will contain two Trhythm elements
      if (baseDur == 36 && subDur == 6) // quarter with dot (4.) minus 16th = 4 and 16th
          remained << Trhythm(e_quarter, isRest()) << Trhythm(e_eighth, isRest(), true);
      else if (baseDur == 48) { // subtracting form half note
          remained << Trhythm(e_quarter, isRest());
          if (subDur == 6) // 2 - 16th = 4 and 8.
              remained << Trhythm(e_eighth, isRest(), true);
          else if (subDur == 18) // 2 - 8. = 4 and 16th
              remained << Trhythm(e_sixteenth, isRest());
      } else if (baseDur == 72) { // subtracting from half with dot
          remained << Trhythm(e_whole, isRest()); // whole is always first
          if (baseDur == 6) // 2. - 16th = 2 and 8.
              remained << Trhythm(e_eighth, isRest(), true);
          else if (baseDur == 12) // 2. - 8 = 2 and 8
              remained << Trhythm(e_eighth, isRest());
          else if (baseDur == 18) // 2. - 8. = 2 and 16th
              remained << Trhythm(e_sixteenth, isRest());
      } else if (baseDur == 96) { // subtracting from whole note
          remained << Trhythm(e_whole, isRest(), true); // whole wit dot is always first
          if (subDur == 6) // 1 - 16 = 2. and 8.
            remained << Trhythm(e_eighth, isRest(), true);
          else if (baseDur == 12) // 1 - 8 = 2. and 8
              remained << Trhythm(e_eighth, isRest());
          else if (baseDur == 18) // 1 - 8. = 2. and 16th
              remained << Trhythm(e_sixteenth, isRest());
          else if (baseDur == 36) { // 1 - 4. = 2 and 16th
              remained[0].setDot(false); // revert a dot set above
              remained << Trhythm(e_sixteenth, isRest());
          }
      } else if (baseDur == 144) { // subtracting from whole and dot
          if (subDur <= 48) {
              Trhythm half(e_half, isRest());
              half.sub(r, remained);
              remained.prepend(Trhythm(e_whole, isRest()));
          }
      }
  }
}