This is a variation of my solution for challenge #2. Just add the class "triangle" to a block element, and specify the lines in the CSS variable --stars:
I have no Go pun this time. Sorry, I need coffee for that.
pyramid.go
packagepyramid// Pyramid creates a text pyramid of the given heightfuncPyramid(heightint)string{ifheight<=0{return""}// Determine width of pyramid basewidth:=(height*2)-1// Get middle of pyramidmiddle:=int(width/2)row:=0// Initialize a base row with only spacesbase:=make([]rune,width,width)fori:=rangebase{base[i]=' '}// Set the top row 'block'base[middle]='*'varpyramidstring// Build the pyramid starting from the topforrow<height{base[middle+row]='*'base[middle-row]='*'pyramid+=string(base)+"\n"row++}returnpyramid}
Since this is pretty much the top half of a string diamond I took my answer from that challenge and used just the first half of the code but it isn't working like expected, can someone tell me where I went wrong? 😥
Ruby:
defriamond_i_mean_ryramid(karat)unlesskarat.odd?&&karat>0raiseArgumentError.new("You want a #{karat} karat ~~diamond~~ pyramid? That's crazy!")endcut=1layers=[]untilcut>karatlayers.push(("*"*cut).center(karat))
19 yo student *and* a full-time developer.
Building with Rails currently, exploring new frontiers.
I enjoy functional programming, Linux, FOSS, refactoring and mentoring :)
Fun challenge :) I did it in React, so here's the function:
and here's a demo!
Python one-liner yet again :)
Impeccable
CSS
This is a variation of my solution for challenge #2. Just add the class "triangle" to a block element, and specify the lines in the CSS variable
--stars:The idea is having an inline SVG background with the asterisks, then clipping the shape of the triangle. Here is a demo on Codepen:
I have no Go pun this time. Sorry, I need coffee for that.
pyramid.go
pyramid_test.go
Since this is pretty much the top half of a string diamond I took my answer from that challenge and used just the first half of the code but it isn't working like expected, can someone tell me where I went wrong? 😥
Ruby:
Here it is!
The right padding isn't necessary, but hey why not
F#:
This is really close to challenge #2
Javascript, can be run from the command line:
My try. I used
padStartandpadEnd, and abused default parameters a bit, just for fun.My solution in js
Rust:
Python
[gist.github.com/devparkk/9b0e19758...]
Isn't that a triangle?