Skip to content

Instantly share code, notes, and snippets.

@thepushkarp
Last active April 18, 2021 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thepushkarp/b410d0bc9e34e9861e6c528810d19f76 to your computer and use it in GitHub Desktop.
Save thepushkarp/b410d0bc9e34e9861e6c528810d19f76 to your computer and use it in GitHub Desktop.
Tech Hunt 2021 Level 5 Hint
// Notice the pattern? 👀
#include <stdio.h>
int main() {
int k = 0, l = 0, m =5,n = 5, val = 1;
//
//
//
int a[m][n];
while (k < m && l < n) {
for (int i = k; i < m; i++)
a[i][l] = val++;
l++;
for (int i = l; i < n; i++)
a[m-1][i] = val++;
m--;
for (int i = m-1; i >= k; i--)
a[i][n-1] = val++;
n--;
for (int i = n-1; i >= l; i--)
a[k][i]= val++;
k++;
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++)
printf("%d\t", a[i][j]);
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment