Ad

Lets praise the STL developers without making our code significantly slower. This will be nicer in C++20.

Code
Diff
  • #include <algorithm>
    #include <list>
    #include <execution>
    #include <iterator>
    
    auto merge_list(const std::list<int>& a, const std::list<int>& b) {
      std::list<int> o;
      std::merge(
        std::execution::seq,
        a.begin(),
        a.end(),
        b.begin(),
        b.end(),
        std::back_insert_iterator<std::list<int>>(o),
        [](const int a, const int b){
          return a < b;
        }
      );
      return o;
    }
    • #include <algorithm>
    • #include <list>
    • #include <execution>
    • #include <iterator>
    • auto merge_list(const std::list<int>& a, const std::list<int>& b) {
    • // If you REALLY want to keep the const & qualifiers: make copies
    • std::list<int> result(a);
    • std::list<int> m(b);
    • result.merge(m); // #payatribute2STLdevelopers #knowyourSTL
    • return result;
    • std::list<int> o;
    • std::merge(
    • std::execution::seq,
    • a.begin(),
    • a.end(),
    • b.begin(),
    • b.end(),
    • std::back_insert_iterator<std::list<int>>(o),
    • [](const int a, const int b){
    • return a < b;
    • }
    • );
    • return o;
    • }
Fundamentals
Code
Diff
  • using System.Numerics;
    
    public class basic 
    {
    		public static BigInteger pow(long down, ulong up)
    		{
    			BigInteger output = 1;
    			BigInteger cumulativeDown = down;
    
    			for(ulong bitChecker = 1; bitChecker > 0 && bitChecker <= up; bitChecker <<= 1)
    			{
    				if((bitChecker & up) != 0)
    				{
    					output *= cumulativeDown;
    				}
    
    				cumulativeDown *= cumulativeDown;
    			}
    
    			return output;
    		}
    }
    • using System.Numerics;
    • public class basic
    • {
    • public static BigInteger pow(long down, long up)
    • => up == 0 ? 1 : down * pow(down, up - 1);
    • public static BigInteger pow(long down, ulong up)
    • {
    • BigInteger output = 1;
    • BigInteger cumulativeDown = down;
    • for(ulong bitChecker = 1; bitChecker > 0 && bitChecker <= up; bitChecker <<= 1)
    • {
    • if((bitChecker & up) != 0)
    • {
    • output *= cumulativeDown;
    • }
    • cumulativeDown *= cumulativeDown;
    • }
    • return output;
    • }
    • }