We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
-- Add to a list behaving like a set of valuesadd_set::Int->[Int]->[Int]add_sety[]=[y]add_sety(t:ts)|y==t=t:ts|otherwise=t:(add_setyts)-- Add (x, y) to the list of values [(x, [y])] giving the possible ys for a given xadd_value::Int->Int->[(Int,[Int])]->[(Int,[Int])]add_valuexy[]=[(x,[y])]add_valuexy((x0,ys):ts)|x==x0=(x0,(add_setyys)):ts|otherwise=(x0,ys):(add_valuexyts)-- Build the set of values [(xs, [ys])] from a function definitionbuild_values::[(Int,Int)]->[(Int,[Int])]build_values[]=[]build_values((x,y):ts)=add_valuexy(build_valuests)-- Checks whether the function is valid, i.e. each x matches to a unique yvalid::[(Int,Int)]->Boolvalidf=all((<=1).length.snd)$build_valuesf
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Functions or Not?
You are viewing a single comment's thread. Return to all comments →