GithubHelp home page GithubHelp logo

brpapa / recursion-tree-visualizer Goto Github PK

View Code? Open in Web Editor NEW
443.0 7.0 62.0 1.84 MB

🌳 Input the source code of any recursive function in javascript, python or golang and visualize its recursion tree

Home Page: https://recursion.vercel.app

License: MIT License

HTML 0.69% TypeScript 95.14% JavaScript 0.81% CSS 2.98% Dockerfile 0.38%
recursion-tree recursion-visualizer recursion visualization algorithms lambda serverless aws-lambda

recursion-tree-visualizer's People

Contributors

brpapa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

recursion-tree-visualizer's Issues

Feature request: Support Java

Can we please get this amazing project to accept solutions in Java?

Nonetheless, great work on the project buddy.

Gives recursion tree empty error

def fn(low: int, high: int):
    def dfs(i, num, output):
        if num >= low and num <= high:
            output.append(num)
        if num > high or i > 9:
            return
        dfs(i+1, num*10+i, output)
    
    output = []
    for i in range(1, 10):
        dfs(i, 0, output)
    
    output.sort()
    return output

result = fn(100, 300)
print(result)

Incomplete drawing display

Here is my code to solve "Unique Binary Search Trees" problem.

def fn(lo,hi):
    if lo >= hi:
        return 1
    tot = 0
    for i in range(lo, hi+1):
        tot += fn(lo,i-1)*fn(i+1,hi)
    return tot

When I call fn(1, 4), it can draw picture(< maximun recursion), it can't draw the recursion tree completely no matter how I zoom in the broswer.
image

So I think you can set a button to download this entire picture quickly. By the way, I always get the screenshot to get a picture.
😋

Incorrect return values

Writing this in a hurry, so cannot be sure, but I noticed that return values were wrong for the following program. (I'll update as soon as I can). Find a screenshot and the code below.

(Great tool, btw!)

function fn(n) {
  Array.prototype.size = function() {
    return this.length
  }
  
  ans = new Array(n)
  
  if(n == 0)
    return ans;
  if(n==1)
    return [0,1];
      
  ans = fn(n-1);
  for(let i = ans.size()-1;i >= 0; i--)
    ans.push(ans[i] | 1<<n-1);
  return ans;
}

image

Giving indentation error for properly indented code

this is the code,its properly indented but still giving indentation error.

def fn(p):
    n = len(p)
    return f(0, 1, p, n)

def f(i, buy, p, n):
    if i == n:
        return 0
    if buy:
        buy_price = -p[i] + f(i + 1, 0, p, n)
        not_buy = f(i + 1, 1, p, n)
        return max(buy_price, not_buy)
    else:
        sell_price = p[i] + f(i + 1, 1, p, n)
        not_sell = f(i + 1, 0, p, n)
        return max(sell_price, not_sell)

Interpreting strings as variables in python

For example, when I use a string "boy", I get an error boy not defined.
It is interpreting "boy" as a variable instead of a string.
But if I escape the quotes \"boy\" , it works.

Run code successfully on local machine, But get an error online

Here is my code:

coins = [25,20,10,5,1]
def fn(i, m):
    if 0 == m:
        return 0
    if len(coins) == i:
        return 0x3f3f3f3f
    ans = 0x3f3f3f3f
    for k in range(m // coins[i] + 1):
        ans = min(ans, fn(i+1,m-coins[i]*k) + k)
    return ans

print(fn(0,40))

It can run in jupyterlab
image

I copy this code to https://recursion.vercel.app/, but it get an error: Your code outputs the following TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
image

I don't know why it can not run online. I hope you can help me. Thanks!😊

Internal server error and Can't install projects locally

Hi, when I run my custom function, I met some troubles.

def fn(idx,step):
    if idx < 0 or idx >= arrLen:
        return 0
    if 0 == step:
        return 0 == idx
    return (fn(idx - 1, step - 1) + fn(idx + 1, step - 1) + fn(idx, step - 1)) % 1000000007

And global variable is steps = 3, arrLen = 2

  1. https://recursion.vercel.app/
    image

  2. install this project by Nodejs

PS D:\NodeJS\recursion-tree-visualizer-master\packages\web> npm install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> [email protected] postinstall D:\NodeJS\recursion-tree-visualizer-master\packages\web\node_modules\babel-runtime\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> [email protected] postinstall D:\NodeJS\recursion-tree-visualizer-master\packages\web\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> [email protected] postinstall D:\NodeJS\recursion-tree-visualizer-master\packages\web\node_modules\core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"


> [email protected] postinstall D:\NodeJS\recursion-tree-visualizer-master\packages\web\node_modules\ejs
> node ./postinstall.js

Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 2032 packages from 799 contributors and audited 2036 packages in 204.781s

137 packages are looking for funding
  run `npm fund` for details

found 167 moderate severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

PS D:\NodeJS\recursion-tree-visualizer-master\packages\web> npm audit fix
npm WARN @babel/[email protected] requires a peer of @babel/core@^7.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 1 package from 1 contributor, removed 1 package and updated 3 packages in 12.588s

137 packages are looking for funding
  run `npm fund` for details

fixed 88 of 167 vulnerabilities in 2036 scanned packages
  79 vulnerabilities required manual review and could not be updated
PS D:\NodeJS\recursion-tree-visualizer-master\packages\web> npm run start

> [email protected] start D:\NodeJS\recursion-tree-visualizer-master\packages\web
> react-scripts start


There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "eslint": "^7.11.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of eslint was detected higher up in the tree:

  D:\NodeJS\recursion-tree-visualizer-master\packages\web\node_modules\eslint (version: 6.8.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if D:\NodeJS\recursion-tree-visualizer-master\packages\web\node_modules\eslint is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls eslint in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed eslint.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web-client@1.0.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the web-client@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\007\AppData\Roaming\npm-cache\_logs\2021-05-13T02_54_00_621Z-debug.log

I don't quite understand how to solve this problem, I hope to get your help, thank you. 😥

Online: Error,Offline:Ok

Old Bug:#8 (comment)

Here is my code:

from functools import lru_cache

matchsticks =[5,5,5,5,16,4,4,4,4,4,3,3,3,3,4]
width=18
@lru_cache(None)
def fn(state,currEdgeWidth):
  if state == (1 << len(matchsticks)) - 1:
    return True
  ans = False
  for i in range(len(matchsticks)):
    if not ((state >> i) & 1) and matchsticks[i] + currEdgeWidth <= width:
      ans |= fn(state | (1 << i), (currEdgeWidth + matchsticks[i]) % width)
  return ans
print(fn(0, 0))

It run ok on my local python

C:\Users\007>python
Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

But I get an Error in https://recursion.vercel.app/,
1654048204(1)

Incorrect param values

When I try to visualize a recursive call with a custom function, I get the error “Incorrect param values”.

image

I guess I am doing something wrong. Any help would be appreciated.

Great work on this, by the way. Congrats are in order!

not allowing default params

image

for some reason it won't allow default params and I saw another issue where it stated that it was fixed already.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.