Skip to content

Instantly share code, notes, and snippets.

@Zaijo
Created February 2, 2018 11:58
Show Gist options
  • Save Zaijo/0d8d195d226373dbb7786b1fa6ca9af2 to your computer and use it in GitHub Desktop.
Save Zaijo/0d8d195d226373dbb7786b1fa6ca9af2 to your computer and use it in GitHub Desktop.
Compute bank note count
«0»def main:
«4»inputAmount = 12345
«2»values = [500, 200, 100, 50, 20, 10, 5, 2, 1]
«26»mappingFunction = «28»computeSentenceForValue inputAmount values
«29»computedForAll = values . each mappingFunction
None
«6»def computeSentenceForValue inputAmount values value:
«14»filteringPredicate = item:
«15»item > value
«10»sortedValues = values . sort
«12»filteredValues = sortedValues . filter filteringPredicate
«16»reversedValues = filteredValues . reverse
«19»residuum = reversedValues . fold inputAmount nextResiduum
«25»occurencesOfValueInResiduum = residuum./ value
«20»residuum
occurencesOfValueInResiduum
«21»def nextResiduum originalResiduum bankNoteValue:
«22»occurences = originalResiduum / bankNoteValue
«23»covered = occurences * bankNoteValue
«24»originalResiduum - covered
### META {"metas":[{"marker":4,"meta":{"_displayResult":false,"_selectedVisualizer":["base: json","base/json/json.html"],"_position":{"fromPosition":{"_vector2_y":0,"_vector2_x":0}}}},{"marker":2,"meta":{"_displayResult":false,"_selectedVisualizer":["base: json","base/json/json.html"],"_position":{"fromPosition":{"_vector2_y":176,"_vector2_x":0}}}},{"marker":26,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":0,"_vector2_x":192}}}},{"marker":29,"meta":{"_displayResult":true,"_selectedVisualizer":["base: json","base/json/json.html"],"_position":{"fromPosition":{"_vector2_y":112,"_vector2_x":320}}}},{"marker":22,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":-48,"_vector2_x":80}}}},{"marker":23,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":32,"_vector2_x":176}}}},{"marker":24,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":-112,"_vector2_x":288}}}},{"marker":14,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":144,"_vector2_x":112}}}},{"marker":15,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":0,"_vector2_x":0}}}},{"marker":10,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":48,"_vector2_x":0}}}},{"marker":12,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":48,"_vector2_x":176}}}},{"marker":16,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":48,"_vector2_x":352}}}},{"marker":19,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":-128,"_vector2_x":464}}}},{"marker":25,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":272,"_vector2_x":544}}}},{"marker":20,"meta":{"_displayResult":false,"_selectedVisualizer":null,"_position":{"fromPosition":{"_vector2_y":0,"_vector2_x":704}}}}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment