6 kyu

Help the bookseller !

7,872 of 30,907g964

Description:

A bookseller has lots of books classified in 26 categories labeled A, B, C, ..., Z. Each book has a code of at least 3 characters. The 1st character of a code is a capital letter which defines the book category.

In the bookseller's stocklist each code is followed by a space and by a positive integer, which indicates the quantity of books of this code in stock.

Task

You will receive the bookseller's stocklist and a list of categories. Your task is to find the total number of books in the bookseller's stocklist, with the category codes in the list of categories. Note: the codes are in the same order in both lists.

Return the result as a string described in the example below, or as a list of pairs (Haskell/Clojure/Racket/Prolog).

If any of the input lists is empty, return an empty string, or an empty array/list (Clojure/Racket/Prolog).

Example

# the bookseller's stocklist:
"ABART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"

# list of categories: 
"A", "B", "C", "W"

# result:
"(A : 20) - (B : 114) - (C : 50) - (W : 0)"

Explanation:

  • category A: 20 books (ABART)
  • category B: 114 books = 25 (BKWRK) + 89 (BTSQZ)
  • category C: 50 books (CDXEF)
  • category W: 0 books
Fundamentals
Algorithms

More By Author:

Check out these other kata created by g964

Stats:

CreatedFeb 12, 2015
PublishedFeb 12, 2015
Warriors Trained96007
Total Skips25274
Total Code Submissions210732
Total Times Completed30907
Java Completions3988
Ruby Completions734
Python Completions7872
C# Completions1664
JavaScript Completions7049
Clojure Completions222
Haskell Completions330
CoffeeScript Completions20
C++ Completions1784
PHP Completions1197
C Completions500
TypeScript Completions1333
Swift Completions614
Crystal Completions21
R Completions126
Shell Completions116
OCaml Completions48
F# Completions73
Julia Completions48
Scala Completions209
Go Completions1252
Nim Completions20
Rust Completions771
Racket Completions27
Kotlin Completions878
Groovy Completions57
Dart Completions537
Pascal Completions16
Lua Completions111
Perl Completions29
Elm Completions8
D Completions6
Erlang Completions7
Prolog Completions8
Total Stars1376
% of votes with a positive feedback rating86% of 3467
Total "Very Satisfied" Votes2668
Total "Somewhat Satisfied" Votes646
Total "Not Satisfied" Votes153
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • ZozoFouchtra Avatar
  • bkaes Avatar
  • anter69 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • dfhwze Avatar
  • KayleighWasTaken Avatar
  • miggycoder Avatar
Ad