Skip to content

Instantly share code, notes, and snippets.

@taboularasa
Last active May 4, 2018 19:53
Show Gist options
  • Save taboularasa/d64db4280924f18236b99c37abe8c8a6 to your computer and use it in GitHub Desktop.
Save taboularasa/d64db4280924f18236b99c37abe8c8a6 to your computer and use it in GitHub Desktop.
# Although our analytics team produces a styling algorithm
# it can't always capture everything a customer has requested.
# For example, a customer might write in their note to the stylist
# "Please no pink!!!". The algorithm can't always tell that,
# so it might suggest pink clothes for the customer.
#
# Suppose the stylist has the ability to manually filter out
# attributes the customer wants to avoid. What we'd like
# you to do is, given a list of items, and a list of
# attributes to avoid, produce a filtered list of items.
#
# Here is what an item looks like:
Item = Struct.new(:id,
:color,
:secondary_color,
:pattern,
:type,
:fit)
# The possible values for color, pattern, etc. don't really matter. You can
# assume they are a consistent normal list and not a bunch of free-form text.
#
# Now, suppose the stylist has the ability to indicate any number of
# "avoids", and that the stylist can further indicate two levels
# of avoidance:
#
# * total
# * partial
#
# We'd like you to take a list of items, filter out all items for "total"
# avoids, and for items with "partial" avoids, sort those to the end of the list.
# Note that a color avoid applies to both color and secondary_color.
colors = %w(red green blue purple silver)
patterns = %w(solid polkadots checks herringbone)
types = %w(pants dress skirt shoes bracelet)
fits = %w(slim normal loose)
items = 10_000.times.map { |i|
Item.new(i,
colors.sample,
colors.sample,
patterns.sample,
types.sample,
fits.sample)
}
avoids = [
[ :color , "red" , :total ] ,
[ :color , "purple" , :partial ] ,
[ :type , "skirt" , :total ] ,
[ :fit , "slim" , :partial ] ,
]
def filter_and_sort_items(items,avoids)
end
filtered_items = filter_and_sort_items(items,avoids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment