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;

char *p;
int a, b, c, d;
string s;

int solve(){
    if(*p == 'a'){
        ++p; return a;
    }
    if(*p == 'b'){
        ++p; return b;
    }
    if(*p == 'c'){
        ++p; return c;
    }
    if(*p == 'd'){
        ++p; return d;
    }
    ++p; // [
    char op = *p; ++p;
    int x = solve();
    int y = solve();
    ++p; //]
    if(op == '+') return x | y;
    if(op == '*') return x & y;
    if(op == '^') return x ^ y;
}



int calc(int v){
    a = v/1000;
    b = v / 100 % 10;
    c = v / 10 % 10;
    d = v%10;
    p = &s[0];
    return solve();
}


int main(){
    while(cin >> s, s != "."){
        int v;
        cin >> v;
        int h = calc(v);
        int c = 0;
        for(int i = 0; i < 10000; ++i){
            if(h == calc(i)) c++;
        }
        cout << h << " " << c << endl;
    }
}

C++: #include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

int fun(string s, string t){
    int n = s.length();
    stack<int> x;
    for(int i = 0; i < n; i++){
        if(s[i] == '[' || s[i] == ']')  continue;
        if(inRange(s[i], 'a', 'd')){
            x.push(t[s[i]-'a']-'0');
            continue;
        }
        int j = x.top(); x.pop();
        int k = x.top(); x.pop();
        if(s[i] == '+'){
            x.push(j|k);
        }else if(s[i] == '*'){
            x.push(j&k);
        }else if(s[i] == '^'){
            x.push(j^k);
        }
    }
    return x.top();
}

int main(){
    string s, p;
    while(cin >> s, s != "."){
        reverse(s.begin(), s.end());
        cin >> p;
        int h = fun(s, p);
        int cnt = 0;
        for(int i = 0; i <= 9999; i++){
            string t = to_string(i);
            while(t.size() < 4) t = "0" + t;
            if(fun(s, t) == h)    cnt++;
        }
        cout << h << " " << cnt << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

string s,t;
map<char,int>mp;
int now;

int dfs(){
	if('a'<=s[now]&&s[now]<='d'){
		now++;
		return t[mp[s[now-1]]]-'0';
	}
	int ret = 0;
	now++;
	int kigou = mp[s[now]];
	now++;
	int a = dfs();
	int b = dfs();
	if(kigou==0)ret = a|b;
	else if(kigou==1)ret = a&b;
	else ret = a^b;
	now++;
	return ret;
}


pair<int,int>solve(){
	now = 0;
	int hash = dfs();
	int cnt = 0;
	rep(i,0,10){
		rep(j,0,10){
			rep(k,0,10){
				rep(l,0,10){
					t="";
					t+=i+'0';
					t+=j+'0';
					t+=k+'0';
					t+=l+'0';
					now=0;
					int gethash = dfs();
					if(gethash==hash)cnt++;
				}
			}
		}
	}
	return {hash,cnt};
}
 
signed main(){
	IOS();
	vector<pair<int,int>>ans;
	rep(i,0,4)mp['a'+i]=i;
	mp['+']=0;
	mp['*']=1;
	mp['^']=2;
	while(1){
		cin>>s;
		if(s==".")break;
		cin>>t;
		ans.push_back(solve());
	}
	for(auto e:ans){
		cout<<e.fi<<" "<<e.se<<endl;
	}
}

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

unsigned int get(unsigned int k,char c){
	for(char i='d';i>c;i--)
		if(i!=c)k/=10;
	return k%10;
}
char* skip(char *s){
	int cnt=0;
	while(1){
		if(*s=='[')cnt++;
		if(*s==']')cnt--;
		if(cnt==0)break;
		s++;
	}
	s++;
	return s;
}
unsigned int f(char *s,unsigned int k){
	if(*s=='['){
		char *s1=s+2;
		char *s2=skip(s1);
		unsigned int l=f(s1,k),r=f(s2,k);
		if(s[1]=='+')
			return l|r;
		else if(s[1]=='*')
			return l&r;
		else return l^r;
	}else return get(k,*s);
}
int main(){
	char s[255];
	while(scanf(" %s",s),s[0]!='.'){
		unsigned int k;
		scanf("%u",&k);
		unsigned int hk=f(s,k),cnt=0;
		for(unsigned int i=0;i<=9999;i++){
			unsigned int hi=f(s,i);
			if(hk==hi)cnt++;
		}
		printf("%u %u\n",hk,cnt);
	}
	return 0;
}