DEV Community

thecashewtrader
thecashewtrader

Posted on

3 1

A simple 3x+1 visualiser

TL;DR

What is 3x+1?

3x+1 is a simple math problem. You start by plotting a number, say x, on the graph. If x is even, you plot x/2, otherwise you plot 3x+1, stopping when x=1.
For example, the 3x+1 array for 3 would be:

[3, 10, 5, 16, 8, 4, 2, 1]

Features of the visualiser

The visualiser is still in it's early stages, with a lot of glue code and styling issues. The main features for now are:

  • Generate an interactive graph for any number.
  • Zoom, pan, and generally navigate the graph
  • Export said graph as an image

Demo

The website

The website

The image output

Image output

The tools used

  • Svelte - Frontend framework
  • Vite - Bundler
  • TailwindCSS + DaisyUI - UI library/framework
  • Chart.js - To plot the graph
  • Chart.js zoom plugin - To add interactivity
  • Hammer.js - Used under the hood by Chart.js zoom plugin for gesture recognition

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay