Ad
  • Default User Avatar

    theres like two main approaches taken to this problem, but some just way overcomplicate the solution.
    hint. read about c++ streams

  • Default User Avatar

    does up and down climbs count equal weight of difference
    if starting from 9 -> 8 -> 7 differences would be still = 3 between these?

    is it the same as going from 7->8->7 differences would still be 3?

  • Default User Avatar

    pro (or noob) tips for C++

    • remember to forward declare if you intend to use class of your own
    • know where to instantiate your object of the class that you need (best practice avoid global variables)
    • know the initial state
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    very clean version using the generic programming! would not have thought this up myself very easily.

  • Default User Avatar

    what must I do for C++ version of this kata, there is barely any test cases and some comment tells me to create helper object but my code keeps crashing because of that?! I already passed this kata with plain C, but I wanted to see if C++ could be done also...

  • Default User Avatar

    very nice kata but it was quite simple to "problem-solve" (usually for 6kyu and harder -> they are devilish for problemsolving)
    It has been a long time (no pun intended) since I coded Java.

    I just used if-else statements and basic math, and maybe two loops to get the time from the input string xD ...
    Then I saw that other people used "snappy code" with all kinds of cool Java functions I was awestruck once again
    O_o

  • Default User Avatar

    this was the most confusing kata ever... I still dont know what I was supposed to do even though apparently I succeeded xD

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Definitely a tough challenge from the computational/algorithmic point of view... I'm not sure if my way of doing it is the most efficient because my solution relies on rational number calculations (with c++ vector) and factoring the initial number...

    if any of you decide to implement factoring -> make sure your trialDivisionFactoring is not the naive solution! :D

  • Default User Avatar

    I finished the problem by improving the efficiency of factoring function that I had !

  • Default User Avatar

    Code passes basic tests but takes too long to execute apparently...

    I was doing this in C++ and was under the impression that you have to treat the summed reciprocals as rational numbers (in my code vector with num and denom as [0] and [1])
    Then you would presumably have to expand those rationals to the same base, and add the numerators, and get then the biggest factor, would be the "expandedDenominator"
    Then you just invert and multiply, and that result itself has to be reduced to irreducable form.
    But my code is apparently too slow even still... but

    ´´´CPP
    #include
    #include
    #include
    #include
    #include
    using namespace std;

    unsigned long long recurGCD(unsigned long long a, unsigned long long b) {
    if (b == 0) {
    return a;
    }
    else {
    return recurGCD(b, a%b);
    }
    }

    bool isOre(unsigned int n) {
    vector factorslist;
    unsigned long long expandedDenominator = 1;
    int factorscount = 0;
    unsigned long long biggest = 1;
    unsigned long long sumExpandedNominator = 0;

    for (uint64_t i = 1; i <= n; i++) {
    	if (n%i == 0) {
    		factorslist.push_back(i);
    		++factorscount;
    		if (i>biggest) {
    			biggest = i;
    		}
    	}
    }
    vector <unsigned long long> rationalnumber;
    expandedDenominator = biggest;
    for (uint64_t i = 0; i < factorscount; i++) {
    	unsigned long long temp = expandedDenominator / factorslist[i];
    	sumExpandedNominator += temp;
    }
    rationalnumber.push_back(sumExpandedNominator);
    rationalnumber.push_back(expandedDenominator);
    unsigned long long gcdValue = 150;
    
    while (gcdValue != 1) {
    	gcdValue = recurGCD(rationalnumber[0], rationalnumber[1]);
    	rationalnumber[0] /= gcdValue;
    	rationalnumber[1] /= gcdValue;
    }
    vector<unsigned long long> harmonicMean = { 1,1 };
    harmonicMean[0] = factorscount * rationalnumber[1];
    harmonicMean[1] = 1 * rationalnumber[0];
    gcdValue = 150;
    while (gcdValue != 1) {
    	gcdValue = recurGCD(harmonicMean[0], harmonicMean[1]);
    	harmonicMean[0] /= gcdValue;
    	harmonicMean[1] /= gcdValue;
    }
    
    if (gcdValue == 1 && harmonicMean[1] == 1) {
    	return true;
    }
    else {
    	return false;
    }
    

    }

    ´´´

  • Loading more items...