Game Theory in Balanced Ternary Numeral System | ( Moving 3 k steps at a time ) | C ++ implementation of the approach ; Function that returns true if the game cannot be won ; Driver code ; Common length
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDefeat ( string s1 , string s2 , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( ( s1 [ i ] == '0' && s2 [ i ] == '1' ) || ( s1 [ i ] == '1' && s2 [ i ] == '0' ) ) continue ; else if ( ( s1 [ i ] == '0' && s2 [ i ] == ' Z ' ) || ( s1 [ i ] == ' Z ' && s2 [ i ] == '0' ) ) continue ; else { return true ; } } return false ; } int main ( ) { string s1 = { "01001101ZZ " } ; string s2 = { "10Z1001000" } ; int n = 10 ; if ( isDefeat ( s1 , s2 , n ) ) cout << " Defeat " ; else cout << " Victory " ; return 0 ; }