Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		S := io.NextLine()
		if S == "." {
			break
		}
		P := io.NextLine()
		i := 0
		val := hash(S, P, &i)
		cnt := 0
		for j := 0; j < 10000; j++ {
			i = 0
			if hash(S, fmt.Sprintf("%04d", j), &i) == val {
				cnt++
			}
		}
		io.Println(val, cnt)
	}
}

func hash(s, n string, i *int) int {
	if s[*i] == '[' {
		*i++
		switch s[*i] {
		case '+':
			*i++
			l := hash(s, n, i)
			r := hash(s, n, i)
			*i++
			return l | r
		case '*':
			*i++
			l := hash(s, n, i)
			r := hash(s, n, i)
			*i++
			return l & r
		case '^':
			*i++
			l := hash(s, n, i)
			r := hash(s, n, i)
			*i++
			return l ^ r
		}
	}
	x := int(n[s[*i]-'a'] - '0')
	*i++
	return x
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

bool is_operand(char c) {
  if(c == '+' || c == '*' || c == '^') return true;
  else return false;
}

int to_number(char num, int a, int b, int c, int d){
  if(num == 'a') return a;
  else if(num == 'b') return b;
  else if(num == 'c') return c;
  else if(num == 'd') return d;
}

int calc(int x, int y, char ope) {
  if(ope == '+') return x | y;
  else if(ope == '*') return x & y;
  else if(ope == '^') return x ^ y;
}

int simulate(string S, int _a, int _b, int _c, int _d) {
  stack<int> stk;
  
  for(int i = 0; i < S.size(); i++) {
    char c = S[i];
    if('a' <= c && c <= 'd') stk.push(to_number(c, _a, _b, _c, _d));
    else if(is_operand(c)) {
      int x = stk.top(); stk.pop();
      int y = stk.top(); stk.pop();
      stk.push(calc(x, y, c));
    }
  }
  return stk.top();
}

void solve(string S, string P) {
  int hash_number = simulate(S, P[0] - '0', P[1] - '0', P[2] - '0', P[3] - '0');

  int hash_count = 0;
  for(int a = 0; a < 10; a++) {
    for(int b = 0; b < 10; b++) {
      for(int c = 0; c < 10; c++) {
	for(int d = 0; d < 10; d++) {
	  if(hash_number == simulate(S, a, b, c, d)) hash_count++;
	}
      }
    }
  }
  cout << hash_number << " " << hash_count << endl;
}

int main(){
  string S, P;
  while(cin >> S, S != ".") {
    cin >> P;
    reverse(all(S));
    solve(S, P);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef string::iterator state;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
string pass;

string S;
int f(state &itr) {
    if(*itr == '[') {
        itr++;
        char operation = *itr;
        itr++;
        int a = f(itr);
        int b = f(itr);
        itr++;
        if(operation == '+') return a | b;
        if(operation == '*') return a & b;
        if(operation == '^') return a ^ b;
    }
    char moji = *itr;
    itr++;
    if(moji == 'a') return pass[0] - '0';
    if(moji == 'b') return pass[1] - '0';
    if(moji == 'c') return pass[2] - '0';
    if(moji == 'd') return pass[3] - '0';
}
int myhash;
int ans;
void g() {
    if(pass.size() == 4) {
        auto itr = S.begin();
        if(f(itr) == myhash) ans++;
        return;
    }
    for(char moji = '0'; moji <= '9'; moji++) {
        pass.push_back(moji);
        g();
        pass.pop_back();
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> S;
        if(S == ".") break;
        cin >> pass;
        state itr = S.begin();
        myhash = f(itr);
        ans = 0;
        pass = "";
        g();
        cout << myhash << " " << ans << endl;
    }
    return 0;
}