QUICK

QUICK

WRITE A FUNCTION IN YOUR FAVORITE PROGRAMMING LANGUAGE THAT ROTATES A SQUARE OF INTEGERS TO THE RIGHT BY 90 DEGREES
[ OPTIONAL BONUS POINTS IF IN-PLACE ]

OR THIS BIRD IS GOING TO STAB YOU

Attached: progbird.jpg (412x430, 39K)

Other urls found in this thread:

jsfiddle.net/g4wqqmeb/4/
jsfiddle.net/swwmnam9/
jsfiddle.net/jbshsq0e/59/
jsfiddle.net/s1173mvb/
pastebin.com/YNjfTggd
twitter.com/NSFWRedditGif

REFERENCE SOLUTION

#include
#include

#define SIZE 4

void rotate(int square[SIZE][SIZE]) {
for(int y = 0; y < SIZE / 2; y++) {
int h = SIZE - y - 1;

for(int x = y; x < h; x++) {
int w = SIZE - x - 1;

int temp = square[y][x];
square[y][x] = square[w][y];
square[w][y] = square[h][w];
square[h][w] = square[x][h];
square[x][h] = temp;
}
}
}

void print(int square[SIZE][SIZE]) {
for(int h = 0; h < SIZE; h++) {
for(int w = 0; w < SIZE; w++) {
printf("%2d ", square[h][w]);
}
printf("\n");
}
}

int main() {
int square[SIZE][SIZE] = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 14, 15, 16 }
};

rotate(&square);
print(&square);

return EXIT_SUCCESS;
}

No.

DON'T MAKE ME COME OVER THERE

Attached: angrybird.jpg (600x475, 42K)

BEGONE FOUL BEAST

Attached: CompelsYou.jpg (300x339, 74K)

up

hole in 46
map((r,i,o)=>r.map((c,j)=>o[o.length-1-j][i]))

i like your puzzles mr berb. they distract me from my shitty life.

Attached: berber.png (361x239, 10K)

Now do it in place.

Attached: 1470962715881.jpg (269x211, 8K)

bump

you want me to write a function with side effects?

what do I look like, a poo in loo?

Good guy user. Stick to your guns.

Fuck it keeps spinning please don't stab me
jsfiddle.net/g4wqqmeb/4/

Attached: spin.gif (93x100, 36K)

10/10

Attached: spiderman.jpg (801x534, 32K)

FASTER
jsfiddle.net/swwmnam9/

function (hire_chinese_slave_to_do_my_work_for_me);

>BIRD
>not BIRB
Fucking newfags those days, ffs!

hole in 19
a.reverse.transpose

as in
@ val a = Array.tabulate(4,4){_*4+_+11}
a: Array[Array[Int]] = Array(
Array(11, 12, 13, 14),
Array(15, 16, 17, 18),
Array(19, 20, 21, 22),
Array(23, 24, 25, 26)
)

@ a.reverse.transpose
res1: Array[Array[Int]] = Array(
Array(23, 19, 15, 11),
Array(24, 20, 16, 12),
Array(25, 21, 17, 13),
Array(26, 22, 18, 14)
)

>inb4 designated golfing language

Best laugh I've had all week, well done user.s

hm, better demo data actually:
@ val a = Array.tabulate(4,4){_*10+_+11}
a: Array[Array[Int]] = Array(
Array(11, 12, 13, 14),
Array(21, 22, 23, 24),
Array(31, 32, 33, 34),
Array(41, 42, 43, 44)
)

@ a.reverse.transpose
res1: Array[Array[Int]] = Array(
Array(41, 31, 21, 11),
Array(42, 32, 22, 12),
Array(43, 33, 23, 13),
Array(44, 34, 24, 14)
)

>>inb4 designated golfing language

well, I'd consider it cheating.

but if you wanna be like that.

hole in 5, matlab
rot90

>matlab
sry m8 that's too designated compared to glorious general purpose scala

>glorious general purpose scala

but can it run on Jow Forums? :^)

sure, on the JVM running all the rest of the glow-in-the-darkware

how long would it be if you didn't use reverse/transpose?

fuck you op

how long would it be if you didn't use rot90?

@(A) fliplr(A')

how long would it be if you didn't use reverse/transpose?

see

I feel bad. I ruined this thread. I turned it into a cockmeasuring contest and no one can keep up.

I'd love to see some innovative implementations from anons, ranging from poo in loo to terry quality. But I guess that is no longer happening.

are you the hole in 46 guy or the matfag guy?
cuz 46 guy's at the root of it all and should be appropriately lynched imho

both :/

sorry mr birb

next time I'll await at least 60 replies.

Attached: ;-;.jpg (500x514, 36K)

jsfiddle.net/jbshsq0e/59/

>sorry mr birb
nah no worries, I stoked the fire by falling for the bait
>next time I'll await at least 60 replies.
not a bad idea, although not always necessary
Cniles and other "muh performance" fags are dropping the ball here, they should've shat on the golf solutions

integers, son.

somebody tell me how to do this in place. thought you'd always need at least one additional place for swapping

Huh?

just rotate every 4-cell set - you always need an extra var for swapping, or xor faggotry

Sin(yaw) * cos(yaw)

xor faggotry doesn't work if you have a matrix with an odd order, unless the middle value is 0

Attached: 1516904676986s.jpg (125x79, 2K)

huh?
what are you on about

but I think birbman just means without allocating a new matrix.

take a 3x3 matrix
1 2 3
4 5 6
7 8 9


5^5 = ?

of course, the obvious solution would be to just leave it.

BUT THAT IS UNELEGANT

>the obvious solution would be to just leave it
answered your own question m8

jsfiddle.net/s1173mvb/

5 xor 5 equals 0
0 xor 5 equals 5
5 xor 0 equals 5
What's wrong?

It'll be covered by your loop limits.
In general, you do a 4-cell rot90 for each row starting at: 0,0; 1,1; 2,2; 3,3 and so on, until (inclusive) the middle row.
For each row, you do that for all but the last column in the sub-square (0,0 - 4-square; 1,1 - 3-square and so on).
This naturally excludes the central element if you're in an odd-N square.

...

every condition is a cancer

>my code magically works without conditional execution
the absolute state of g

It's like sin(X) * cos(z) or something isn't it?

non-working code gets you disqualified
post shit we can copy, paste, compile and get the correct result, or you're getting stabbed

>5 xor 5 equals 0
>0 xor 5
here is your error
>equals 5
>5 xor 0 equals 5
>What's wrong?

I can't really shit on your algorithm because the time complexity is the same as any other, and it'll work, but it's extremely contrived.

>I can't really shit on your algorithm
but yes you can, it's right there at the end of yo sentence:
>but it's extremely contrived.
describe a less contrived one and throw in some dpt-tier insults and you've got a stew goin'
cmon bby, I need this
*rubs nipples*

I'm talking about if, switch, etc. obviously.

nobody cares about the low level shit. the point is that every branch is a potential for untested mistakes

nigga you don't need explicit conditionals either, just think a second before writing the code ffs

ezpz

Attached: Screen Shot 2018-04-21 at 11.46.34.png (615x488, 80K)

reigning unreadability champion of the thread right here
have you considered applying in the ioccc?

my brain works too fast when solving problems to write pretty code, besides who cares about maintainability when you're writing a code and forget program? this isn't for production

Well it's not even a correct solution. It's a coordinate rotation rather than an array rotation.

>describe a less contrived one
split it into two functions, transpose and flip :|

that would be SOLID

>dpt-tier
GLYCINE BOIIIIIIIIII

disclaimer: I don't visit dpt.

>my brain works too fast when solving problems to write pretty code
t. 1GB/s garbage

A = A'

>do twice the work
>somehow better
ah, an Atom developer spotted in his native habitat!

[code=c]
void rotateSquare90(int square);
[/code]

the way you use for, it might as well be an explicit condition.

unless you speak of other things

>int square
>passing the argument by copy, not by reference, and returning void
Is this some sort of magical C thing I'm not aware of?

>the way you use for, it might as well be an explicit condition.
wow

how often are you gonna need transpose
how often are you gonna need flip
how often are you gonna need rot90

only once
and it's 99% of the program's runtime
better make it twice as slow (ignoring the slowdown due to shit locality)

rip in peaces

what language is this

Elixir

thanks because now i know that i should never have to learn elixir because its garbage

four chins style
a = [[1,2,3], [4,5,6],[7,8,9]];
a.map(
(r,i,o)=>r.map(
(e,j)=>setTimeout(
_=> o[j][o.length-1-i] = e,o.length*o.length
)
)
);

elixir is garbage to you just like shit is a delicacy to a fly

I'm sorry, did somebody say this is about math?
pastebin.com/YNjfTggd

Attached: matrix_transform.png (400x152, 7K)

4/10
the extra rotation of the whole square can be avoided when you rotate every row on its own

Fowl beast

if it doesn't work, use pic related.

Attached: curados-de-espantos-02.jpg (480x360, 28K)

Now this, this is how you ask Jow Forums to do your homework.

bump

TOPZOZ

Attached: 1512072511226.jpg (765x685, 195K)

I don't understand the question. how do you rotate a number 90 degrees?

that's not what the chicken asked

top kek

>reference solution

s/chinese/indian

nevermore

Don't die on me

Hole in 4:
NB. |. = reverse, |: = transpose
i.4 4
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
|:|. i.4 4
12 8 4 0
13 9 5 1
14 10 6 2
15 11 7 3

#define b dodeshit(a)

hole in 1:
b

>Quoth the raven, "Waka waka waka"

NB. begins a comment.

yeah right
and #define defines a comment too

There's a mathematical way to rotate a matrix, which I forgot, but could look up. I'd use that, op.