Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //rosette
- function Problem2() {
- let params = arguments[0]
- let size = Number(params[0])
- let sizeOfParamas = params[1].split(" ").length
- let inputText = params.slice(size + 1)
- let controlTab = CreateTablet(size)
- let codedText = ReadCode(inputText)
- let decriptedCode = DecriptCode(controlTab, codedText, sizeOfParamas, size)
- let result = ""
- for (let i = 0; i < decriptedCode.length; i++) {
- for (let j = 0; j < decriptedCode[i].length; j++) {
- if(decriptedCode[i][j]!==""){
- result += decriptedCode[i][j]
- }
- }
- }
- console.log(result)
- function DecriptCode(control, coded, sizeOfParamas, heightSize) {
- let result = []
- for (let i = 0; i < coded.length; i += heightSize) {
- for (let j = 0; j < coded[i].length; j += sizeOfParamas) {
- if (result[i] == undefined) {
- result[i] = []
- }
- for (let x = j; x < j+sizeOfParamas; x++) {
- //current cell
- if ( x < coded.length) {
- result[i][x] = FinalDecription(coded[i][x] + control[i%heightSize][x% sizeOfParamas])
- }
- //extra down
- for (let z = i+1; z < i+heightSize; z++) {
- if ( z < coded.length && result[z]==undefined) {
- result[z] = []
- }
- if (z < coded.length) {
- result[z][x] = FinalDecription(coded[z][x] + control[(z) % heightSize][x % sizeOfParamas])
- }
- }}
- }
- }
- function FinalDecription(secretChar) {
- return secretChar % 27 + 64 == 64 ? " " : String.fromCharCode(secretChar % 27 + 64)
- }
- return result
- }
- function ReadCode(inputData) {
- let result = []
- for (let i = 0; i < inputData.length; i++) {
- let tempLine = inputData[i].split(" ").map(x => Number(x))
- for (let j = 0; j < tempLine.length; j++) {
- if (result[i] == undefined) {
- result[i] = []
- }
- result[i][j] = tempLine[j]
- }
- }
- return result
- }
- function CreateTablet(size) {
- let controlTablet = []
- let tempCounter = 1
- for (let i = 0; i < size; i++) {
- if (controlTablet[i] == undefined) {
- controlTablet[i] = []
- }
- let tempLine = params[tempCounter].split(" ").map(x => Number(x))
- tempCounter++
- for (let j = 0; j < tempLine.length; j++) {
- controlTablet[i][j] = tempLine[j]
- }
- }
- return controlTablet
- }
- }
- Problem2(['2',
- '59 36',
- '82 52',
- '4 18 25 19 8',
- '4 2 8 2 18',
- '23 14 22 0 22',
- '2 17 13 19 20',
- '0 9 0 22 22'
- ]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement