Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1095179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:05:00+00:00 2026-05-17T00:05:00+00:00

Since this week noone has posted a code-golf challenge, I’ll give it a try.

  • 0

Since this week noone has posted a code-golf challenge, I’ll give it a try. I do it so you can do something other than playing with swords during those long compile cycles.

The challenge:

Draw ASCII art stars, given three numbers on standard input (number of spikes, type of star (star is drawn by joining vertices that are n vertices apart), and diameter of star). Examples:

Input:                        Input:                       Input:

5 2 20                        7 2 20                       7 3 20

Output:                       Output:                      Output:

             x                        x                        x
            xx                        xx                       x
            xx                       x  xx   xx                xx      x
           x x                       x   xxxx x                xx     xx
  xx      x  x                      xxxxx  x  x                x x  xxx
   xxxx   x  x                   xxxx       x x                x x x  x
   x   xxx   x                 xx  x         xx         xxx    x  x  x
    x   x xxxx                 x   x          xx         x xxxxx xx  x
     x  x    xxx                x x           x x         xx   xxxxxx
     x x     x  xxx             x x           x  x          x xx   xxxxxx
      x      x     xx            x            x   x          x x   x     xxx
     x x     x  xxx              x            x  x          x xx   xxxxxx
     x x     xxx                x x           x x         xx   xxxxxx
    x   x xxxx                  x x           xx         x xxxxx xx  x
   x   xxx   x                 xx  x         xx         xxx    x  x  x
   xxxx   x  x                   xxxx       x x                x x x  x
  xx      x  x                      xxxxx  x  x                x x  xxx
           x x                      x    xxxx x                xx     xx
            xx                       x  xx   xx                xx      x
            xx                       x x                       x
             x                        x                        x

Since rasterizing correctly the lines can be a PITA for a code-golf challenge, I’ll leave some leeway, but not too much. More examples:

Good enough:

    x           x                   x       x
     xx       xx                    x       x
       x     x                       x     x
     x  xx xx  x                      x   x
          x                            x x
         x x                            x
      xxx   xxx                      x     x
      x       x               xxxxxxxxxxxxxxxxxxxxx
     x         x                xx    x   x    xx
   xx  x     x  xx                xx x     x xx
  x               x                 xxx   xxx
xxxxxxxxxxxxxxxxxxxxx                 xxxxx
        x   x                      x  xx xx  x
                                  x xx     xx x
                                 xxx         xxx
         x x                    xx     x x     xx


          x
                                        x

Doesn’t cut it:

            x                  xx               xx
            xx                   x             x
            xx                    x           x
           x x                     xx       xx
 xx       x  x                       x     x
  xxxx   x   x                     x  xx xx  x
  x   xxxx   x                          x
   x    xxxx x                         x x
    x  x    xxx                     xxx   xxx
     xx      x xxxxxx               x       x
     xx      x xxxxxx              x         x
     xx     xxx                  xx  x     x  xx
    x  x xxx x                  x               x
    x xxx    x                xxxxxxxxxxxxxxxxxxxxx
   xxx  x    x                        x   x
 xx      x   x
          x  x
          x  x                         x x
           x x
            xx
                                        x

 Lack of precission              Lack of clipping

Have fun!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:05:01+00:00Added an answer on May 17, 2026 at 12:05 am

    Ruby — 323 276 304 297

    a,b,c=gets.split.map &:to_i
    o=(0..c).map{' '*c}
    m=(1..a).map{|i|r=2*h=Math::PI*i/a
    [(1+Math.sin(r))*c/2+0.5,(1+Math.cos(r))*c/2]}
    a.times{|n|j,i,x,y=*m[n],*m[n-b]
    j,x,i,y=i,y,j,x if k=((i-y)/(j-x))**2>1
    s,z=[x,j].sort
    s.to_i.upto(z){|m|t=i+(m-j)*(i-y)/(j-x)
    k ?(o[t][m]='x'):(o[m][t]='x')}}
    puts o
    
                 x              xx                   x                      xx          
                 x              x x                  x                      x x         
                xx              x  x    xx           xx       x            x   x        
               x x             x    xxxx x           xx      xx      xxxxxxxxxxxxxxxx   
     xxx      x  x             xxxxx xx  x           x x    xx       x   x       x  x   
      x xxx   x  x         xxxxx       x x    x      x x   x x       x  x         x x   
      x    xxx   x       xx   x         xx     xxxx  x  xxx x        x x           xx   
       x    x xxxx        x  x           x       x xxxxxx   x        xx             x   
        x  x     xxx      x  x           xxx      x  x xxxxx         x              xx  
         x x     x  xxx    xx            x  x      x xx  x xxxxx    xx              x x 
         xx      x     xx  xx            x   x      xx    x     xxxx x              x  x
         xx      x  xxx    xx            x  x      x xx   x xxxx    xx              x x 
         x x     xxx       xx            xxx      x  x xxxxx         x              xx  
        x  x  xxxx        x  x           x       x xxxxxxx x         xx             x   
       x   xxx   x       xx  x          xx     xxxx  x  xxx x        x x           xx   
      x xxx  x   x         xxxxx       x x    x      x  x  xx        x  x         x x   
     xxx      x  x            x xxxx xx  x           x x    xx       x   x       x  x   
              x  x             x    xxxx x           x x     x       xxxxxxxxxxxxxxxx   
               x x             x   x    xx           xx       x            x   x        
                xx              x x                  xx                     x x         
                 x              xx                   x                       x          
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.