<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: FLEXARION</title>
    <description>The latest articles on DEV Community by FLEXARION (@matto_yanni2_5018bfec28).</description>
    <link>https://dev.to/matto_yanni2_5018bfec28</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4255552%2F8e37e8b1-0bdf-4392-9fe3-70e8c05d8277.png</url>
      <title>DEV Community: FLEXARION</title>
      <link>https://dev.to/matto_yanni2_5018bfec28</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matto_yanni2_5018bfec28"/>
    <language>en</language>
    <item>
      <title>Ternary logic explained through a hacking game</title>
      <dc:creator>FLEXARION</dc:creator>
      <pubDate>Fri, 20 Nov 2026 11:06:54 +0000</pubDate>
      <link>https://dev.to/matto_yanni2_5018bfec28/ternary-logic-explained-through-a-hacking-game-31hh</link>
      <guid>https://dev.to/matto_yanni2_5018bfec28/ternary-logic-explained-through-a-hacking-game-31hh</guid>
      <description>&lt;p&gt;In Vesper Protocol, alien machines don't think in 0s and 1s, but in −1, 0 and +1. This tutorial explains ternary logic through the game's puzzles: how to count with three states, how ternary logic gates work, and why they trip up even experienced developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why three states instead of two?
&lt;/h2&gt;

&lt;p&gt;A conventional computer handles &lt;strong&gt;bits&lt;/strong&gt;: each memory cell is either 0 or 1. That is an engineering choice, not a law of nature. Nothing prevents you from building a machine where each cell can hold three values. Such a digit is called a &lt;strong&gt;trit&lt;/strong&gt; (short for &lt;em&gt;trinary digit&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;A trit carries more information than a bit: about 1.58 bits (that's log₂ 3). With 6 trits you can encode 3⁶ = 729 different values, versus 64 with 6 bits. It isn't just a curiosity: in 1958, Moscow State University built &lt;strong&gt;Setun&lt;/strong&gt;, a real ternary computer, of which around fifty units were produced.&lt;/p&gt;

&lt;p&gt;For Vesper Protocol, we wanted computing that feels alien while staying logical. Ternary was perfect: players already know binary, or have heard of it, and must "unlearn" it to understand the machines of the Vesper.&lt;/p&gt;

&lt;h2&gt;
  
  
  Balanced ternary: counting with −1, 0 and +1
&lt;/h2&gt;

&lt;p&gt;There are two ways to write numbers in base 3. The most intuitive one uses the digits 0, 1 and 2. The Vesper uses −1, 0 and +1 instead: this is &lt;strong&gt;balanced ternary&lt;/strong&gt;. In the game's console they are written &lt;code&gt;−&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It is still a positional system: each trit is multiplied by a power of 3, starting from the right (1, 3, 9, 27…).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+0−  =  (+1 × 9) + (0 × 3) + (−1 × 1)  =  9 + 0 − 1  =  8
−++  =  (−1 × 9) + (+1 × 3) + (+1 × 1)  = −9 + 3 + 1  = −5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two properties make this system very elegant (mathematician Donald Knuth described it as one of the prettiest number systems):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No separate sign&lt;/strong&gt;: negative numbers are written naturally, with no sign bit and no two's complement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Negating = flipping every trit&lt;/strong&gt;: &lt;code&gt;+0−&lt;/code&gt; is 8, so &lt;code&gt;−0+&lt;/code&gt; is −8. No arithmetic needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two trits cover every value from −4 to +4; three trits, from −13 to +13. That detail matters in the game: a Vesper register doesn't overflow where a binary register would.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ternary logic gates
&lt;/h2&gt;

&lt;p&gt;In logic, the three states can be read as &lt;em&gt;false&lt;/em&gt; (−1), &lt;em&gt;unknown&lt;/em&gt; (0) and &lt;em&gt;true&lt;/em&gt; (+1). This is the three-valued logic described by logician Stephen Kleene. Binary operations then have direct equivalents.&lt;/p&gt;

&lt;h3&gt;
  
  
  NEG: the inverter
&lt;/h3&gt;

&lt;p&gt;NEG swaps −1 and +1 and leaves 0 untouched. An inverted "unknown" stays unknown.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;x&lt;/th&gt;
&lt;th&gt;NEG x&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;td&gt;+1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+1&lt;/td&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  MIN and MAX: three-state AND and OR
&lt;/h3&gt;

&lt;p&gt;In binary, AND is 1 only if both inputs are 1: it's the minimum of the two. OR is 1 if either input is 1: it's the maximum. Ternary keeps exactly that idea.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;MIN (x, y)&lt;/th&gt;
&lt;th&gt;y = −1&lt;/th&gt;
&lt;th&gt;y = 0&lt;/th&gt;
&lt;th&gt;y = +1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;x = −1&lt;/td&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;x = 0&lt;/td&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;x = +1&lt;/td&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;+1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;MAX reads the same way, taking the larger value: MAX(−1, 0) = 0, MAX(0, +1) = +1. An AND is only true if everything is true, and a single "false" is enough to make it false.&lt;/p&gt;

&lt;h3&gt;
  
  
  ADD: addition modulo 3
&lt;/h3&gt;

&lt;p&gt;Adding two trits can leave the range: +1 + +1 = 2. In balanced ternary, 2 is written &lt;code&gt;+−&lt;/code&gt; (3 − 1): you keep the trit −1 and carry +1. The Vesper's virtual machine keeps only the rightmost trit, without the carry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ADD(+1, +1) = −1      ADD(−1, −1) = +1      ADD(+1, −1) = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's counter-intuitive, and that's deliberate: many puzzles rely on this "wrap-around".&lt;/p&gt;

&lt;h2&gt;
  
  
  How it becomes a puzzle in Vesper Protocol
&lt;/h2&gt;

&lt;p&gt;In the game, every door or machine reads a register. The player plugs in a console, watches the values and writes a short routine with the available instructions. Here is a typical puzzle from the first sector:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Door 12-A: opens when R0 = +1
// Allowed instructions: NEG, MAX
R0 = 0
R1 = −1

NEG R1        // R1 = +1
MAX R0, R1    // R0 = max(0, +1) = +1  → door open
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difficulty comes from the constraints: a machine only accepts a reduced instruction set, and some instructions heat up the suit. So the player looks for the shortest routine.&lt;/p&gt;

&lt;h3&gt;
  
  
  The classic trap: thinking in binary
&lt;/h3&gt;

&lt;p&gt;During our playtests, players who already code all fell into the same traps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Assuming NEG always changes the value&lt;/strong&gt;: NEG(0) = 0. A neutral register can't be inverted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reading MIN(0, +1) as "true"&lt;/strong&gt;: the result is 0. An AND with an unknown stays unknown.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting the wrap-around&lt;/strong&gt;: ADD(+1, +1) isn't +1 but −1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These mistakes are the best part of the game: players realise they can't apply their habits to a machine they don't know. That's exactly the mindset of a security auditor facing unknown firmware.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exercises: your turn
&lt;/h2&gt;

&lt;p&gt;Three short exercises to check everything is clear. Prefer hands-on? Try the &lt;a href="https://flexarion-studio.github.io/en/demo/" rel="noopener noreferrer"&gt;playable mini demo&lt;/a&gt;, with three ternary locks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is &lt;code&gt;+−0&lt;/code&gt; in decimal? — &lt;em&gt;Answer:&lt;/em&gt; 9 − 3 + 0 = &lt;strong&gt;6&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;What is MAX(NEG(+1), 0)? — &lt;em&gt;Answer:&lt;/em&gt; NEG(+1) = −1, then MAX(−1, 0) = &lt;strong&gt;0&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;How do you write 5 in balanced ternary, with three trits? — &lt;em&gt;Answer:&lt;/em&gt; &lt;code&gt;+−−&lt;/code&gt;: 9 − 3 − 1 = &lt;strong&gt;5&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Going further
&lt;/h2&gt;

&lt;p&gt;Ternary logic is at the heart of &lt;a href="https://flexarion-studio.github.io/en/vesper-protocol/" rel="noopener noreferrer"&gt;Vesper Protocol&lt;/a&gt;, our space hacking game. On the rendering side, our &lt;a href="https://flexarion-studio.github.io/en/devlog/raymarching-nebula-shader/" rel="noopener noreferrer"&gt;tutorial on raymarching a nebula&lt;/a&gt; explains how we draw the sky around Tau-Heliade. All English articles are in the &lt;a href="https://flexarion-studio.github.io/en/devlog/" rel="noopener noreferrer"&gt;Flexarion devlog&lt;/a&gt;; more articles, a lore codex and the full press kit are available &lt;a href="https://flexarion-studio.github.io/devlog/" rel="noopener noreferrer"&gt;in French&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on the &lt;a href="https://flexarion-studio.github.io/en/devlog/ternary-logic-hacking-game/" rel="noopener noreferrer"&gt;Flexarion devlog&lt;/a&gt;. Flexarion is a fictional video game studio created for a computer science student project. Text licensed under CC BY-NC 4.0.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
