title: Painting Fence Algorithm
signature: function painting_fence_algorithm(n, k)
source_py: def painting_fence_algorithm(n, k):
      total = k
      mod = 1000000007
      (same, diff) = (0, k)
      for i in range(2, (n + 1)):
          same = diff
          diff = (total * (k - 1))
          diff = (diff % mod)
          total = ((same + diff) % mod)
      return total
source_cpp: long painting_fence_algorithm(int n, int k) {
    long total = k;
    int mod = 1000000007;
    int same = 0, diff = k;
    for ( int i = 2;
    i <= n;
    i ++ ) {
      same = diff;
      diff = total * ( k - 1 );
      diff = diff % mod;
      total = ( same + diff ) % mod;
    }
    return total;
  }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(n, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(n, k) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver(6, 30, 725841870)
      print(string.format("TEST-0...%s",result))
  
      result = driver(23, 87, 370622679)
      print(string.format("TEST-1...%s",result))
  
      result = driver(89, 31, 7554776)
      print(string.format("TEST-2...%s",result))
  
      result = driver(63, 36, 76740139)
      print(string.format("TEST-3...%s",result))
  
      result = driver(23, 68, 647498520)
      print(string.format("TEST-4...%s",result))
  
      result = driver(44, 66, 70208793)
      print(string.format("TEST-5...%s",result))
  
      result = driver(81, 18, 227130467)
      print(string.format("TEST-6...%s",result))
  
      result = driver(43, 73, 204618786)
      print(string.format("TEST-7...%s",result))
  
      result = driver(9, 42, 797370673)
      print(string.format("TEST-8...%s",result))
  
      result = driver(41, 98, 903959704)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 725841870, "inputs": {"n": 6, "k": 30}}, {"idx": 1, "outputs": 370622679, "inputs": {"n": 23, "k": 87}}, {"idx": 2, "outputs": 7554776, "inputs": {"n": 89, "k": 31}}, {"idx": 3, "outputs": 76740139, "inputs": {"n": 63, "k": 36}}, {"idx": 4, "outputs": 647498520, "inputs": {"n": 23, "k": 68}}, {"idx": 5, "outputs": 70208793, "inputs": {"n": 44, "k": 66}}, {"idx": 6, "outputs": 227130467, "inputs": {"n": 81, "k": 18}}, {"idx": 7, "outputs": 204618786, "inputs": {"n": 43, "k": 73}}, {"idx": 8, "outputs": 797370673, "inputs": {"n": 9, "k": 42}}, {"idx": 9, "outputs": 903959704, "inputs": {"n": 41, "k": 98}}]
question_info.extension: lua
question_info.entry_fn_name: painting_fence_algorithm
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__