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

jt-packer-utility

v1.0.25

Published

Package Challenge

Downloads

37

Readme

Package Challenge

Introduction

You want to send your friend a package with different things. Each thing you put inside the package has such parameters as index number, weight and cost. The package has a weight limit. Your goal is to determine which things to put into the package so that the total weight is less than or equal to the package limit and the total cost is as large as possible. You would prefer to send a package which weighs less in case there is more than one package with the same price.

Input sample

Your API should accept as its first argument a path to a filename. The input file contains several lines. Each line is one test case. Each line contains the weight that the package can take (before the colon) and the list of items you need to choose. Each item is enclosed in parentheses where the 1st number is a item’s index number, the 2nd is its weight and the 3rd is its cost. E.g.

81 : (1,53.38,€45) (2,88.62,€98) (3,78.48,€3) (4,72.30,€76) (5,30.18,€9) (6,46.34,€48)
8 : (1,15.3,€34)
75 : (1,85.31,€29) (2,14.55,€74) (3,3.98,€16) (4,26.24,€55) (5,63.69,€52) (6,76.25,€75) (7,60.02,€74) (8,93.18,€35) (9,89.95,€78)
56 : (1,90.72,€13) (2,33.80,€40) (3,43.15,€10) (4,37.97,€16) (5,46.81,€36) (6,48.77,€79) (7,81.80,€45) (8,19.36,€79) (9,6.76,€64)

Output sample

For each set of items that you put into a package provide a new row in the output string (items’ index numbers are separated by comma). E.g.

4
-
2,7
8,9

Constraints

  1. Max weight that a package can take is ≤ 100
  2. There might be up to 15 items you need to choose from
  3. Max weight and cost of an item is ≤ 100
  4. You should implement a class Packer with a static method named pack.
  5. This method accepts a file path to a test file as a string. The test file will be in UTF-8 format. The pack method returns the solution as a string.
  6. Your method should throw an error named PackingError where relevant, if any constraints are not met. Therefore your signature in pseudocode should look like:
class Packer {
  async pack(filePath: string): Promise<string> {
    // ...
  }
}
  1. Signatures of Packer class, pack() method and PackingError are already provided, please do not change them.

Usage

Install NPM package: npm install jt-packer-utility

Import and Use: import Packer from 'jt-packer-utility';

const packingSolution = await Packer.pack(filePath); // filePath is an absolute/relative file path