-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime_number.exem
54 lines (45 loc) · 1.83 KB
/
prime_number.exem
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
"A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller
natural numbers." Eg, 2 is prime because it is >1 and cannot be formed by multiplying two /smaller/ positive ints.
This problem matches better to a (unavailable) WHILE loop solution. In the meantime, replace the induced code's
end of FOR range, currently 6, with "inp". 11/14/19
The below <2 example is commented out because it isn't helpful to E. That's because it shows only 1 iteration while multiple need tracing for E to create a loop.
<2
i1==inp
inp>1
j==2
j==inp
>True
Without a WHILE in Exemplar, this example requires the j loop to continue to 1009, way past the actual 5 termination value.
<1009
>True
Note that we aren't going for maximum algorithmic efficiency in what the user specifies. Hopefully, E can optimize that once it has a correct algorithm but in any case, correctness and usually, programmer time, are more important than execution time. 7/31/2020
"""
<1008 # A stub only considered for testing, not function synthesis.
>False
<0
i1==inp
inp <= 1 # I.e., because inp is <=1, we
>False # return False.
<1
i1==inp
inp <= 1 # Ditto.
>False
<3
>True
<4
i1==inp # Renaming i1 is a good (often necessary) practice.
inp > 1
j == 2 # FOR loop (and divisor) set up but it has no iterations in this example
inp % j == 0 # because inp gets divided evenly.
>False # And so we have an answer: not prime.
<5
i1==inp
inp > 1 # Since inp is > 1, the following (j) loop is reached.
j==2
# inp % j != 0, the earlier condition NOTed, is *not* traced here because that truth does not trigger a divergent path.
j==3 # j is simply incremented,
j==4
j==5
j==inp # until it reaches the value of inp,
>True # at which point we conclude that inp is prime.