Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. theNum#TASK4
  2. import numpy as np
  3.  
  4. n = int(input())
  5.  
  6. a = np.array([range(n*n)])
  7. a = np.zeros([n, n], dtype = int)
  8.  
  9. diag = True            
  10. changedirection = False
  11.  
  12. theNum = 0
  13. i = 0
  14. j = 0
  15.  
  16. while theNum < n*n:
  17.     a[i,j] = theNum
  18.    
  19.     if diag:
  20.         j+=1
  21.         i-=1
  22.         if j == n:
  23.             j-=1            
  24.             i+=2              
  25.             changedirection = True
  26.         elif i < 0:
  27.             i+=1
  28.             changedirection = True
  29.            
  30.     if not diag:
  31.         j-=1
  32.         i+=1
  33.         if i == n:
  34.             i-=1            
  35.             j+=2              
  36.             changedirection = True
  37.         elif j < 0:
  38.             j+=1
  39.             changedirection = True
  40.            
  41.     if changedirection:
  42.          diag = not diag
  43.    
  44.     changedirection = False
  45.     theNum = theNum + 1
  46.  
  47. print(a)
  48.  
  49.  
  50.  
  51. #TASK6
  52.  
  53. keys = [0, 1, 2, 3, 4 , 5, 6, 7 ,8 ,9 , "A", "B" , "C", "D", "E", "F"]
  54.  
  55. def deep(ans, n, m):
  56.     if len(ans) == n:
  57.         print(ans)
  58.         ans = ''
  59.         return
  60.    
  61.     for i in range(m):
  62.         deep(ans+str(keys[i]),n, m)
  63.  
  64.  
  65. def back(n, m):
  66.     ans = ''
  67.     deep(ans, n, m)
  68.  
  69. back(int(input()), int(input()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement