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 <string>
#include <stack>
using namespace std;

string s; int p;

int expression(int p, string &s) {
	int i;
	int d = p % 10;
	int c = (p / 10) % 10;
	int b = (p / 100) % 10;
	int a = (p / 1000) % 10;
	
	stack<int> stk;
	int x, y;
	
	for (i = s.length() - 1; i >= 0; i--) {
		if (s[i] == '[' || s[i] == ']') continue;
		if (s[i] == 'a') stk.push(a);
		if (s[i] == 'b') stk.push(b);
		if (s[i] == 'c') stk.push(c);
		if (s[i] == 'd') stk.push(d);
		if (s[i] == '+' || s[i] == '*' || s[i] == '^') {
			x = stk.top(); stk.pop(); y = stk.top(); stk.pop();
		}
		if (s[i] == '+') stk.push(x | y);
		if (s[i] == '*') stk.push(x & y);
		if (s[i] == '^') stk.push(x ^ y);
	}
	return stk.top();
}

int main() {
	while (cin >> s) {
		if (s == ".") break;
		cin >> p;
		int hashNum = expression(p, s);
		int cnt = 0;
		for (int i = 0; i < 10000; i++) if (expression(i, s) == hashNum) cnt++;
		cout << hashNum << " " << cnt << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;
class ParseError
{
};
int expr(State &begin);
int a, b, c, d;
int main()
{
    string S, P;
    while (cin >> S >> P)
    {
        if (S == ".")
            return 0;
        map<int, int> mp;
        State s = S.begin();
        a = P[0] - '0';
        b = P[1] - '0';
        c = P[2] - '0';
        d = P[3] - '0';
        int x = expr(s);
        int cnt = 0;
        for (int i = 0; i < 10000; i++)
        {
            s = S.begin();
            int k = i;
            a = k / 1000;
            b = (k / 100) % 10;
            c = (k / 10) % 10;
            d = k % 10;
            if (x == expr(s))
                cnt++;
        }
        cout << x << " " << cnt << endl;
    }
}
//パースして、その評価結果を返す。
int expr(State &begin)
{
    int res;
    if (*begin == '[')
    {
        begin++;
        int x, y;
        if (*begin == '+')
        {
            begin++;
            x = expr(begin);
            y = expr(begin);
            res = x | y;
        }
        else if (*begin == '*')
        {
            begin++;
            x = expr(begin);
            y = expr(begin);
            res = x & y;
        }
        else if (*begin == '^')
        {
            begin++;
            x = expr(begin);
            y = expr(begin);
            res = x ^ y;
        }
        begin++;
        return res;
    }
    if (*begin == 'a')
        res = a;
    else if (*begin == 'b')
        res = b;
    else if (*begin == 'c')
        res = c;
    else if (*begin == 'd')
        res = d;

    begin++;
    return res;
}