"blind" programming [challenge]
1
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.
2
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;
3
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;
4
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.
5
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 $ " * "
6
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 $ " * "
7
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; }
8
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))
9
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; }
10
Name:
Anonymous
2015-04-30 0:47
Ruby 10.times { |n| puts "*"*n if (n%2).odd? }
11
Name:
Anonymous
2015-04-30 0:53
>>9 This one failed horribly, lol
12
Name:
Anonymous
2015-04-30 2:07
STAR = 5 for x in range(STAR): print "*" * (x+1)
13
Name:
Anonymous
2015-04-30 2:11
import BoringChallengesThatPlagueProgrammingCommunitiesLikeAIDSPlaguesFags main = printStars 5
14
Name:
Anonymous
2015-04-30 2:11
STAR = 5 for x in range(1, STAR*2, 2): print "*" * x
15
Name:
Anonymous
2015-04-30 3:00
cute thread.
16
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; }
17
Name:
Who am I quoting?
2015-04-30 4:58
>>16 ,s/puts/putchar/
$ ./triangle * *** ***** ******* *********
18
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
19
Name:
Anonymous
2015-04-30 12:23
def star_printer(row_count): for row in range(row_count): print('*', '**' * row, sep='')
20
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; }
21
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...
22
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 ;
23
Name:
Anonymous
2015-04-30 18:48
24
Name:
Anonymous
2015-04-30 19:08
print "%d%s" % ('*'*x, '\n') for x in xrange(1,10,2)
25
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)])
26
Name:
Anonymous
2015-04-30 20:02
void main(){while(rand()){putchar(rand()&1?'*':'\n');}}
worked very well for me
27
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.
28
Name:
Anonymous
2015-04-30 20:52
#!/bin/bash echo '* *** ***** ******* *********' exit 0
29
Name:
Anonymous
2015-04-30 20:58
30
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
31
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.
32
Name:
Anonymous
2015-04-30 23:26
>>31 Perl 6. Out by Christmas.This Christmas. I was waiting over 10 Christmas for this.
33
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.
34
Name:
Anonymous
2015-05-01 7:46
>>33 backported via libs years ago. Like what, for example? Serious question.
35
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); }
36
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); } ``
37
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>
38
Name:
Anonymous
2015-05-01 9:55
39
Name:
Anonymous
2015-05-01 13:55
>>34 Junctions, Roles, Grammars, the object system, etc.
40
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
41
Name:
Anonymous
2015-05-01 16:50
42
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
43
Name:
Anonymous
2015-05-01 21:16
#!/bin/sh STRING="*"; ITERATION=0; while [ 5 -gt "$ITERATION" ]; do echo "$STRING"; STRING="$STRING**"; ((ITERATION++)); done;
44
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
45
Name:
Anonymous
2015-05-02 22:57
Ruby pyramid10.times { |n| puts " "*(10-n)+"*"*n if (n%2).odd? }
46
Name:
Anonymous
2015-05-02 22:59
whoops, fixed!10.times { |n| puts " "*((10-n)/2)+"*"*n if (n%2).odd? }
47
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?
48
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,l ev++)\
printf("%.*s%.*s\n",spaces,space,stars,star);})
STDSTART //default 80 max base stars
pyr((argc>1?atol(argv[1]):80));
STDEND
49
Name:
Anonymous
2015-05-03 14:07
++++[>++++++++++>++<<-]>++>++<.>.<<+++[>.<-]>>.<<+++++[>.<-]>>.<<+++++++[>.<-]>>.<<+++++++++[>.<-]>>.
50
Name:
Anonymous
2015-05-03 15:18
>>49 did you fuck write that without testing
51
Name:
Anonymous
2015-05-03 18:49
51 Some people think in brainfuck.
52
Name:
Anonymous
2015-05-03 20:28
53
Name:
Anonymous
2015-05-03 22:01
54
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; }
55
Name:
Anonymous
2016-10-24 14:48
//Compile Time Optimization #pragma message "\n"\ " *\n"\ " *** \n"\ " ***** \n"\ " ******* \n"\ " ********* \n"\ " *********** \n"\ " ************* \n"\ int main(){}
56
Name:
Anonymous
2016-10-24 15:26
57
Name:
Anonymous
2016-10-24 21:05
main = putStrLn $ foldr (++"\n"++) "" $ map show $ take 5 $ iterate (\x -> "*"++x++"*") "*"
58
Name:
Anonymous
2016-10-24 21:08
Fuck, I failed.main = putStrLn $ foldr (\x y -> x++"\n"++y) "" $ take 5 $ iterate (\x -> "*" ++ x ++ "*") "*"
59
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)))
60
Name:
Anonymous
2016-10-25 3:28
5.times do |i| puts "#{' ' * (4 - i)}#{?* * ((i * 2) + 1)}" end