Questions tagged [ternary]

The base-3 positional numeral system which represents numbers using the digits 0, 1, and 2

Ternary is the base-3 positional numeral system which represents numbers using the digits 0, 1, and 2. In computing it is less common than , but there have been ternary computers, and it can be used to represent sequences of ternary (3-way) choices.

A unit of information in the ternary numeral system is sometimes called a trit (by analogy with for binary).

Number systems:

       Name         |   Base  |   numbers
------------------------------------------                 
ternary   - system  |     2   |    0... 2
decimal   - system  |    10   |    0... 9

ternary    |    decimal      
-----------------------
         0 |        0        
         1 |        1         
         2 |        2       
        10 |        3        
        11 |        4      
        12 |        5       
        20 |        6      
        21 |        7       
        22 |        8       
        30 |        9      
       101 |       10       
       121 |       16      
      1012 |       32       
      2101 |       64       
     11202 |      128     
    100110 |      255      

Decimal -> Ternary

Number: 42

42 / 3 = 14 Rest 0    ^
14 / 3 =  4 Rest 2    |
 4 / 3 =  1 Rest 1    |
 1 / 3 =  0 Rest 1    |  => 42 = 1120
                                 ----->

Ternary -> Decimal

Number: 1120

1  1  2  0   
|  |  |   -------- 0 x 3^0  ->   0
|  |   ----------- 2 x 3^1  ->   6
|   -------------- 1 x 3^2  ->   9
 ----------------- 1 x 3^3  ->   27
                                    = 42
643 questions
3
votes
1 answer

Ruby ternary operator structure

puts bool ? "true" : "false" is proper, but bool ? puts "true" : puts "false" is not. Can somebody explain to me why this is? Side note: bool ? ( puts "true" ) : ( puts "false" ) works fine as well.
NBarnes
  • 109
  • 6
3
votes
1 answer

Change to ternary in JSTL

Can you please help me to convert this JSTL tag to a JSTL ternary class="author" class="${page.class}" >
Morais
  • 801
  • 2
  • 10
  • 15
2
votes
2 answers

Is there a shorter ternary for Ruby?

This is the closest I've found but it deals with booleans instead of numbers: DRY up Ruby ternary I'm trying to avoid a divide by 0 scenario in Ruby, while keeping the code shorter and easier to read. I want to make the following bit of code more…
Zhao Li
  • 4,936
  • 8
  • 33
  • 51
2
votes
1 answer

React.JS Parsing Error for ternary conditional operation component rendering

I am trying to create a nested if statement within a nested if statement using ternary operations. However, I am encountering an error when trying to do so. Here is my code: {count > 0 ? ( <>
Annissa Mu
  • 23
  • 3
2
votes
2 answers

"ggtern" Ternary plot gridlines and axis ticks needed

I am trying to add gridlines and axis ticks to the ternary plot. I was able to adjust the numeric values of the axis, but unable to get axis ticks and grids inside the plot. Here is an example R code: library(ggplot2) # Example data x <-…
J.M
  • 25
  • 4
2
votes
4 answers

Vue.js 3 v-if ternary function, how to pass object as a conditional

Brand Color#: {{ message }}

I am bringing in data off a…
randomfool
  • 69
  • 1
  • 9
2
votes
1 answer

Is there a way to rotate the ticklabels in a ternary plot with the python ternary package?

I am working with the python ternary package. To improve the intuitive understanding of the plot, I want to rotate the tick labels on the axis to indicate in which direction the gridlines of this axis point, like in the plot below. Python-ternary…
AlexWach
  • 592
  • 4
  • 16
2
votes
1 answer

Ternary Plot using a vector as density

I have a dataset like this: DENSE<-runif(10, min=0, max=100) CROP<-runif(10, min=0, max=100) WILD<-runif(10, min=0, max=100) BetaDiv<-runif(10, min=0, max=1) df<-data.frame(DENSE, CROP, WILD, BetaDiv) I use this code to do a simple ternary…
2
votes
5 answers

Two if statements using ternary condition

The title seems confusing but this is my first time using ternary conditions. I've read that ternary is meant to be used to make an inline if/else statement. Using no else is not possible. Is it true? I want to change this with ternary condition for…
user874737
  • 469
  • 1
  • 9
  • 24
2
votes
1 answer

ggtern - create contoured ternary plot

I am trying to create a ternary plot with contoured filling using the "ggtern" package. The aim would be to create a similar plot as shown below, where each triangulation point (EXT;INT;SA) expresses a value MF... I was using the…
cblaettle
  • 33
  • 3
2
votes
1 answer

How to work Define Function As #define Max(a,b)(a>b?a:b)

How does It shows 5 as Out put . #include #define max(a,b)(a>b?a:b) int main() { int i=2,j=3,k; k=max(++i,++j); printf("%d",k); }
2
votes
1 answer

Powershell 5.1 ternary with array assignment

I have a question towards ternary operators in Powershell 5.1. It doesn't work as I expected it if I try to assign an array @(...): # I can assign an array to a variable: $a=@("TRUE") write-host "a:" $a # I can do that in a…
jamacoe
  • 519
  • 4
  • 16
2
votes
1 answer

In java is ternary operator considered a single line expression while using inside a lambda function?

Collections.sort(employees, (employee1, employee2) -> { return (employee1.getAge() >= employee2.getAge()) ? -1 : 1; }); The above code sample sorts the 'employees' List according to age just fine. But, the code below gives an…
2
votes
2 answers

Ternary Equivalency UML

[Ternary] [Equivalency] Hi guys, I need to know if this two connections are similar, i suspect they aren't but i am clueless about the reasons why. Much appreciated for any help ;D
2
votes
2 answers

Javascript: Remove specific items from an array and return the original array without those items

New to JS. Doing a practice exercise in which I want to remove some specific items from an array and return the original array back without those items. I did it one way, but the sample solution was completely different and I want to try and…
Katie Reynolds
  • 317
  • 2
  • 16