Golden Choice Computer Science 6 Javascript help please!

Hello. I don’t even know where to start in this level. Can someone please explain the logic of the program to me so that I can possible have a shot at this? Thanks a lot. @AnSeDra @Alexander_Hollowell

Sorry, but I can not help you because I am gone at countryside and I will not stay for long in this zone with signal, so I will ask @dedreous and @Deadpool198 to help you. Sorry if I disappointed you!

Andrei

Thanks Ansedra for at least getting other to come to my rescue @dedreous

1 Like

Well, not sure we can come to the rescue, but we might be able to assist. Most of us have not even seen the ‘scholastic’ versions of CoCo, only what’s available to the general public.

However, if you post your code (or even just the starting comments), properly formatted as per this article, [Essentials] How To Post/Format Your Code Correctly, we might be able to give some guidance.

Ok Thanks here is my code. @dedreous

// You must collect the required amount of gold.
// The gate keeper will tell you how much you need.
// Always move in the direction of the exit.
// For each row you can take only one coin.
// Choose only one from the nearest coins in the next row.

// Distance between rows and coins.
var distanceX = 4;
var distanceY = 6;
var zeroPoint = {x: 14, y: 14};
var coinLines = 10;

function makeGoldMap(coins) {
    var template = [];
    for (var i = 0; i < coinLines; i++) {
        template[i] = [];
        for (var j = 0; j < 2 * coinLines - 1; j++) {
            template[i][j] = 0;
        }
    }
    for (var c = 0; c < coins.length; c++) {
        var row = Math.floor((coins[c].pos.y - zeroPoint.y) / distanceY);
        var col = Math.floor((coins[c].pos.x - zeroPoint.x) / distanceX);
        template[row][col] = coins[c].value;
    }
    return template;
}

// Prepare the gold map. It looks like:
// [[1, 0, 9, 0, 4],
//  [0, 1, 0, 9, 0],
//  [8, 0, 2, 0, 9]]
var goldMap = makeGoldMap(hero.findItems());

// Find your path.
var highestSum = 0;

var reqLen = goldMap.length * goldMap.length;

for (var x = 0; x < goldMap.length; x++) {
    var sum = 0;
    for (var j = 0; j < goldMap.length; j++) {
        var nestedList = goldMap[j];
        for (var i = 0; i < nestedList.length; i++) {
            var element = nestedList[x];
            sum += element;
            break;
        }
        if (sum > highestSum) {
            highestSum = sum;
        }
    }
}



Everything from “Find your path” downwards is code that i have written. It gives the highest sum of values of the same index from the different nested lists but I don’t know how to do the rest from here.

This is actually a campaign level from the Glacier campaign…teachers are able to select such, if they fit with their plan.

Unfortunately, JS is not my best coding language…only been playing with it since around Feb. Hopefully, one of our JS guru’s will be able to pipe in and assist.

For what it’s worth, your syntax looks good, and your logic appears solid. It seems you just need to follow the same path used to derive ‘highestSum’.

Ok.

  1. Do u know any JS gurus?
  2. I forgot to say that it only goes through one index value (0) and not the several others that are supposed to follow.

Thank you so much for what you’ve been able to do for me today. I really appreciate it :slight_smile:
for those who follow, i’m going to update my code

// You must collect the required amount of gold.
// The gate keeper will tell you how much you need.
// Always move in the direction of the exit.
// For each row you can take only one coin.
// Choose only one from the nearest coins in the next row.

// Distance between rows and coins.
var distanceX = 4;
var distanceY = 6;
var zeroPoint = {x: 14, y: 14};
var coinLines = 10;

function makeGoldMap(coins) {
    var template = [];
    for (var i = 0; i < coinLines; i++) {
        template[i] = [];
        for (var j = 0; j < 2 * coinLines - 1; j++) {
            template[i][j] = 0;
        }
    }
    for (var c = 0; c < coins.length; c++) {
        var row = Math.floor((coins[c].pos.y - zeroPoint.y) / distanceY);
        var col = Math.floor((coins[c].pos.x - zeroPoint.x) / distanceX);
        template[row][col] = coins[c].value;
    }
    return template;
}

// Prepare the gold map. It looks like:
// [[1, 0, 9, 0, 4],
//  [0, 1, 0, 9, 0],
//  [8, 0, 2, 0, 9]]
var goldMap = makeGoldMap(hero.findItems());

// Find your path.
var highestSum = 0;
var magicIndex = 21;


var reqLen = goldMap.length * goldMap.length;

for (var x = 0; x < goldMap.length; x++) {
    var sum = 0;
    for (var j = 0; j < goldMap.length; j++) {
        var nestedList = goldMap[j];
        for (var i = 0; i < nestedList.length; i++) {
            var element = nestedList[x];
            sum += element;
            break;
        }
        if (sum > highestSum) {
            highestSum = sum;
            magicIndex = element;
        }
    }
    hero.say(highestSum);
}
hero.say(magicIndex);


@Alexander_Hollowell @A_Woo @Archion @Chaboi_3000 @Gamestack @AlyTomji @no_u @Johnny_Fuentes-McClu @Deadpool198

1 Like

You are welcome!..sorry I can’t help more. I’d rather not drop names, as the individual(s) may not be available, or in a position to assist. Instead, trust that they will see this topic, read it and will respond if able. (There are many members with wicked skills in both JS and/or PY who might respond…maybe not today, maybe not for a couple of days, but eventually.)

1 Like

Actually don’t worry about it. I’ve found it after some hard work. :slight_smile:

3 Likes