Code Golf is the art of achieving a particular challenge with as less code as possible. I'd like to see what kinds of tricks Sup Forums can do with their favorite language. The challenge is to print an ASCII "diamond" on the terminal, like so: * *** ***** ******* ***** *** *
you can drop the parenthesis in an arrow function if there's exactly one argument
Jack Diaz
You mean APL, J or one of those specialized golfing languages.
Christopher Clark
>java heresy! bring the pitchforks, this worm dared to proliferate unwholly words inside the Saint IGNUcius altar
Ethan Sullivan
Lua version. Could shave off some characters by not making it a function. function d(w)o="*";r=o:rep(w);s="";for i=2,w,2 do s=s.." ";t=s..o:rep(w-i);r=t.."\n"..r.."\n"..t;end;print(r)end d(7) d(3) d(1) * *** ***** ******* ***** *** * * *** * *
Good luck, I hope you have one of those special keyboards with moon runes, eh?
J looks cool, though.
Isaiah Long
python, only because I had my IDE open h=10 def a(s,l): x=s if l!=0 else '' for i in range(l-1): x+=s return x for i in range(h*2-1): x=h-i-1 if i
Carson Scott
100 characters lambda n:print("\n".join(' '*(n-j)+'*'*(j*2-1) for i in (range(1,n+1),range(n-1,0,-1)) for j in i))
Jose Bailey
Fiddled with it a bit more, saved four characters. function d(w)o="*"r=o:rep(w)for i=2,w,2 do t=(" "):rep(i/2)..o:rep(w-i)r=t.."\n"..r.."\n"..t;end;print(r)end
John Perez
test test
Dylan Perez
Sup Forums does not like my 199 char java8 solution, have a screenshot instead..
Behold! The least comprehensible code of all time! (|.|:(' ','*',^:(1+i.2)''),|.' ','*',^:(1+i.3)''),|:('*',^:(1+i.3)''),|.'*',^:(1+i.4)''
87 characters
Tyler Bailey
it also generalizes, at the cost of a few more characters: d =: 3 : 0 f =.
Hudson Ward
the fuck is this language?
Justin Martinez
Can we also see who can do this trying to use as many characters as they can? I need a good laugh
Easton Howard
Now we just need one for pony.
Jeremiah Gomez
Meant to also quote since Pony can have even more processes than Erlang/Elixir.
It will automatically garbage collect processes that are waiting for a message but will never recieve one, I guess that could be a source of inspiration.
William White
Sup Forumsod tier
Eli Jenkins
That image makes me want to learn Erlang
Carson Butler
I want to say awk
Lucas Wilson
import diamond print(diamond(n))
Nicholas Rivera
python3 for y,x in zip([3,2,1,0,1,2,3],[1,3,5,7,5,3,1]):print(' '*y+'*'*x)
66 :^(
Wyatt Reyes
its not werf it tantalizes you with possibility but ultimately the ecosystem is slumping towards disrepair slowly but surely
Jeremiah Ward
>Come with me if you want to research But I use Ruby and Python for that...
Not that great, but meh, I didn't want to spend all that long on it f x=sequence$putStrLn((reverse$g$x-2)++g x) where g (-1)=[] g y=(replicate(quot(x-y)2)' '++replicate y '*'):g(y-2)
main(i) { i = (i-1)?i:0x1ffff03; char* s = &i; for(;*s!=s[1];(*s)+=s[2]) printf("%*s\n",7-*s,*s+(short*)"*******"); s[3] && main(0x10401); }
works on my machine
Hudson Stewart
Mix up Erlang, C++ and Rust.
Aiden Wood
The ecosystem is growing. The library quality is as good as ever.
Chase Mitchell
I'd recommend taking a look at Elixir instead. Get all the benefits of BEAM and OTP, plus a bitchin' macro system (macros are themselves written in Elixir and work on the parsed source code, not the plain-text representation) that cuts out 95% of the obscene amount of boilerplate code that Erlang requires.
Neither Erlang nor Elixir have much of a job market at the moment, but I've been studying Elixir in my spare time the past couple of months and I really think it's poised to blow up in the next few years as people realize that it's much more than just "Erlang that looks like Ruby".
Mason Kelly
You'll still need to learn Erlang to use Elixir seriously because you'll need to read the docs for Erlang/OTP itself and for its libraries.
Jack Bennett
what the fuck
Jordan Cruz
Fair enough. I've been slowly working through "Elixir in Action" and while the author strongly recommends studying Erlang, I am definitely not at the "using Elixir seriously" level so it hasn't been much of an issue for me yet.
Cooper James
you should check out the IOCCC
Aaron Lewis
It's not perfect, but here's my brainfuck thing: +++++[>+++++ +++< +++++ ++[>>+++++ +................<
.>.........
Juan Cooper
Read Programming Erlang next. It's a really good programming book.