Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

75%
+4 −0
Challenges When The Ternary Is Balance

Inspired by this Rosetta Code article. Introduction Balanced Ternary is a method of representing integers using -1, 0 and 1 in base 3. Decimal 11 = (1 * 32) + (1 * 31) + (−1 * 30) = [1,1,-1] or ...

3 answers  ·  posted 3y ago by Razetime‭  ·  last activity 3y ago by Moshi‭

Question code-golf number base
#1: Initial revision by user avatar Razetime‭ · 2021-09-05T05:04:06Z (over 3 years ago)
When The Ternary Is Balance
Inspired by [this Rosetta Code article.](http://rosettacode.org/wiki/Balanced_ternary)

# Introduction

Balanced Ternary is a method of representing integers using -1, 0 and 1 in base 3.

Decimal 11 = (1 * 3<sup>2</sup>) + (1 * 3<sup>1</sup>) + (−1 * 3<sup>0</sup>) = [1,1,-1] or "++-"

Decimal 6 = (1 * 3<sup>2</sup>) + (−1 * 3<sup>1</sup>) + (0 * 3<sup>0</sup>) = [1,-1,0] or "+-0"

# Task

Given any integer, you must give its balanced ternary representation in any permitted format (array, string, etc.)

Your program must support all integers present within its maximum integer limit.

# Test Cases
[Reference implementation with first 200 values](https://tio.run/##lVRNb6MwED23v2I28ioGYwtabaUNTYR62/P2sGqVA6Qm8YoEhOmW9OO3p2MbKP3IYXNw7PGbmfeebSpZFxeHw6pItYara3g6BfxtUg2JWJUyz@NTsKHtHr6vyrOsgTlMeTSF@QL/pwFMQzcPzbyLs2k8JGXN2arEJJct1O6frJuh6n3RKNjKZlPewU4@AP3d1EC0h0ROtCxykRVSa2qpmNKu3BPRIi9UhRS32Yvnmr0cqfhr1wBR8LCRtTSTxRzCo/VXaV3vESWyVEt67tkOopZIWsv/bHQ57oMIyonycLIeyrhCroQRThHfGfWUfLOkXsTfUu2s2r6xw5tuFn/LltCB4cYHGgXnwU8hhO@9tXjPdW0T34jN4IN@u@Fif3zgUU/Y1NP3WYeifnKn1qrRoDRWqPZed32KsqyAbo2PePBh7MzowGbFmO3/sFGF7OO3RC0RxSOUNA6xOZzHowiLlpzHSOaL9AVE8CGdf05nLO6sdGOFbHsl72pCukO7ymZI93m0dF70Yqwlzt6qlrlqZ5d8ARRfEmnN4ZDWHDi8odTOglgPCsyrI4N1aBolWUBSD53TZd0A891JBLiBaIQ6BlfXXx4dJWl3cjcMnknWJz/TENoWhl0O/Z7njVV0/PhnfrgAhtOvBfnHBSUtakEj@u9JF92b6P5j9NHcGMM0aVmy76@e2dFpLt0qL2tTFDmS9s5cJJuFg5FMsTBeWtzxBtXJI0@Mbye2iKju9WaGQaE3Km/Gj/qIqTYtwIzOKbzZKXbs0RPG@SS24WwU5j8uQhddvQcz1sOtMyngqzWp3CCR5qkRSHkUhkLg4FmlCoWalGZbjaoR5ejr1Ly2YAKTwCAEfk2Q6@HwCg "Perl 6 – Try It Online")

```
5 +--
6 +-0
11 ++-
65 +-++-
-44 -++0+
-540 -+-+000
```

# Scoring

This is code-golf. Shortest answer in each language wins.