Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

"blind" programming [challenge]

Name: Anonymous 2015-04-29 23:33

Here's a stupid idea.

You know things like "print this pattern:

*
***
*****
*******
*********


can be done wiht any dumb challenges like this..

try to solve it by writing the program into this thread - NO TESTING! Then try it out.

Name: Anonymous 2015-04-29 23:40

Using Perl.
my $STAR = "*";

print $STAR x 3;
print $STAR x 5;
print $STAR x 7;
print $STAR x 9;

Name: Anonymous 2015-04-29 23:42

Ok, that was pretty shitty because I forgot newlines.
use feature "say";
my $STAR = "*";

say $STAR;
say $STAR x 3;
say $STAR x 5;
say $STAR x 7;
say $STAR x 9;

Name: Anonymous 2015-04-29 23:50

>>3
I also screwed up using m instead of code, which strips initial spaces... I meant the challenge:
*
***
*****
*******
*********

but people can attempt either. Or an X pattern, or a box.

Name: Anonymous 2015-04-29 23:52

let ca s = [ r a b c | a <- (' ' : s) | b <- s | c <- s ++ " " ] ; r '*' _ = '*' ; r _ '*' _ = '*' ; r _ _ '*' = '*' ; r _ _ _ = ' ' in mapM putStrLn . take 5 . iterate ca $ " * "

Name: Anonymous 2015-04-29 23:54

darn it, fixed version after testing:

let ca s = [ r a b c | a <- (' ' : s) | b <- s | c <- tail s ++ " " ] ; r '*' _ _ = '*' ; r _ '*' _ = '*' ; r _ _ '*' = '*' ; r _ _ _ = ' ' in mapM putStrLn . take 5 . iterate ca $ " * "

Name: Anonymous 2015-04-30 0:10

This is in C,

#include <stdio.h>
#include <string.h>

// N >= 1
#define N 5

void f(char *s, size_t n)
{
size_t i;
for(i = 0; i < n; i++)
if(s[i] == '*') s[i-1] = s[i+1] = '*';
}

int main() {
char s[2*N] = {0};
memset(s, ' ', sizeof s - 1);
s[sizeof s / 2 - 1] = '*';
for(puts(s); *s != '*'; puts(s))
f(s);
return 0;
}

Name: Anonymous 2015-04-30 0:27

Range
method(n,
1 to(n) asList select(isOdd) foreach(m,
(" " repeated((n / 2) - (m / 2) floor - 1)
.. "*" repeated(m)) println))

Name: Anonymous 2015-04-30 0:46

C, the X version
#include <stdio.h>

// N => 1
#define N 5

int main() {
int i, j;
char s[64], out[2*N] = {0};
for(i = 0; i < 2*N - 1; i++) {
for(j = 0; j < 2; j++) {
sprintf(s, "%%.%ds%%c", i + 2*j*(N - i - 1));
sprintf(out, s, '*');
}
puts(out);
}
return 0;
}

Name: Anonymous 2015-04-30 0:47

Ruby

10.times { |n| puts "*"*n if (n%2).odd? }

Name: Anonymous 2015-04-30 0:53

>>9
This one failed horribly, lol

Name: Anonymous 2015-04-30 2:07

STAR = 5

for x in range(STAR):
print "*" * (x+1)

Name: Anonymous 2015-04-30 2:11

import BoringChallengesThatPlagueProgrammingCommunitiesLikeAIDSPlaguesFags

main = printStars 5

Name: Anonymous 2015-04-30 2:11

STAR = 5

for x in range(1, STAR*2, 2):
print "*" * x

Name: Anonymous 2015-04-30 3:00

cute thread.

Name: Who am I quoting? 2015-04-30 4:56

#include <stdio.h>

void
pyramid(int width, int level)
{
int stars = (2 * level) + 1;
int spaces = (width - stars) / 2;

if(stars > width)
return;
while(spaces--)
puts(' ');
while(stars--)
puts('*');
puts('\n');
pyramid(width, level + 1);
}

int
main(void)
{
pyramid(9, 0);
return 0;
}

Name: Who am I quoting? 2015-04-30 4:58

>>16
,s/puts/putchar/

$ ./triangle
*
***
*****
*******
*********

Name: Anonymous 2015-04-30 7:24

>>17
Are you sure that's the output? I ran it on my local machine and I got:

$ ./triangle
8==============================D

Name: Anonymous 2015-04-30 12:23

def star_printer(row_count):
for row in range(row_count):
print('*', '**' * row, sep='')

Name: Cudder !cXCudderUE 2015-04-30 13:22

#include <stdio.h>

int main() {
int i, j;
for(i=0;i<5;i++) {
for(j=0;j<2*i+1;j++)
putchar('*');
putchar('\n');
}
return 0;
}

Name: Cudder !cXCudderUE 2015-04-30 13:25

>>7,9,16
Are you deliberately going for a verbose and roundabout way of doing it? I've seen far better C from /prog/ before...

Name: Anonymous 2015-04-30 16:44

: stars 0 ?do [char] * emit loop ;
: triangle
dup 0
do cr dup i - spaces i 2* 1+ stars
loop
drop ;

Name: Anonymous 2015-04-30 18:48

>>22
dope

Name: Anonymous 2015-04-30 19:08

print "%d%s" % ('*'*x, '\n') for x in xrange(1,10,2)

Name: Anonymous 2015-04-30 19:12

>>24
fuck i mena
print reduce(lambda x, y: x+y, ["%s%s" % ('*'*x, '\n') for x in xrange(1,10,2)])

Name: Anonymous 2015-04-30 20:02

void main(){while(rand()){putchar(rand()&1?'*':'\n');}}
worked very well for me

Name: Anonymous 2015-04-30 20:02

>>24-25
xrange

What, Pythonists still haven't migrated to 3.x? After six fucking years? Haha, Guido is a fucking loser, the stupid Jewish Nazi.

Name: Anonymous 2015-04-30 20:52

#!/bin/bash
echo '*
***
*****
*******
*********'
exit 0

Name: Anonymous 2015-04-30 20:58

>>28
technically correct

Name: Anonymous 2015-04-30 21:40

>>27
Guido can pry 2.7 out of my cold dead fingers

just kidding i'm wracked with guilt daily

Name: Anonymous 2015-04-30 22:20

>>27
If you're going to break something, break it right¹. If you want back-compat, do it right.

Perl 6. Out by Christmas.

This Christmas.

¹and while you're at it, get rid of the GIL.

Name: Anonymous 2015-04-30 23:26

>>31
Perl 6. Out by Christmas.
This Christmas.
I was waiting over 10 Christmas for this.

Name: Anonymous 2015-05-01 6:15

>>32
You didn't have to wait. Perl 5 got most of what was in the Perl 6 spec in 2005 backported via libs years ago.

Perl 6 was still doing naive shit in 2009. But experience informed design and it's a much more solid language now.

Name: Anonymous 2015-05-01 7:46

>>33
backported via libs years ago.
Like what, for example? Serious question.

Name: FRIGN 2015-05-01 9:32

#include <stdio.h>

int
main(void)
{
int i, j;

for (i = 0; i < 5; i++) {
for (j = 0; j < 2 * i + 1; j++) {
fputc('*', stdout);
}
fputc('\n', stdout);
}

return (fclose(stdout) < 0);
}

Name: FRIGN 2015-05-01 9:41

Here's my go at the pyramid. No idea why people complicated this so much.

``
#include <stdio.h>

#define HEIGHT 5

int
main(void)
{
int i, j;

for (i = 0; i < HEIGHT; i++) {
for (j = HEIGHT - i; j; j--) {
fputc(' ', stdout);
}
for (j = 0; j < 2 * i + 1; j++) {
fputc('*', stdout);
}
fputc('\n', stdout);
}

return (fclose(stdout) < 0);
}
``

Name: FRIGN 2015-05-01 9:43

<code>
#include <stdio.h>

#define HEIGHT 5

int
main(void)
{
int i, j;

for (i = 0; i < HEIGHT; i++) {
for (j = HEIGHT - i; j; j--) {
fputc(' ', stdout);
}
for (j = 0; j < 2 * i + 1; j++) {
fputc('*', stdout);
}
fputc('\n', stdout);
}

return (fclose(stdout) < 0);
}
</code>

Name: Anonymous 2015-05-01 9:55

>>36-37
It's [code]

Name: Anonymous 2015-05-01 13:55

>>34
Junctions, Roles, Grammars, the object system, etc.

Name: 7,9 2015-05-01 14:51

>>21
I wanted to write it in an unusual manner.
>>25
I don't fucking get it lol. What is that x+y?
>>37
I think your program contains an unnecessary space in every line

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List