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

  • Home
  • SEARCH
  • 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 685535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:55:57+00:00 2026-05-14T01:55:57+00:00

The Challenge Guidelines for code-golf on SO The shortest code by character count to

  • 0

The Challenge

Guidelines for code-golf on SO

The shortest code by character count to display a representation of a circle of radius R using the *character, followed by an approximation of π.

Input is a single number, R.

Since most computers seem to have almost 2:1 ratio you should only output lines where y is odd. This means that when R is odd you should print R-1 lines. There is a new testcase for R=13 to clarify.

eg.

Input
    5
Output      Correct                          Incorrect

        3    *******                    4      *******
        1   *********                   2     *********
       -1   *********                   0    ***********
       -3    *******                   -2     *********
           2.56                        -4      *******
                                            3.44

Edit: Due to widespread confusion caused by odd values of R, any solutions that pass the 4 test cases given below will be accepted

The approximation of π is given by dividing twice the number of * characters by R².
The approximation should be correct to at least 6 significant digits.
Leading or trailing zeros are permitted, so for example any of 3, 3.000000, 003 is accepted for the inputs of 2 and 4.

Code count includes input/output (i.e., full program).

Test Cases

Input
    2
Output
     *** 
     *** 
    3.0

Input
    4
Output
      *****  
     ******* 
     ******* 
      *****  
    3.0

Input
    8
Output
         *******     
      *************  
     *************** 
     *************** 
     *************** 
     *************** 
      *************  
         *******     
    3.125

Input
    10
Output
          *********      
       ***************   
      *****************  
     ******************* 
     ******************* 
     ******************* 
     ******************* 
      *****************  
       ***************   
          *********      
    3.16

Bonus Test Case

Input
    13
Output

           *************       
        *******************    
       *********************   
      ***********************  
     ************************* 
     ************************* 
     ************************* 
     ************************* 
      ***********************  
       *********************   
        *******************    
           *************                                          
    2.98224852071
  • 1 1 Answer
  • 2 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-14T01:55:57+00:00Added an answer on May 14, 2026 at 1:55 am

    In dc: 88 and 93 93 94 96 102 105 129 138 141 chars

    Just in case, I am using OpenBSD and some supposedly non-portable extensions at this point.

    93 chars. This is based on same formula as FORTRAN solution (slightly different results than test cases). Calculates X^2=R^2-Y^2 for every Y

    [rdPr1-d0<p]sp1?dsMdd*sRd2%--
    [dd*lRr-vddlMr-32rlpxRR42r2*lpxRRAP4*2+lN+sN2+dlM>y]
    dsyx5klNlR/p
    

    88 chars. Iterative solution. Matches test cases. For every X and Y checks if X^2+Y^2<=R^2

    1?dsMdd*sRd2%--sY[0lM-[dd*lYd*+lRr(2*d5*32+PlN+sN1+dlM!<x]dsxxAPlY2+dsYlM>y]
    dsyx5klNlR/p
    

    To run dc pi.dc.

    Here is an older annotated version:

    # Routines to print '*' or ' '. If '*', increase the counter by 2
    [lN2+sN42P]s1
    [32P]s2
    # do 1 row
    # keeping I in the stack
    [
     # X in the stack
     # Calculate X^2+Y^2 (leave a copy of X)
     dd*lYd*+ 
     #Calculate X^2+Y^2-R^2...
     lR-d
     # .. if <0, execute routine 1 (print '*')
     0>1
     # .. else execute routine 2 (print ' ')
     0!>2 
     # increment X..
     1+
     # and check if done with line (if not done, recurse)
     d lM!<x
    ]sx
    # Routine to cycle for the columns
    # Y is on the stack
    [
      # push -X
      0lM- 
    
      # Do row
      lxx 
      # Print EOL
      10P
      # Increment Y and save it, leaving 2 copies
      lY 2+ dsY 
      # Check for stop condition
      lM >y
    ]sy
    # main loop
    # Push Input value
    [Input:]n?
    # Initialize registers
    # M=rows
    d sM
    # Y=1-(M-(M%2))
    dd2%-1r-sY
    # R=M^2
    d*sR
    # N=0
    0sN
    [Output:]p
    # Main routine
    lyx
    # Print value of PI, N/R
    5klNlR/p
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The challenge The shortest code by character count to input a 2D representation of
The challenge The shortest code by character count to draw an ASCII representation of
The Challenge The shortest code by character count that takes a single input integer
The challenge The shortest code, by character count to output an ASCII representation of
The challenge The shortest code by character count to solve the input lights out
The challenge The shortest code by character count to generate a wave from the
The challenge The shortest code by character count, that will output musical notation based
The challenge The shortest code by character count to output a spider web with
The challenge The shortest code by character count that will generate a beehive from
The challenge The shortest code by character count that will output the numeric equivalent

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.