General FizzBuzz: Difference between revisions
Content added Content deleted
(Added Elixir) |
m (→{{header|AWK}}: Input) |
||
Line 47: | Line 47: | ||
This is a two-step solution: |
This is a two-step solution: |
||
* First, we get the parameters, and |
* First, we get the parameters, and |
||
** generate a file with the list of numbers (writing |
** generate a file with the list of numbers (writing directly to that file) |
||
** generate a custom awk-program for that special case (redirecting standard-output) |
** generate a custom awk-program for that special case (redirecting standard-output) |
||
* the custom program is run, and does the actual work to output the desired result |
* the custom program is run, and does the actual work to output the desired result |
||
<lang bash> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
;Input: |
|||
<pre> |
|||
105 |
|||
3 Fizz |
|||
5 Buzz |
|||
7 Baxx |
|||
⚫ | |||
⚫ | |||
<!-- (!!) Note: the sandbox at ideone.com does not allow output to files --> |
|||
<lang awk># usage: awk -f fizzbuzzGen.awk > fizzbuzzCustom.awk |
<lang awk># usage: awk -f fizzbuzzGen.awk > fizzbuzzCustom.awk |
||
# |
# |
||
Line 61: | Line 69: | ||
q2 = "\"" |
q2 = "\"" |
||
fN = "numbers.txt" |
fN = "numbers.txt" |
||
#fP = "fizzbuzzCustom.awk" |
|||
} |
} |
||
NF==1 { print "#", $1, "Numbers:" |
NF==1 { print "#", $1, "Numbers:" |
||
for( i=1; i <= $1; i++ ) |
for( i=1; i <= $1; i++ ) |
||
print( i ) > fN |
print( i ) > fN # (!!) |
||
print "# Custom program:" |
print "# Custom program:" |
||
print "BEGIN {print "q2"# CustomFizzBuzz:"q2"}" |
print "BEGIN {print " q2 "# CustomFizzBuzz:" q2 "}" |
||
next |
next |
||
} |
} |