Intermediate Brainlet Test

Write a function in a programming language of your choice that does a diagonal sweep of 0's and a diagonal sweep of 1's or this crow stabs you!
e.g.

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

1 0 0 0 0
0 0 0 0 0
0 0 0 0 0

1 1 0 0 0
1 0 0 0 0
0 0 0 0 0

1 1 1 0 0
1 1 0 0 0
1 0 0 0 0

Attached: crowknife.jpg (529x416, 56K)

Other urls found in this thread:

pastebin.com/7eARZdsL
youtube.com/watch?v=rIX_6TBeph0
twitter.com/NSFWRedditImage

no

fn main() {
poo_init(5, 3);
}

fn poo_init(x: i32, y: i32) {
for i in 0..(x + y) {
for j in 0..y {
for k in 0..x {
print!("{}", if j + k < i { "1 " } else { "0 " })
}

println!();
}
println!();
}
}

Sorry this is wrong user, but I appreciate you trying it with Rust

I have no fucking clue what you expect me to do. Your explanation is severly lacking. Please elaborate.

If you want *exactly* what you posted replace x + y with y + 1, and print "e.g." first. Otherwise I don't know what the fuck you want.

brainlet detected

shit thread apologist detected

I was only pretending to be retarded desu
now that I read again and think about it, yeah, I've no idea what the OP wants

**ELABORATION**

Your array can be any size, I don't care. Just make it a 2D array.

Iterate over it, do a diagonal sweep of 0's then a sweep of 1's which in a better example would look like:
0 0 0 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 1 0 0 1 1 0 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1


Sorry, I realise my first example maybe threw you off and my explanation was rather lacking

Nevermore

def tri(ones: Int, len: Int) {
assert(len >= ones)
val res = for (i

Still doesn't make sense. If I first set everything to 0 and then to 1 why not just skip setting it to 0? Also what does it matter if it is done diagonally or not? Why a 2d array? What the fuck?

yeah, wtf do you mean with "a diagonal sweep of 0's then a sweep of 1's"

(cont'd)
Well, I certainly didn't see that one yet.
Updated:
def tri(ones: Int, len: Int) {
val res = for (i

-module(diag).
-export([sweep/2]).

sweep(Width, Height) ->
sweep(Width, Height, 0, Width + Height - 1).

sweep(Width, Height, N, N) ->
print(Width, Height, N);
sweep(Width, Height, N, Max) ->
print(Width, Height, N),
sweep(Width, Height, N + 1, Max).

print(Width, Height, N) ->
iterate(fun(X) ->
case X > Width of
true ->
repeat(fun() -> io:format("1 ") end, Width);
false ->
repeat(fun() -> io:format("1 ") end, X),
repeat(fun() -> io:format("0 ") end, Width - X)
end,
io:format("\n"),
case X =:= 0 of
true ->
0;
false ->
X - 1
end
end, N, Height),
io:format("\n").

iterate(_Fun, Input, 0) ->
Input;
iterate(Fun, Input, N) ->
iterate(Fun, Fun(Input), N - 1).

repeat(_Fun, 0) ->
ok;
repeat(Fun, N) ->
Fun(),
repeat(Fun, N - 1).

Attached: file.png (307x1000, 193K)

Not OP, but imagine making an LED sweep animation.

Now just generating all the shitty cubes
def tri(ones: Int, len: Int) = {
val res = for (i

oh, I finally understood what OP wanted

let sweep w h = [[[if x + y < n then '1' else '0' | x

Cool & pretty; I really like this one.

But I guess you scared the imperative coders away.

Your two posts are my favourite, good work user. I've always been a fan of scala but never took the time to learn it just with it not being what I use at work.

stabbed
enjoy being dead, faggot

Recursive floodfill algorithm starting from the "corner" in a 2D array. Not worth my time to do baby programming.

#include
#include
#include
void sweep(int x,int y);
void printMatrix(int x,int y,int a[x][y]);
int main(int argc, char *argv[]) {
srand(time(NULL));
sweep(5,5);
return 0;
}
void sweep(int x, int y){
int i,k;
int j=0;
int num=0;
int arr[x][y];
for(i=0;i

>srand(time(NULL));

Attached: 1508545835967.jpg (600x534, 147K)

Removed the useless libraries that I was using to fuck around.
#include

void sweep(int x,int y);
void printMatrix(int x,int y,int a[x][y]);

int main(int argc, char *argv[]) {
sweep(5,5);
return 0;
}
void sweep(int x, int y){
int i,k;
int j=0;
int num=0;
int arr[x][y];
for(i=0;i

"use strict";
function* makeSweep(width = 5, height = 5, step = 0) {
const result = [];
const limit = width + height;
let pointer = -1;
for (; step < limit; ++step) {
for (let i = 0; i < height; ++i) {
const left = step - i;
for (let j = 0; j < width; ++j) {
result[++pointer] = 48 + Number(j < left);
}
result[++pointer] = 10;
}
result.pop();
yield String.fromCharCode.apply(undefined, result);
pointer = -1;
}
}

for (const sweep of makeSweep()) {
console.log(sweep);
}

row length diag nth = [if ind + nth > (putStrLn . showBoard $ b)) $ sweep 3 5


Compacting for no apparent reason:
sweep n m = [ [ [if ind + x

The hardest part of this shit is figuring out what OP wants you to do

Also no, we're not doing your homework for you

test

Python makes everything easy desu
N = 6
M = 6

matrix = [[0]*N]*M

for step in range(M+N):
for i in range(M):
ones = min(N, max(0, step-i))
matrix[i] = [1]*ones + [0]*(N-ones)

#printing
for j in range(N):
print(matrix[i][j], end = " ")

print("")
print("")

Multi-threaded solution in javascript

pastebin.com/7eARZdsL

Attached: Untitled.png (1592x1165, 56K)

ruby ftw

def sweep(r, l)
(0..3).each do |i|
(0..r).each do |j|
x = (i + r-j)
print "1 "*(x) + "0 "*(l-x+r)
print "\n"
end
print "\n"
end
end

sweep(2, 4)

Illegible garbage

Cleanly readable
Also you have a typo
(0..l).each do |i|

void sweep(bool mat[MAX_SIZE][MAX_SIZE],int numLines,int numColumns)
{
for(int ln=0;ln

BIRDMIN NO

sorry,went full retard for a sec
Here's correct version
void sweep(bool mat[MAX_SIZE][MAX_SIZE],int numLines,int numColumns)
{
for(int ln=0;ln

which works just for the first half
You would have to add this at the end
for(int j=1;j=0 && auxCol

hey don't steal my code and put it in shit format you pajeet. You are also missing the other half

fixed with my autism
def sweep(r, l)
(0..l).each do |i|
(0..r).each do |j|
x = [i - j, 0].max
y = [j, l-x].max
print "1 "*x + "0 "*(y)
print "\n"
end
print "\n"
end
end

sweep(3, 5)

//Diagonal sweep
#include
#include
#include

int main(int argc, char **argv){
if(argc != 3)
return 0;

int x = atoi(argv[1]), y = atoi(argv[2]);

if(x = 0; j--)
for(i = 0; i < x; i++)
if(array[j][i] == '0'){
array[j][i] = '1';
break;
}
}
}

Attached: 1415171233163.jpg (315x404, 15K)

youtube.com/watch?v=rIX_6TBeph0
>quoth the raven: "waka waka waka"

Not better, but an alternative using .tabulate:
def pretty(xss: Array[Array[Int]]) = xss map {_ mkString " "} mkString "\n"

def rects(rs: Int, cs: Int) =
for(i if (r+c rects(2,3) map pretty mkString("\n\n")
res1: String =
0 0 0
0 0 0

1 0 0
0 0 0

1 1 0
1 0 0

1 1 1
1 1 0

1 1 1
1 1 1

>Quoth the raven, "Waka waka waka" : videos 19 Sep 2011
>19/11/11
>1-9/11-11
crows double-did one-nine-eleven-even

>worst possible approach
>ezpz
>pssht not worth my time
>it's totally not that I can't think of a much simpler solution that can be written in under 3 minutes
every thread

OP u suk at describing the requirements.
See A better arrangement of the requirements: do a southeast-bound diag sweep with 1s, then another one with 0s
Example with 2x3:
0 0 0 1 0 0 1 1 0 1 1 1 1 1 1
0 0 0 0 0 0 1 0 0 1 1 0 1 1 1

then
0 1 1 0 0 1 0 0 0 0 0 0
1 1 1 0 1 1 0 0 1 0 0 0

or even
0 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 0 0 0

Thanks! Don't worry, you'll get to it eventually. sbt and scala and so on are still getting better anyhow.

It's prettier code regardless. Nice.

By the by, have you tried the Ammonite REPL?
>prettier code
Cheers m8, let me remedy that:
An alternative that actually generates the sequence in , trimmed to loop properly:
def pretty(xss: Array[Array[Int]]) =
xss map {_ mkString " "} mkString "\n"

def loop(rs: Int, cs: Int) = {
def sweep(ul: Int, lr: Int) =
for (diag if (r+c < diag) ul else lr}

sweep(1, 0) ++ sweep(0, 1).tail.init
}

> loop(2,3) map pretty mkString "\n\n"
res0: String =
0 0 0
0 0 0

1 0 0
0 0 0

1 1 0
1 0 0

1 1 1
1 1 0

1 1 1
1 1 1

0 1 1
1 1 1

0 0 1
0 1 1

0 0 0
0 0 1

>.tail.init
Can be removed if we just s/until/to/, but then the 'sweep' name would be misleading.

Nvm that's retarded, we'd need until rs+cs-1.
Looks like it's half past off-by-one'o'clock up in this bitch.

Print("00000")
Print("00000")
Print("00000")
Print ()
Print("10000")
Print ("00000")
Print("00000")
Etc