# My challenge to everyone on this forum

 Lazar Bulic · January 24, 2015 The task is simple:Users inserts an whole number N. Print a square  matrix using this pattern. Example is give for N = 4 Let the games begin

## Replies

- page 1

 Kevin Faust · February 9, 2015 I will try the first one but I don't understand the pattern in the second one. Nishant Kumar Thakur · February 9, 2015 Solution in python 2.7:-``from __future__ import print_functiondef printMatrix(inputList):    for rowItem in inputList:        for colItem in rowItem:            print(colItem, end=' ')        print(" ")def generateEmptyMatrix(N):    outputMatrix = []    for i in range(N):        rowList = []        for j in range(N):            rowList.append(0)        outputMatrix.append(rowList)    return outputMatrix                    def generateMatrix(N):    outPutMatrix = generateEmptyMatrix(N)    dir = 0    val = 1        #0 - West to East    #1 - North to South    #2 - East to West    #3 - South to North    j=0    i=0    while(outPutMatrix[i][j] == 0):        outPutMatrix[i][j] = val        val = val + 1        if dir == 0:            if j+1 < N: # next elem is within matrix                if outPutMatrix[i][j+1] == 0: #if next elem is zero                    j = j+1                else:                    dir = 1                    i = i+1            else:                dir = 1                i = i+1        elif dir == 1:            if i+1 < N: #next elem is within matrix                if outPutMatrix[i+1][j] == 0:                    i = i+1                else:                    dir = 2                    j = j-1            else:                dir = 2                j = j-1        elif dir == 2:            if j-1 >= 0 :                if outPutMatrix[i][j-1] == 0:                    j = j-1                else:                    dir = 3                    i = i-1            else:                dir = 3                i = i-1        elif dir == 3:            if i-1 >= 0 :                if outPutMatrix[i-1][j] == 0:                    i = i-1                else:                    dir = 0                    j = j+1            else:                dir = 0                j = j+1            return outPutMatrix            if __name__ == '__main__':    printMatrix(generateMatrix(5))`` Lazar Bulic · January 26, 2015 Nobody, oh come on people  You didn't even bother to try. Maybe start with something easier. Try this one:User inputs whole number n. Form square matrix nxn that follows this patter. Following example is given for N=5 Lazar Bulic · February 9, 2015 Yes  Luka Lopotar you can just post the code here but this forum teds to mess up some character ([*i*] [*b*] ....) so its much better to paste theme at other site like http://pastebin.com/ Bernhard Riemann Georg Friedrich · July 6, 2015 Looks like a Pascal's triangle, problem solved ,I also stumbled across that while watching the table video on C. Lazar Bulic · January 27, 2015 I have solved all of these but I saw people asking for more challenges on this forum so I though why not give some. But it looks like nobody is taking my matrix seriously J show · February 8, 2015 Yea i dont even know how to make a matrix in c yet. i'm still pretty new to it Lazar Bulic · February 8, 2015 Matrix is a multidimensional array. That should kick start your search  There are many simpler matrices that you can practice on. The first 1 I gave is really hard and the second one isn't quite simple if you just started. I can give you a simpler examples if you want. Lazar Bulic · February 9, 2015 Kevin that is the point of the second one. As soon as you figure out the pattern programming it  will be easy While on the other had the first patter is easy but programming it is a little bit harder. Luka Lopotar · February 9, 2015 Ok, I'm done with second one, still need to figure out the pattern for first one xD.  I assume I just post the code here? (Sorry, I'm new on this forum)
• 1
• 2

## C

129,719 followers
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}