[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Daily programming challenge

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 32
Thread images: 3

File: varg-vikernes[1].jpg (114KB, 762x464px) Image search: [Google]
varg-vikernes[1].jpg
114KB, 762x464px
Let's see how many brainlets are on /g/ tonight

Task:
>Rotate outer matrix by one element clockwise/counter-clockwise

Rules:
>time complexity: O(n) or better
>constant space complexity (= creating another matrix is not allowed)

Example:
>original
2 1 8 7 4
3 9 0 2 6
8 1 4 3 9
0 1 3 8 1
7 5 5 6 2
>rotated clockwise
3 2 1 8 7
8 9 0 2 4
0 1 4 3 6
7 1 3 8 9
5 5 6 2 1

>OP solution (try it yourself first, Pajeet):
https://pastebin.com/YhDAyj7W
>>
>>61641750
Usually 4chan doesn't do someone's homework.
>>
>>61641750
I see nothing hard here.
>>
>>61641777
I have already done it and provided link to my solution. Learn to read, retard.
>>
Sorry bro I'm not going to do your comp sci 2 homework
>>
>"Let's see how many brainlets are on /g/"
>uses python
>>
>>61641795
>>61641828
>>61641891
Hello summer
>>
>>61641750
your solution is in linear time, but is not better than O(n) time. Its something like O(10n) time, but lets just pretend you meant linear time so that your solution fits the parameters.

Other than me being a dick just now, I doubt this can be done better than linear time and the most straightforward solution is something along the lines of the swap solution you provided.

If you remove the constant space complexity requirement, this could be made into real O(n) time by just reading into a new matrix.
>>
>>61641927
It can be done in leinear time.
>>
>>61641927
>O(10n)
This notation is literally never used. It doesn't matter if it is n, 2n, or 44n + 365, it is alway O(n)
>>
>>61641955
but can it be done better?

the solution already was a linear time solution it just wasnt O(n)
>>
>>61641968
then call it linear time
>>
>>61641972
No. It can not be improved. You need tomove every elements (except centre if there is one).

O(n) and O(100n) are exactly the same thing. I hope you understand why.
>>
>>61642011
im just pedant
>>
>>61641750
>If I post a bad solution 4chan will correct me and do my homework for me!
Really?
>>>/wsr/
>>
>>61642038
>im just pedant
No. You justfail to understand why big O notation was introduced,
>>
>>61642060
And why exactly is my solution bad, faggot? And who the fuck have uni in middle of summer
>>
>>61642011
>1 = 100
>your brain on CS
>>
>>61642038
>>61642143
I'm laughing so hard right now, this is the perfect example of /g/ in 2017. Not surprised that most threads are about consumerism, when you are failing CS 101.
>>
>>61642135
Do your own homework, cunt. Or ask /wsr/. I'm not gonna sit here and say why it's bad so you can fix it. Go learn and put forth effort.
>>
>>61642224
this is really poor attempt at trolling, sorry.
>>
File: corner.jpg (33KB, 358x400px) Image search: [Google]
corner.jpg
33KB, 358x400px
>>61642182
>nobody does your homework for you
>f-f-f fucking /g/ newfags! I b-b-bet youre the ones failing cs 101!
>>
File: 1497944988128.jpg (90KB, 500x355px) Image search: [Google]
1497944988128.jpg
90KB, 500x355px
>>61642258
Not as bad as your attempt to get people to do your homework for you.
>>
>>61642274
I was pointing out they fucking doesn't understand what a Big O notation is. Back to "watz da best gpu for gayming" threads
>>
>>61642224
I dunno, he has done the task, why would he ask anyone to do the done job?
>>
>>61641750
>Daily programming challenge
What was yesterday's challenge?
>>
>>61641993
O(n) literally means linear
>>
>>61641750
are you kidding me? even the most obvious solution is O(n).

>someone doesn't know what O(n) means
a function f is O(g(n)) if there exists a c > 0 such that f(n) < cg(n) for all n.
as an application, any function that is O(100n) is O(n).
>>
>>61641750
depending on how your matrix is stored, the solution can be done in O(1). but optimizing your data structure for such problems will leave it relatively useless for most other things.
>>
>>61643435
Any pb can be solved in O(1) with a gopd coding.
>>
>>61643503
okay, perform element-wise addition of two integer arrays (each of length n) in O(1).
>>
>>61641750

I'd just use a reverse iterating vector in C++ easy peasy
Thread posts: 32
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.