Help My Brother Work on his Tan(gent)!

7

2

This challenge is entirely fictional. There is no time limit for this challenge.

My little brother is terrible with computers! He saved up all of his money to buy a new one, and within half an hour the hard drive was wiped and the only software left is a lousy BF interpreter. The worst part of it is, he has a huge Geometry test tomorrow and needs help!

The Challenge

There's no way I'm going to let him touch my machine, so I'm going to need a fast way to write BF programs that solve his problem. He's learning about finding the area of regular polygons, and writing a new BF program for every calculation is a massive task. I need a fast way to generate BF programs! That's where you come in...

The Input

Your program or function will receive an integer 2 < N <= 100 which shall represent the number of sides of a regular polygon. You may receive input from function arguments, command line arguments, STDIN, or your language's closest alternative. If necessary, you may additionally require trailing or leading whitespace.

The Output

Your program should generate a separate BF program that takes input of a single positive integer 0 < a <= 10^10 that shall represent the length of the apothem of a regular polygon. When run, the BF program should output the area of a polygon with N sides and an apothem of a. More specifically:

  • Assume that the BF interpreter is set up such that , takes a number as input and . outputs a value as a number, not a character. An input of 12 does not translate to the characters '1' '2' in memory, rather the literal number 12. Similarly, when a value of 48 is output, it outputs '48', not the character '0'.
  • Assume also that each value on the tape of the BF program may contain an infinitely large integer -- the value will never wrap to 0.
  • Assume that the tape of the BF spans infinitely to the right, but has no negative indices. The pointer starts at 0.
  • My brother is as careless with numbers as he is with computers. As such, the BF code should output the area rounded to the nearest integer.

The Rules

In a separate and unrelated incident, my brother downloaded so much garbage onto my primary programming machine that I have virtually no hard drive space left. As such, your original program may not exceed 512 bytes.

Your score in this challenge is the length of all BF programs generated by your program for values of N from 3 to 100 inclusive.

Standard loopholes are disallowed.

BrainSteel

Posted 2015-04-17T02:14:42.500

Reputation: 5 132

So, you don't allow him to touch your computer, but he somehow clugged up your computer with garbage? Maybe clean it up. – Bálint – 2016-06-05T11:46:23.627

@Bálint If this is not humorous, then you're wrong. He might have installed all that garbage there before bying the new PC. – Erik the Outgolfer – 2016-06-06T18:33:53.243

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Don't worry, I was – Bálint – 2016-06-06T18:59:00.320

@Bálint You were wrong or the comment was humorous? – Erik the Outgolfer – 2016-06-06T19:00:53.017

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ The comment was humorous – Bálint – 2016-06-06T19:47:39.683

@Bálint Typo + Spellchecker = MESS! – Erik the Outgolfer – 2016-06-06T19:51:50.393

Answers

4

Python, 23938 score

from math import*
def apothem(n):
 c=int(n*tan(pi/n)/2*10)

 s=',>' + '+'*c
 m=">[-]>[-]<<[>>+<<-]>>[<<<[>+>+<<-]>>[<<+>>-]>-]<<"*2
 p=">>[-]<[-]<+++++<[-]++++++++++"
 d=">[>+<-]>[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[>+<<-[>>[-]>+<<<-]>>>[<<<+>>>-]<[<-[<<->>[-]]+>-]<-]<<+>]"
 o="<."
 print s+m+p+d+o
  • the area of a regular polygon is nsa/2 width n given in Python and a later in BF. s is the sidelength of the polygon, which can be computed from a and n
  • c is a constant, such that the area is (aac+5)/10, so only this formula must be coded into BF. c is between 15 and 25.
  • s is the starting point for the BF code: read the apothem and write c
  • m does c=ca twice, so in the cell formaly holding c there is aac
  • p prepares for the final operation, clearing temporary cells, adding 5 to aac and setting the first cell to 10
  • d division
  • o output

This is my first writing in BF, so all algorithms are from this page.

Karl Napf

Posted 2015-04-17T02:14:42.500

Reputation: 4 131