Finding Triplets for n in Brainf***: An Algorithm Analysis

  • Context: Graduate 
  • Thread starter Thread starter Aphex_Twin
  • Start date Start date
  • Tags Tags
    Weird
Click For Summary
SUMMARY

The discussion focuses on finding triplets (a, b, c) that satisfy the equation n = a*b + c + 5 under specific conditions, particularly for the esoteric programming language Brainf***. The participants suggest that for n=65, optimal values are a = 5, b = 11, and c = 5, derived from simplifying the conditions. The analysis emphasizes minimizing the absolute difference |a-b+c| while ensuring n exceeds a+b+|c|+5. The conversation also explores alternative approaches, including prime factorization and adjusting the constant in the equation.

PREREQUISITES
  • Understanding of natural numbers and integers
  • Familiarity with the Brainf*** programming language
  • Basic knowledge of algebraic manipulation and inequalities
  • Concept of absolute values in mathematical expressions
NEXT STEPS
  • Research efficient algorithms for solving equations involving multiple variables
  • Explore optimization techniques in mathematical programming
  • Study the properties of prime factorization and its applications
  • Learn about complexity analysis in algorithm design
USEFUL FOR

Mathematicians, algorithm developers, and programmers interested in optimization problems and the Brainf*** programming language.

Aphex_Twin
Messages
39
Reaction score
0
Given n, can we find a triplet a, b, c that fits the following conditions:

n = a*b+c+5
abs(a-b+c) is minimum

but only if
n>a+b+abs(c)+5

Where n, a, b are naturals and c is integer.


For instance in case of n=65, I have a hunch the best choices are:
a = b = 8
c = 1


The background for this problem stems from an esoteric programming language - brainf*** ( http://en.wikipedia.org/wiki/brainf*** ). Specifically, I'm trying to find out the most efficient way of writing up ASCII text strings (numerical values between 32 and 255). You can do it either by using an n number of + signs (basically unary, where 65 would be represented by 65 times the '+' sign). The idea is that multiplying two numbers together would be a more efficient way. The code length would be exactly a+b+abs(c)+5.


Well, you don't have to get bogged down in the details of the language, but if you have an idea for an answer, algorithm or complexity analisys of the problem, you are most welcome to post it.
 
Mathematics news on Phys.org
Unless I'm more tired than I realize, 8*8 + 1 + 5 = 70. For n = 65, I found a = 5, b = 11, c = 5 pretty quickly by just putting things together and simplifying:
1) ab + c + 5 > a + b + |c| + 5 =
2) ab + c > a + b + |c|.
If c > 0, (2) reduces to
3) ab > a + b
If c < 0, (2) reduces to
4) ab > a + b + 2|c|
And add in
5) |a - b + c|
To minimize (5), when c > 0, you want a < b, and when c < 0, you want a > b. And of course, you ideally want (5) to equal 0, and that's easy enough to set up. You can get (5) = 0 for a = b, a > 2, c = 0, n = a2 + 5. Work from there maybe. I don't know how to solve your problem, just thought I'd mention some things. If you continue in this manner, you may find your algorithm. Otherwise, I dunno- did you look at some prime factorizations? [shrug] Good luck.
Edit: Actually, why not just ditch the constant (n is any number in your sequence, so you can just add 5 back in later). Set c > 0 and a < b. Then I think your problem becomes finding solutions for:
6) n = ab + c
7) b - a = c
8) ab > a + b
(7) should make (5) = 0. You can try the other way (c < 0) if this doesn't work out. So some things are apparent now- like that c can't equal 0 unless n is a perfect square. Edit: If you play around with (6) and (7), you may discover a familiar form.
 
Last edited:

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
9
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 125 ·
5
Replies
125
Views
21K