How to resolve the algorithm McNuggets problem step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm McNuggets problem step by step in the AWK programming language
Table of Contents
Problem Statement
Calculate (from 0 up to a limit of 100) the largest non-McNuggets number (a number n which cannot be expressed with 6x + 9y + 20z = n where x, y and z are natural numbers).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm McNuggets problem step by step in the AWK programming language
Source code in the awk programming language
# syntax: GAWK -f MCNUGGETS_PROBLEM.AWK
# converted from Go
BEGIN {
limit = 100
for (a=0; a<=limit; a+=6) {
for (b=a; b<=limit; b+=9) {
for (c=b; c<=limit; c+=20) {
arr[c] = 1
}
}
}
for (i=limit; i>=0; i--) {
if (!arr[i]+0) {
printf("%d\n",i)
break
}
}
exit(0)
}
You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the Plain English programming language
You may also check:How to resolve the algorithm Look-and-say sequence step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the FunL programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the BCPL programming language