Advertisement
xapu

Untitled

Jun 1st, 2017
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //rosette
  2.  
  3. function Problem2() {
  4.     let params = arguments[0]
  5.     let size = Number(params[0])
  6.     let sizeOfParamas = params[1].split(" ").length
  7.     let inputText = params.slice(size + 1)
  8.     let controlTab = CreateTablet(size)
  9.     let codedText = ReadCode(inputText)
  10.     let decriptedCode = DecriptCode(controlTab, codedText, sizeOfParamas, size)
  11.  
  12.     let result = ""
  13.  
  14.     for (let i = 0; i < decriptedCode.length; i++) {
  15.         for (let j = 0; j < decriptedCode[i].length; j++) {
  16.             if(decriptedCode[i][j]!==""){
  17.             result += decriptedCode[i][j]
  18.             }
  19.         }
  20.     }
  21.  
  22.     console.log(result)
  23.  
  24.     function DecriptCode(control, coded, sizeOfParamas, heightSize) {
  25.         let result = []
  26.         for (let i = 0; i < coded.length; i += heightSize) {
  27.             for (let j = 0; j < coded[i].length; j += sizeOfParamas) {
  28.                 if (result[i] == undefined) {
  29.                     result[i] = []
  30.                 }
  31.                    
  32.                
  33.                 for (let x = j; x < j+sizeOfParamas; x++) {
  34.                     //current cell
  35.                     if ( x < coded.length) {
  36.                         result[i][x] = FinalDecription(coded[i][x] + control[i%heightSize][x% sizeOfParamas])
  37.                     }
  38.                
  39.                 //extra down
  40.                 for (let z = i+1; z < i+heightSize; z++) {
  41.                     if ( z < coded.length && result[z]==undefined) {
  42.                         result[z] = []
  43.                     }
  44.                     if (z < coded.length) {
  45.                         result[z][x] = FinalDecription(coded[z][x] + control[(z) % heightSize][x % sizeOfParamas])
  46.                     }
  47.                 }}
  48.  
  49.  
  50.             }
  51.         }
  52.         function FinalDecription(secretChar) {
  53.             return secretChar % 27 + 64 == 64 ? " " : String.fromCharCode(secretChar % 27 + 64)
  54.         }
  55.  
  56.         return result
  57.     }
  58.  
  59.     function ReadCode(inputData) {
  60.         let result = []
  61.         for (let i = 0; i < inputData.length; i++) {
  62.             let tempLine = inputData[i].split(" ").map(x => Number(x))
  63.             for (let j = 0; j < tempLine.length; j++) {
  64.                 if (result[i] == undefined) {
  65.                     result[i] = []
  66.                 }
  67.                 result[i][j] = tempLine[j]
  68.             }
  69.         }
  70.         return result
  71.     }
  72.  
  73.     function CreateTablet(size) {
  74.         let controlTablet = []
  75.         let tempCounter = 1
  76.  
  77.         for (let i = 0; i < size; i++) {
  78.             if (controlTablet[i] == undefined) {
  79.                 controlTablet[i] = []
  80.             }
  81.             let tempLine = params[tempCounter].split(" ").map(x => Number(x))
  82.             tempCounter++
  83.             for (let j = 0; j < tempLine.length; j++) {
  84.                 controlTablet[i][j] = tempLine[j]
  85.             }
  86.         }
  87.         return controlTablet
  88.     }
  89. }
  90.  
  91. Problem2(['2',
  92.     '59 36',
  93.     '82 52',
  94.     '4 18 25 19 8',
  95.     '4 2 8 2 18',
  96.     '23 14 22 0 22',
  97.     '2 17 13 19 20',
  98.     '0 9 0 22 22'
  99.     ]
  100. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement