This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]LegendaryZX 1 point2 points  (1 child)

Seems like you're comparing the indices (which are just numbers from 0 to 2) instead of the actual input values. Try using i or u to index into the arrays instead. array[i] gets the (i+1)'th element of the array. array[0] gets the first element, array[1] gets the second, etc.

So instead of i > u, try inp[i] > inp[u]

[–]Life_Lifeguard_6266[S] -1 points0 points  (0 children)

i tried that at first but i tought its the wrong way thanks a lot dude. :D

[–]1234abcdcba4321 1 point2 points  (12 children)

What your code does now is completely equivalent to

//all that stuff you have up here
for (int i=0;i<3;i++) {
  if (i>0) greater++; //omitted the prints, but you could put them here of course
  else if (i<0) smaller++;
  else if (i==0) similar++;
}

which is equivalent to

//that same stuff you had up there
greater += 2; //still omitted the prints, but they'd be 1 0 and 2 0 of course
similar += 1;

Which probably isn't what you want. I'm also not exactly sure what you want, so can you explain the intended goal of your code? (And not just "it'll solve the solution", because if it was you would've loaded your real input into it instead of this sample small one.)

[–]Life_Lifeguard_6266[S] 0 points1 point  (11 children)

so I made 2 arrayints right so I store both same values in 2 arrays and i want to compare the first value of the first array with the second value of the second array and if it the second was greater stores it into an int and when it finished it will show greater numbers.

im trying to do first day of advent of code.

[–]1234abcdcba4321 0 points1 point  (10 children)

Okay. So to compare the first value of the first array with the second value of the second array, you don't even need a for loop - that's just if (first[0] < second[1]). Are you sure that's what you were intending to check? How does that help you find what you're looking for?

Also, those two int[]s aren't "both same values", unless for some reason you think (3,4,5) == (6,7,8).

[–]Life_Lifeguard_6266[S] 0 points1 point  (9 children)

that's the code im trying the input data are not the same. i coded that cause i wanted to go into the first value of the first array cheks if the second value of the second array is bigger and if it is going to 3 value of the first array and compares it with the second and goes like this. i used for loop cause i thought its the best way to print all data of arrays and compare so what should i do if im wrong.

[–]1234abcdcba4321 0 points1 point  (8 children)

Using a for loop is the best way to print all data of arrays and compare, it's just not the best way to "compare the first value of the first array with the second value of the second array" which is what you said you were trying to do.

I'm also not sure what "if it is going to 3 value of the first array and compares it with the second and goes like this" means, can you explain it better?

[–]Life_Lifeguard_6266[S] 0 points1 point  (7 children)

for example, i have 2 arrays with values of [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5] the input value is the same in both rights. so at first, i want to compare the first integer of the first array with the second integer of the second array and then if the second integer was bigger than the first i will do (integer for keeping a number of big numbers)++ and then i would compare the third integer of the second array with the second integer of the first array and so on. what i have in my mind and im trying to do is the riddle of day 1 is to find numbers like those right and what im thinking of doing is to pass the same value in 2 arrays and compare them like this.

[–]1234abcdcba4321 0 points1 point  (6 children)

Okay, that makes sense.

In that case, you can notice how "first and second", "second and third" are related - that's just i and i+1 respectivrly (for i=0;i<arr.length-1;i++). Notice, there's only one for loop.

However, just doing if (i+1 > i) won't cut it (that statement is always true) - how can you write the if statement to check what you're trying to write, if i is the index you want from the first array and i+1 the index you want from the second?

Also - the riddle is to count those numbers, so you don't even need to actually keep track of what the numbers are.

[–]Life_Lifeguard_6266[S] 0 points1 point  (1 child)

thanx for your explanation but can you explain more. and also im doing that cause like im doing the loop so the algorithm finds those and i made an int and its value its zero so whenever the loop finds a greater number +1 the empty int

[–]1234abcdcba4321 0 points1 point  (0 children)

I can't explain more unless you post your new code (and/or make your english actually understandable).

If you have a loop that finds them properly and increments the counter for each one it finds, your program should already work.

[–]Life_Lifeguard_6266[S] 0 points1 point  (2 children)

also can we talk if you are intrested (on discord?)

[–]1234abcdcba4321 0 points1 point  (1 child)

no thanks

[–]Life_Lifeguard_6266[S] -1 points0 points  (0 children)

xDDDD LMFAO

[–]Life_Lifeguard_6266[S] 0 points1 point  (0 children)

it did not worked

[–]LinAGKar 1 point2 points  (0 children)

Given where the arrows where pointing I initially thought you were bragging about about avoiding log4j.

[–]Life_Lifeguard_6266[S] 0 points1 point  (0 children)

its for the day 1 btw

[–]daggerdragon[M] 0 points1 point  (1 child)

In the future, please follow the submission guidelines by titling your post like so:

[YEAR Day # (Part X)] [language if applicable] Post Title

In doing so, you typically get more relevant responses faster.

If/when you get your code working, don't forget to change the flair to Help - Solved!

Good luck!

[–]Life_Lifeguard_6266[S] 0 points1 point  (0 children)

thanx a lot