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;

int solve(string s, int p[4]){
    stack<char> op, num;
    for(auto c : s){
        if(c=='[')continue;
        if(c=='+' || c=='*' || c=='^'){
            op.push(c);
        }
        else if(c==']'){
            int a, b;
            a = num.top(); num.pop();
            b = num.top(); num.pop();
            if(op.top()=='+'){
                a |= b;
            }
            if(op.top()=='*'){
                a &= b;
            }
            if(op.top()=='^'){
                a ^= b;
            }
            num.push(a);
            op.pop();
        }
        else{
            num.push(p[c-'a']);
        }
    }
    return num.top();
}

int main() {
    string s, p;
    while(cin >> s){
        if(s==".")break;
        cin >> p;
        int a[4], h, cnt = 0;
        for(int i=0;i<4;i++){
            a[i] = p[i]-'0';
        }
        h = solve(s, a);
        for(int i=0;i<10000;i++){
            int t = i;
            for(int j=0;j<4;j++){
                a[j] = t%10;
                t /= 10;
            }
            if(solve(s, a)==h)cnt++;
        }
        cout << h << " " << cnt << endl;
    }
    return 0;
}

C++: #include<string>
#include<iostream>
#include<cctype>
typedef long long ll;
using namespace std;
typedef string::const_iterator State;

string s, pass;
ll a, b, c, d;

ll solve(State &begin) {
  ll ans = 0;
  if (*begin == 'a') ans = a, begin++;
  else if (*begin == 'b') ans = b, begin++;
  else if (*begin == 'c') ans = c, begin++;
  else if (*begin == 'd') ans = d, begin++;
  else if (*begin == '[') {
    begin++;
    if (*begin == '+') begin++, ans = solve(begin) | solve(begin);
    else if (*begin == '*') begin++, ans = solve(begin) & solve(begin);
    else if (*begin == '^') begin++, ans = solve(begin) ^ solve(begin);
    begin++;
  }
  return ans;
}

int main() {
  while (cin >> s, s != ".") {
    cin >> pass;
    a = pass[0] - '0';
    b = pass[1] - '0';
    c = pass[2] - '0';
    d = pass[3] - '0';
    State state = s.begin();
    ll result = solve(state), ans = 0;
    for (a = 0; a < 10; a++) for (b = 0; b < 10; b++) {
      for (c = 0; c < 10; c++) for (d = 0; d < 10; d++) {
        state = s.begin();
        if (result == solve(state)) ans++;
      }
    }
    cout << result << " " << ans << endl;
  }
}

C++: #include "bits/stdc++.h"
using namespace std;

string s;
int ind=0;
//'['を検知したら開始
int saiki(int a,int b,int c,int d)
{
	int ret=0;
	if(s[0]!='[')
	{
		switch(s[0])
		{
			case 'a':
			return a;
			case 'b':
			return b;
			case 'c':
			return c;
			case 'd':
			return d;
		}
	}
	ind++;
	//cerr<<ind<<" "<<s[ind]<<endl;
	int op;//+...0 ^...1 *...2
	//operatorの検出
	if(s[ind]=='+')
		op=0;
	else if(s[ind]=='^')
		op=1;
	else
		op=2;
	ind++;
	//数字の検出
	int num[2];
	for(int i=0;i<2;i++)
	{
		if(s[ind]=='[')
			num[i]=saiki(a,b,c,d);
		else{
			switch(s[ind])
			{
				case 'a':
				num[i]=a;
				break;
				case 'b':
				num[i]=b;
				break;
				case 'c':
				num[i]=c;
				break;
				case 'd':
				num[i]=d;
			}
			ind++;
		}
	}
	if(op==0)
		ret=(num[0]|num[1]);
	else if(op==1)
		ret=(num[0]^num[1]);
	else
		ret=(num[0]&num[1]);
	ind++;
	return ret;
}

int main()
{
	while(1)
	{
		cin>>s;
		if(s[0]=='.')
			break;
		string p;
		cin>>p;
		ind=0;
		int hash=saiki(p[0]-'0',p[1]-'0',p[2]-'0',p[3]-'0');
		int ans=0;
		cout<<hash<<" ";
		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++)
					{
						ind=0;
						int tmp=saiki(a,b,c,d);
						if(tmp==hash)
							ans++;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}