Skip to content

Instantly share code, notes, and snippets.

@kirkins
Created October 29, 2018 17:02
Show Gist options
  • Save kirkins/00cf1acb7f6c6a845694af98f2c08c58 to your computer and use it in GitHub Desktop.
Save kirkins/00cf1acb7f6c6a845694af98f2c08c58 to your computer and use it in GitHub Desktop.
fizz buzz in a makefile, found online
range = $(if $(filter $1,$(lastword $3)),$3,$(call range,$1,$2,$3 $(words $3)))
make_range = $(foreach i,$(call range,$1),$(call range,$2))
equal = $(if $(filter-out $1,$2),,$1)
limit := 101
numbers := $(wordlist 2,$(limit),$(call range,$(limit)))
threes := $(wordlist 2,$(limit),$(call make_range,$(limit),2))
fives := $(wordlist 2,$(limit),$(call make_range,$(limit),4))
fizzbuzz := $(foreach v,$(numbers),\
$(if $(and $(call equal,0,$(word $(v),$(threes))),$(call equal,0,$(word $(v),$(fives)))),FizzBuzz,\
$(if $(call equal,0,$(word $(v),$(threes))),Fizz,\
$(if $(call equal,0,$(word $(v),$(fives))),Buzz,$(v)))))
.PHONY: all
all: ; $(info $(fizzbuzz))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment