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

Pages: 1-4041-

"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

Name: Anonymous 2015-05-01 16:50

>>40
["%s%s" % ('*'*x, '\n') for x in xrange(1,10,2)] is a list comprehension (http://www.secnetix.de/olli/Python/list_comprehensions.hawk) which gives a list of ["*\n", "***\n" "*****\n" .. ] etc.

https://docs.python.org/2/library/functions.html#reduce
http://www.secnetix.de/olli/Python/lambda_functions.hawk

Name: Anonymous 2015-05-01 21:14

#!/bin/sh
STRING="*";
ITERATION=0;
while [ 5 -ge "$ITERATION"]; do
echo "$STRING";
STRING="$STRING**";
((ITERATION++));
done;


NO EXCEPTIONS

Name: Anonymous 2015-05-01 21:16

#!/bin/sh
STRING="*";
ITERATION=0;
while [ 5 -gt "$ITERATION" ]; do
echo "$STRING";
STRING="$STRING**";
((ITERATION++));
done;

Name: Anonymous 2015-05-02 18:51

//pyramid.c
#include "void.h"
//https://gist.github.com/FrozenVoid/87e6ad6212ac9ce496e0
#define pyrpr(w,l) sm s4 stars=(l<<1) + 1,spaces = (w - stars)>>1;\
if(stars <= w){\
while(spaces--)putchar(' ');\
while(stars--)putchar('*');\
putchar('\n');} em
#define pyr(w,l) ({for(s4 lev=l;lev<w;lev++)pyrpr(w,lev);})
STDSTART //default 80 max base stars
s4 basew=(argc>1?atol(argv[1]):80);
pyr(basew,0);
STDEND

Name: Anonymous 2015-05-02 22:57

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

Name: Anonymous 2015-05-02 22:59

whoops, fixed!
10.times { |n| puts " "*((10-n)/2)+"*"*n if (n%2).odd? }

Name: Anonymous 2015-05-02 23:29

>>35-37
return (fclose(stdout) < 0);
Is this actually him or is it someone making fun of him?

Name: Anonymous 2015-05-03 4:08

>>46
//pyramid2.c
#include "void.h"
//https://gist.github.com/FrozenVoid/87e6ad6212ac9ce496e0
#define pyr(w) ({ c1 star[w],space[w];\
fill(star,'*');fill(space,' ');\
s4 stars=0,spaces=w>>1;\
for(s4 lev=0;stars<=w;\
stars=(lev<<1)+1,spaces=(w-stars)>>1,lev++)\
printf("%.*s%.*s\n",spaces,space,stars,star);})
STDSTART //default 80 max base stars
pyr((argc>1?atol(argv[1]):80));
STDEND

Name: Anonymous 2015-05-03 14:07

++++[>++++++++++>++<<-]>++>++<.>.<<+++[>.<-]>>.<<+++++[>.<-]>>.<<+++++++[>.<-]>>.<<+++++++++[>.<-]>>.

Name: Anonymous 2015-05-03 15:18

>>49
did you fuck write that without testing

Name: Anonymous 2015-05-03 18:49

51
Some people think in brainfuck.

Name: Anonymous 2015-05-03 20:28

>>49
.<

Name: Anonymous 2015-05-03 22:01

>>50

yay

Name: Anonymous 2016-10-24 14:16

#include <stdio.h>

void printstars(int n) {
while(n--) putchar('*');
putchar('\n');
}

int main(void) {
int lines, i=0, width;
printf("How many lines to print?"); scanf("%d", &lines);
while(i < lines) {
width = 1 + ((i+1) * 2);
printstars(width);
i++;
}
return 0;
}

Name: Anonymous 2016-10-24 14:48

//Compile Time Optimization
#pragma message "\n"\
" *\n"\
" *** \n"\
" ***** \n"\
" ******* \n"\
" ********* \n"\
" *********** \n"\
" ************* \n"\
int main(){}

Name: Anonymous 2016-10-24 15:26

Name: Anonymous 2016-10-24 21:05

main = putStrLn $ foldr (++"\n"++) "" $ map show $ take 5 $ iterate (\x -> "*"++x++"*") "*"

Name: Anonymous 2016-10-24 21:08

Fuck, I failed.

main = putStrLn $ foldr (\x y -> x++"\n"++y) "" $ take 5 $ iterate (\x -> "*" ++ x ++ "*") "*"

Name: Anonymous 2016-10-25 1:32

(use srfi-1)
(define (genstars x)
(append (make-list (/ 2 (- 9 x)) " ")
(make-list x "*"))

(define (prnstars)
(map (lambda (x)
(map (lambda (c)
(display c))
(genstars x))
(newline))
(iota 5 1 2)))

Name: Anonymous 2016-10-25 3:28

5.times do |i|
puts "#{' ' * (4 - i)}#{?* * ((i * 2) + 1)}"
end

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