#I am having difficulty with this maybe I can discuss this problem with someone

174 messages · Page 1 of 1 (latest)

somber shuttleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

keen dove
#

rip

keen dove
#

welp

#

It appears no-one wants to help :(

dense anvil
#

!homework

mighty elkBOT
#
Not_Somebody
We Don't Do Your Homework

Welcome to Together C&C++! We won't do your homework for you, but we are happy to help you learn and point you in the right direction. We can help most if you have a specific question / have started writing the code.

(Please refer to our #rules, 5.)

keen dove
#

@dense anvil Im not asking for someone to do my homework lol

#

litterally read the title

#

maybe I can discuss this problem with someone

#

aka where do i start

dusky walrus
#

try breaking the problem into a smaller piece? Could you do it in just one dimension if it was an array instead of a matrix?

keen dove
#

chetco!!!!!!!!!!

#

my 2x hero

#

hi again

#

uhhh yes I think so

#

thats a good idea maybe I can do it in peices

dusky walrus
#

i just did the assignment so its really not that hard

#

i promise, it just looks like a lot

keen dove
#

wait it took u 9 minutes?

dusky walrus
#

its only about 30 lines of code including printing the result so trust me you got this

keen dove
#

ok lemme

#

try and work through it here

#

I gotta speed run this

#

like fr fr

dusky walrus
#

haha no take your time, just because I have dozen years experience in C

keen dove
#

... mostly because its the night before halloween and I am alone with no-one doing CSC and math

#

...troll despair

dusky walrus
#

try one dimension. I wil lgive you a hint if you like (use modulus operator)

keen dove
#

ohhh

dusky walrus
#
L = [6, 10, 17]
s = ""
for i in range(2):
    s += str(L["""??? what goes here???"""]) + " "
print(s[:-1])
#

one dimension example

keen dove
#

what on earth is that

dusky walrus
#

in python

keen dove
#

oh

#

ok

#

ima work in the middle now

#

wait

#

what

#

no what I did made no sense

#

deleted it all

#

Actually maybe I don't know how to do it in one dimention

#

the hardest thing im having

#

is have the same row repeat multiple times

dusky walrus
#

its similar to repeating the same elements multiple times in 1 dimension

#

its all about how you index the 2d array

#

imagine you have array like
double A[5] = {-4, 5, 3, 9, -2};

#

A[2] would give you 3

keen dove
#

right

dusky walrus
#

A[6] is out of bounds

keen dove
#

true

dusky walrus
#

in comes modulus operator

#

the expression x % 5 will always give you a result less than 5

#

so you are never out of bounds

#

and A[6 % 5] simplifies to A[1]

keen dove
#

coudlent u just loop through

#

each element of the array

#

and be like while its less than 5

dusky walrus
#

you could

#

but array B may be larger than A

keen dove
#

i think thats how im supposed to do it

#

oh

#

I see

#

sorta

dusky walrus
#

evaluate expression A[x % 5] for x between 0 to 10

#

and you wil see a repetition

#

it gives all elements of A then starts back at the beginning when x is out of bounds of A

#

and you could keep looping x as long as you want really

keen dove
#

ohhh thats cheeky

#

oh my goodness you big brain god

#

does this seem right

dusky walrus
#

i assumed first dimension is 'rows' of the matrix

#

you have n rows I believe, so you are on the right track but you did not use A yet

keen dove
#

oops hahaha

dusky walrus
#

you probably want i < somethingelse ?

#

because for me k is columns

keen dove
#

s!

#

oops

#

good catch

dusky walrus
#

but your online submission thing might prefer a different thing idk

keen dove
#

eh does not matter

#

prof does not look at the code i could use litterally anything

#

a computer checks it

dusky walrus
#

if you use wrong index your matrix will be transposed in memory

#

and computer will say wrong answer

keen dove
#

oh

#

holy crap

#

we are cooking now!!

#

one dimension is complete

dusky walrus
#

looking better but might be wrong still idk. if s is rows of B then what is correct between these two options:
B[row][column]
B[column][row]

keen dove
#

lemme pull up expected output

keen dove
#

and

dusky walrus
#

but if i write B[x] what did I index into, the row or column?

keen dove
#

row

#

i think

dusky walrus
#

then your code B[0][i] = A[0][i%n]; is using i to index the column?

dusky walrus
#

I think we can assume its B[row][col]

#

but its still ambiguous

keen dove
#

gotcha

#

i swapped it

dusky walrus
#

actually reading your assignment comments they say "if A is a 2 x 3 matrix" and then it shows 2 rows 3 columns

#

so yeah now it looks correct your last change

keen dove
#

alrighty

#

now for 2d

#

how would I approach this

dusky walrus
#

when I am stuck I like to take a guess

keen dove
#

Ima guess

#

that

#

I make another loop

dusky walrus
#

good guess

keen dove
#

ok

#

so since its rows

#

by collomns

#

my nested loop will be looping le columns

#

so then I do the same trick

#

that you did

dusky walrus
#

sounds good

keen dove
#

modulo hack

#

but colomns

#

wait a second

#

hmmm

#

wait a secondo

#

i dont know if this will work

#

cus im just

#

indexing [0] of the row and columns

dusky walrus
#

ok but you are close except

#

B[i][0] = A[i%n][0]; should be a red flag because we don't assign arrays to other arrays

#

which feels like what u intended?

keen dove
#

I have to assign B

#

to A

#

and then it prints out B

dusky walrus
#

you can do the whole function in like 3 lines of code not counting declarations and braces

keen dove
#

hmm

dusky walrus
#

sneaky delete for u just a hint

keen dove
#

I don't know whats wrong with mine tho

#

I know its wrong

#

I think I have to assign B to A there

#

in order to update the columns

dusky walrus
#

idk is it wrong? I feel like it is but I don't actually know lol

keen dove
#

it is wrong

dusky walrus
#

you are assigning only one element in that line of code each time you loop through i

#

so you should expect it to be wrong because you make a total of i + j assignments for a s x t matrix

#

or s + t assignments i think?

#

also you overwrite your assignments i believe

keen dove
#

how would I change it without overwring it

dusky walrus
#

if i = 0 you overwrite B[0][0] and then move into the loop and with j = 0 you instantly overwrite B[0][0] yet again

keen dove
#

ah right

dusky walrus
#

at no point are you indexing the columns, only the rows, you are still in one dimension

#

only ever indexing column 0

#

now whenever you index the columns you only do so on row zero

keen dove
#

maybe that should be

#

j

#

nvm it should not be j

#

*i was referencing B[j][j] = A[j][j%k] but that did not work

dusky walrus
#

I really want to give you another hint but I am shoehorning you into the 'correct' answer only because its very simple solution and the one they probably want you to find

keen dove
#

wait

#

maybe it should be i

#

I GOT IT

dusky walrus
#

funny thing I believe last time I helped you that you found the solution before me, I think you will find this

keen dove
#

i think

dusky walrus
#

correct but you did not need the outer loop assignment only the inner part

keen dove
#

oh

#

well

#

its there for good keeping if it works

dusky walrus
#

lol

keen dove
#

hoooooly

#

chetco

#

man

#

thank you

#

i might have time to take a shower and go outside tonight

dusky walrus
#

no problem easy homework is easy

#

alright have a good one

keen dove
#

!solved