File: calc_cache.pl

package info (click to toggle)
libquantum-entanglement-perl 0.32-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 104 kB
  • ctags: 41
  • sloc: perl: 695; makefile: 52
file content (34 lines) | stat: -rwxr-xr-x 1,004 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl -w

use Quantum::Entanglement qw(:DEFAULT);

# list of possible input values for our computationally slow function:

my @inputsA = (1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,10);
my @inputsB = (1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,10);

# make a superposition of these (we don't need to worry about probs here...)

my $inputsA = entangle( @inputsA );
my $inputsB = entangle( @inputsB );

# calculate our nasty function, save the entangled answer
# this should have many steps and be nasty, but that'll take too long

my $answer = $inputsA * $inputsB;

# store the global state space

my $state = save_state($inputsA, $inputsB, $answer);

# set up "conform" mode
$Quantum::Entanglement::conform = 1;

print "Enter two numbers between 1 and 10 to multiply\n";
while (<>) {
  last unless /(\d+)[^\d]*(\d+)/;
  1 if $inputsA == $1; # yes, really ==, just in void context
  1 if $inputsB == $2;
  print "\n$1 * $2 = $answer\n";
  ($inputsA, $inputsB, $answer) = $state->restore_state; # again!
}