Color of the cars [closed] - algorithm

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Could you give me a hint on how to solve this problem?
How can I find out whether most cars have the same color if the only function I can use is to check whether two cars have the same color?

With equality, you can first build equivalence classes and then count the largest one.

You can create a "list" where the color of the car is the key value and it counts how many cars of that color you have and stores a car of that color.
It goes something like this:
you will have a struct of with this fields:
struct color
car *car_with_color = NULL
int count = 0
so you go to the first car store it's color and add 1:
color[1].car_with_color=&cars[1];
color[1].count=1;
then for the next car you do:
if (cars[2].color == color[1].car_with_color->color)
color[1].count++;
else
color[2].car_with_color=&cars[2];
color[2].count=1;
and so on:
for (i=1;i<=NUM_OF_CARS;i++){
j=1;
while (color[j].car_with_color != NULL){
if (cars[i].color == color[j].car_with_color->color){
color[i].count++;
break;
}else
j++;
}
if (color[j].car_with_color == NULL){
color[j].car_with_color=&cars[i];
color[j].count=1;
}
}
it's written in a C like pseudo-code.

Related

Looking for help to use script in Sheets to avoid having equations in multiple sheets [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Using example Test Sheet
Looking to use script in Sheets to;
Read active sheet name [e.g. RED]
Look in SUMMARY Sheet and find matching sheet name in column A and read associated integer [e.g. R1C2]
Multiply that by RED R1C1 and display result in RED R1C2
I would want to be able to do this for all values in column 1 in RED, GREEN & BLUE sheets, either on opening or by using a button
Any pointers would be greatly appreciated!
Your question has been voted down as you haven't shown any research or posted any of your own code. I'll help you out as I too am new here ;-). It is good that you have broken your request down, the next step would have been to start writing code... The following code will do what you have requested, bar it on running on open or by using a button. My advice to getting started with Apps Script would be to read through the reference documents and samples so that you understand fully what the code does.
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();
var activeSheetName = activeSheet.getSheetName();
var activeSheetData = activeSheet.getDataRange().getValues();
var summarySheet = ss.getSheetByName("SUMMARY");
var summarySheetData = summarySheet.getDataRange().getValues();
for (var i = 0; i < summarySheetData.length; i++) {
if (summarySheetData[i][0] == activeSheetName) {
valueToMultiplyBy = summarySheetData[i][1];
}
}
for (var j = 0; j < activeSheetData.length; j++) {
var resultOfMultiplication = valueToMultiplyBy * activeSheetData[j][0];
activeSheet.getRange(j+1,2).setValue(resultOfMultiplication);
}
}

Trying to make a button that apears after achieving a certain score [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Im making a Single View Application in Swift and I want to create a button that appears on the screen once you get a certain score. How can I do this?
Also, if possible, I want the button to disappear after you click it.
The solution by which i solved it is timer ...
var score : Int = 0
override func viewDidLoad() {
super.viewDidLoad()
btnTest.hidden = true
_ = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector:Selector("printer"), userInfo: nil, repeats: true)
}
func printer() {
score++
if score == 10 {
btnTest.hidden = false
}
}
you can set your updation on score variable.
there is also some other ways to do it
hope you found your solution
Thank you.
Welcome to SO. This site isn't a good fit for "teach me the basics of programming" type questions like this.
I'll give you something to start from though. Created a score property in your view controller. Implement a didSet method on your score property. Put the logic to show your button in your didSet method.
Create a button and in your code hide it in viewDidLoad then reveal it whenever your score reaches the amount you wish. But it is correct that you should be providing code and not asking just how to do something. Stack overflow is for debugging errors not asking how code should be written.

Filter (no display) layers in GeoExt.LegendPanel using LIKE operator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
This works to avoid Basemap layers such as Google Maps and overlays such as WMS to appear in the GeoExt Legend Panel:
var legendPanel = new GeoExt.LegendPanel({
border: false,
filter: function(record){
if(!(record.getLayer().isBaseLayer) && (record.getLayer() instanceof OpenLayers.Layer.WMS)){
return true;
}
} });
The problem is that I need to filter (ie. no display) layers with names having "beam" in their names, I tried with no success this:
return record.getLayer().displayInLayerSwitcher == false && record.getLayer().name == '%beam%';
return record.getLayer().displayInLayerSwitcher == false &&
record.get("layer").name.indexOf("%beam%") == -1;
return record.get("layer").name.indexOf("%beam%") == -1;
Any hints are welcomed,
Just remove the "%". Use
return record.getLayer().name.indexOf("beam") == -1;
instead of
return record.getLayer().name.indexOf("%beam%") == -1;

Transferring some parts of image [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to transfer some part of my image to another matrix with this code:
p1 = zeros(512,512,3);
p1(1:128, 1:128, 1:3) = image(1:128, 129:256, 1:3);
And when this code did not work I tried with 3 for loop
and after that I tried to transfer R G B layers separately:
p1(1:128, 1:128, 1) = image(1:128, 129:256, 1);
But none of these codes work. Could anyone tell me what to do?
In Matlab you can always assign one matrix to another with the same size. For example:
A = ones (4,2,3,4,5);
B = zeros(4,2,3,4,5);
A = B
will run with no errors.
It is possible that the type of the image you are using is uint8 (8-bit unsigned integer), while zeros creates a double matrix. This will result in improper behavior of operations or built-in functions, if you do not cast (change the type of) your matrices properly. Use whos to check the type of your image:
whos image
Try to cast the zeros to uint8:
p1 = uint8(zeros(512,512,3));
...
Here is an example:
image = imread('peppers.png');
partail_im = uint8(zeros(size(image)));
partail_im(1:128,1:128,:) = image(1:128,129:256,:);
imshow(partail_im);
Note: It's better not to use image as the name of any variable since it's name of a built-in function image.

Combine Thumbnails to One Large Image with RMagick [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
What's the shortest way to combine say 20 256x256 thumbnails into a single large image of 4 rows by 5 columns using RMagick?
Assuming all the images are in the current directory and named from 1.jpg to n.jpg and row * col = n.
include Magick
row = NUM_ROWS
col = NUM_COLS
ilg = ImageList.new
1.upto(col) {|x| il = ImageList.new
1.upto(row) {|y| il.push(Image.read((y + (x-1)*col).to_s + ".jpg").first)}
ilg.push(il.append(false))}
ilg.append(true).write("out.jpg")

Resources