npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

turnip-price

v0.1.1

Published

[中文版](docs/README_zh-CN.md)

Downloads

2

Readme

Turnip Price

中文版

A Rust (and WebAssembly) implementation of the calculator turnip price of Animal Crossing: New Horizon. This project can't be done without @_Ninji's C++ code and his disassembly work. You can try the demo online.

🚀 Getting Started

You can install this package via npm or Yarn.

npm i turnip-price
# or
yarn add turnip-price

Also, make sure that the target environment has access to WebAssembly. Then you can write a calculation function like this.

function calculate(whatPattern, seed) {
  const turnip = wasm.calculate(whatPattern, seed);
  return {
    buyingPrice: trunip.buying_price,
    sellingPrices: new Int32Array(memory.buffer, turnip.selling_prices(), 12),
  };
}

Explanation of the sellingPrices array:

  • The 0th, 2nd, 4th, 6th, 8th, 10th elements indicate the morning price from Tuesday to Saturday respectively;
  • The 1st, 3rd, 5th, 7th, 9th, 11th elements indicate the afternoon price from Tuesday to Saturday respectively.

🤔 FAQ

📈 Can I Predict the Price on My Island by This?

No, yet. Because you don't have the random seed, which is not exposed to regular players. By the way, if you have the seed, the calculator won't work the first time you buy the turnips, according to @_Ninji's reply.

🕸️🦀️ Why do you use WebAssembly?

Because the code involves the practice of reinterpreting unsigned 32-bit integer as 32-bit IEEE 754 floating number. Though I can do that in JavaScript, using WebAssembly maybe more stable.

🔍 Discovery

📚 Can I Enumerate All Combinations?

There are total 4 × 2 ^ 32 = 17,179,869,184 combinations. On my machine, it tooks 4 minutes to enumerate all combinations (in 4 threads).

However, it's cost to save all combinations to your disk. For each combination, the algorithm will product 13 prices. Each price is a positive integer from 0 to around 660, which can be represented by an unsigned 10-bit integer. Therefore, the uncompressed data size is 2,233,382,993,920 bits, i.e. 260 GBs.

💰 How Much Is The Highest Price?

I tried all combinations of patterns (0, 1, 2, 3) and seeds (from 0 to UINT32_MAX). Here is the results.

  • In pattern 0 (i.e. what_pattern is set to 0), the highest price is 660 when seed = 326.
  • In pattern 1 (i.e. what_pattern is set to 1), the highest price is 660 when seed = 326.
  • In pattern 2 (i.e. what_pattern is set to 2), the highest price is 660 when seed = 326.
  • In pattern 3 (i.e. what_pattern is set to 3), the highest price is 660 when seed = 9772.

In conclusion, the highest price of turnips is 660.

📈 Weekly Highest Price Distribution

You may want to acknowledge the distribtion. I also did this.

The Histogram of Weekly Highest Price of Turnips