Advertisement
enfiskutensykkel

Improved Make FizzBuzz

Jun 20th, 2019
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 0.93 KB | None | 0 0
  1. ### Operators
  2. eq = $(filter $1,$2)
  3. slice = $(wordlist 2,$(words $1),$1)
  4. repl = $(if $(call eq,$(words $4),$1),$3,$(call repl,$1,$2,$3 $2,$(words $4) $4))
  5. map = $(if $2,$(call map,$1,$(call slice,$2),$3,$4 $(call $1,$(firstword $2),$3,$4)),$4)
  6. rotate = $(call slice,$1) $(firstword $1)
  7. zip3 = $(if $2,$(call zip3,$1,$(call slice,$2),$(call rotate,$3),$(call rotate,$4),$5 $(call $1,$(firstword $2),$(firstword $3),$(firstword $4))),$5)
  8. inc = $(words $(call repl,$1,_) _)
  9.  
  10. ### Program body
  11. count = $(words $3)
  12. cycle = $(call slice,$(call repl,$1,_)) $2
  13.  
  14. fizz := $(call cycle,3,fizz)
  15. buzz := $(call cycle,5,buzz)
  16. numbers := $(call map,inc,$(call map,count,$(call repl,100,_)))
  17.  
  18. select = $(if $1,$1,$2)
  19. fizzbuzz = $(call select,$(if $(call eq,$2,_),,$2)$(if $(call eq,$3,_),,$3),$1)
  20.  
  21. result := $(call zip3,fizzbuzz,$(numbers),$(fizz),$(buzz))
  22. println = $(info $1)
  23.  
  24. ### Targets
  25. .PHONY: all
  26. all: ; $(call map,println,$(result))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement