Retired

Numerical Solution of Initial-Value Problems (retired)

Description
Loading description...
Numerical Analysis
Algorithms
  • Please sign in or sign up to leave a comment.
  • Unnamed Avatar

    What about this?

  • Unnamed Avatar

    The reference solution times out sometimes, for example, with this input from the random tests: [4, 4, 1, -5], [0, 0.2], 0.0.

  • dolamroth Avatar

    Function name two_oldest_ages in initial solution doesn't match the expected init_val_problem

  • dolamroth Avatar

    Several suggestions:

    1. Let first array in input be [a, b, c, d]. Then, you should include static tests with corner cases d + b/a == 0, because it produces differential equation of other form.
    2. Since you are not enforcing any numerical method, it's quite unclear what to do. Euler's method? Runge-Kutta method? It's actually simplier to go with analytical solution.
    3. Rounding floats is a bad idea. It's better to use test.approx_equals or whatever it's called.
    • rge123 Avatar

      I agree. There is also already a kata on Euler's method. Maybe enforce a more efficient algorithm (and defo make it non-analytical)?

    • dolamroth Avatar

      I would suggest to make kata with differential equation, that does not have analytical solution (i.e. riccati system) and enforce large difference between y(0) and y(T). Furthermore, as Unnamed suggested, you should disable some Python modules, that allow user to cheat the kata.

    • Boniaszewski Avatar

      Now I've found the kata that concerns the Euler's method. I've been planning to create the whole series about solving systems of differential equations and I wanted to start off with something easy. Maybe I will transform the task into the system of two equations or, as rge123 suggested, I will enforce improved Euler's method.

      Answering dolamroth suggestions:

      1. I don't quite follow, I need to think this through
      2. I will change the task to be more specific

      Now I am aware that I should disable some functions but I can not figure it out. How to block a function? I know it may be a silly question but I've been trying to find this out and no success.

    • dolamroth Avatar

      This comment has been hidden.

    • dolamroth Avatar

      About forbidding modules: Here is old code from one of my katas, it would give you the general idea. You need to include this code in Preloaded section. (note, that test is import codewars_test as test)

      import random
      
      toForbid  = ['importlib', '_frozen_importlib', 'os', 'sys', 'builtins',
                   '_frozen_importlib', '_frozen_importlib_external', '_imp',
                   'gc', 'json', 'requests', 'subprocess']
      
      def module_forbidder(*forbid):   
          from functools import wraps
          import re, sys
          original      = __import__
          checker       = 'extract.hlsidhgfoisHDE67678EFG2Sdyftsrtstfh'
          modulesToKeep = ('random',)
          keptModules   = tuple(__import__(name) for name in modulesToKeep)
          toForbid.extend(modulesToKeep)
          for name in modulesToKeep + ('sys',):
              del sys.modules[name]
          @wraps(__import__)
          def DontDoThis(*a,**k):
              if a[0] == checker: return keptModules
              for name in forbid:
                  if re.search(r'\b{}\b'.format(name), a[0]):
                      test.fail("Don't import {} or a module that depends on it.".format(name))
                      raise Exception("Don't do this...")
              try:    return original(*a,**k)
              except: pass         
          return DontDoThis
      array_to_delete = tuple(('functools', 'itertools', 'operator', '_operator'))
      toForbid.extend(array_to_delete)
      __builtins__['__import__'] = module_forbidder(*toForbid)
      
      for func in 'eval exec open'.split():  __builtins__[func] = None
      
      del module_forbidder, toForbid, func