-
Notifications
You must be signed in to change notification settings - Fork 0
/
prime_birthday.sf
82 lines (67 loc) · 1.42 KB
/
prime_birthday.sf
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/ruby
# Daniel "Trizen" Șuteu
# Date: 11 October 2018
# https://github.com/trizen
# Find the most "prime" birthday:
#
# Y / M / D
#
# where all the following expressions are prime numbers:
#
# D
# D - M
#
# D + M
# D + Y
#
# Y * M - D
# Y + M + 1
#
# Y*D + M + 1
# Y*D - M - 1
#
# Y + M*D - 1
# Y - M*D + 1
#
# Y*M*D - 1
# Y*M*D + 1
#
# Y*D - 1
# Y*M + 1
# M*D - 1
# M*D + 1
#
# Y + M + D
# Y - M - D
# Y + M - D
# Y - M + D
# Only one such birthday exists between the years 1 and 10000, and that is:
# Y = 1980
# M = 12
# D = 19
# Jake Gyllenhaal, famous American actor and producer, was born on this date.
for y in (1900..2018), m in (1..12), d in (1..31) {
d.is_prime || next
d - m -> is_prime || next
d + m -> is_prime || next
d + y -> is_prime || next
y * m - d -> is_prime || next
y + m + 1 -> is_prime || next
y*d + m + 1 -> is_prime || next
y*d - m - 1 -> is_prime || next
y + m*d - 1 -> is_prime || next
y - m*d + 1 -> is_prime || next
y * m * d - 1 -> is_prime || next
y * m * d + 1 -> is_prime || next
y * d - 1 -> is_prime || next
y * m + 1 -> is_prime || next
m * d - 1 -> is_prime || next
m * d + 1 -> is_prime || next
y + m + d -> is_prime || next
y - m - d -> is_prime || next
y + m - d -> is_prime || next
y - m + d -> is_prime || next
say "#{y} #{m} #{d}"
}
__END__
1980 12 19