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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int path[4] = {};
string S;
int IDX = 0;
int calc(int idx)
{
    IDX = idx;
    if (S[idx] - 'a' >= 0 && S[idx] - 'a' < 4)
    {
        return path[S[IDX] - 'a'];
    }
    if (S[idx] == '+')
    {
        return calc(++IDX) | calc(++IDX);
    }
    if (S[idx] == '*')
        return calc(++IDX) & calc(++IDX);
    if (S[idx] == '^')
        return calc(++IDX) ^ calc(++IDX);
    else
        return calc(++IDX);
}
int main()
{
    vector<int> ans1, ans2;
    while (1)
    {
        IDX = 0;
        cin >> S;
        if (S[0] == '.')
            break;
        string P;
        cin >> P;
        rep(i, 4) path[i] = P[i] - '0';
        int res = calc(IDX);
        ans1.push_back(res);
        int ans = 0;
        rep(i, 10000)
        {
            IDX = 0;
            string p = to_string(i);
            reverse(p.begin(), p.end());
            while (p.size() < 4)
                p.push_back('0');
            reverse(p.begin(), p.end());
            rep(j, 4) path[j] = p[j] - '0';

            if (calc(IDX) == res)
                ans++;
        }
        ans2.push_back(ans);
    }

    rep(i, ans1.size())
    {
        cout << ans1[i] << " " << ans2[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void itov(int n, vector<int> &v){
	int digit = 4;
	for(int i=digit-1; i>=0; i--){
		v[i] = n%10;
		n /= 10;
	}
}

int gethash(string &s, int &p, vector<int> &v){
	if(s[p] != '['){
		return v[s[p++] -'a'];
	}
	p++;
	char op = s[p++];
	int a = gethash(s, p, v);
	int b = gethash(s, p, v);
	p++;
	if(op == '+') return a|b;
	if(op == '*') return a&b;
	return a^b;
}

int main(){
	while(1){
		string s;
		cin >> s;
		if(s == ".") break;
		int pass;
		cin >> pass;

		vector<int> hashv(10000);
		vector<int> v(4);
		for(int i=0; i<10000; i++){
			itov(i, v);
			int p = 0;
			hashv[i] = gethash(s, p, v);
		}

		int count = 0;
		for(int i=0; i<10000; i++){
			if(hashv[pass] == hashv[i]) count++;
		}
		cout << hashv[pass] << " " << count << endl;
	}
    return 0;
}

C++: #include<algorithm>
#include<climits>
#include<cmath>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int f(const string &s, unordered_map<char, int> &mp){
    stack<int> st;
    rrep(i, s.size()){
        if(s[i] == '[' || s[i] == ']'){
            continue;
        }
        if('a' <= s[i] && s[i] <= 'd'){
            st.push(mp[s[i]]);
        }else if(s[i] == '+'){
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a | b);
        }else if(s[i] == '*'){
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a & b);
        }else{
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a ^ b);
        }
    }

    return st.top();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, p;
    while(cin >> s >> p){
        unordered_map<char, int> mp;
        rep(i, 4){
            mp['a' + i] = p[i] - '0';
        }

        int myHash = f(s, mp);

        int cnt = 0;
        rep(a, 10){
            mp['a'] = a;
            rep(b, 10){
                mp['b'] = b;
                rep(c, 10){
                    mp['c'] = c;
                    rep(d, 10){
                        mp['d'] = d;
                        if(f(s, mp) == myHash){
                            ++cnt;
                        }
                    }
                }
            }
        }

        cout << myHash << " " << cnt << endl;
    }

    return 0;
}