Advertisement
enfiskutensykkel

Functional FizzBuzz

Jun 19th, 2019
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 1.06 KB | None | 0 0
  1. equals = $(if $(filter $1,$2),$1)
  2. slice = $(wordlist 2,$(words $1),$1)
  3. map = $(if $(call equals,$(words $2),0),$(strip $3),$(call map,$1,$(call slice,$2),$3 $(call $1,$(firstword $2),$(words $3))))
  4. replicate = $(if $(call equals,$(words $3),$1),$(strip $3),$(call replicate,$1,$2,$3 $2))
  5. range = $(if $(call equals,$(words $2),$1),$(strip $2),$(call range,$1,$2 $(words $2)))
  6.  
  7. repeat = $(if $(call equals,$(words $4),$1),$3,$(call repeat,$1,$2,$(call $2,$3),$4 $1))
  8. rotate = $(call slice,$1) $(firstword $1)
  9.  
  10. cycle = $(firstword $(call repeat,$1,rotate,$2))
  11. select = $(if $1,$1,$2)
  12. concat = $(if $(call equals,$1,_),,$1)$(if $(call equals,$2,_),,$2)
  13. add = $(words $(call replicate,$1,_) $(call replicate,$2,_))
  14. incr = $(call add,1,$1)
  15.  
  16. numbers := $(call map,incr,$(call range,100))
  17. fizz := $(call replicate,2,_) fizz
  18. buzz := $(call replicate,4,_) buzz
  19.  
  20. fizzbuzz = $(call select,$(call concat,$(call cycle,$2,$(fizz)),$(call cycle,$2,$(buzz))),$1)
  21. result := $(call map,fizzbuzz,$(numbers))
  22.  
  23. print = $(info $1)
  24.  
  25. .PHONY: all
  26. all: ; $(call map,print,$(result))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement