Last active
July 10, 2018 00:00
-
-
Save Akiyah/4c207505f80b8f4a5749f00d5ba2b9dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gmp) | |
library(gtools) | |
MARIO <- paste0( | |
" ...", | |
" ***** ...", | |
" *********..", | |
" @@@..@. @@@", | |
" @.@...@...@@", | |
" @.@@...@...@", | |
" @@....@@@@@ ", | |
" .......@ ", | |
" @@@@@*@@@*@ ", | |
" @@@@@@@*@@@* @", | |
"..@@@@@@***** @", | |
"... *@***.*.*@@", | |
" . @ *********@@", | |
" @@@*********@@", | |
" @@@******* ", | |
" @ **** " | |
) | |
patterns <- permutations(n=10,r=4,v=0:9) | |
for (i in 1:nrow(patterns)) { | |
s <- MARIO | |
s <- gsub(" ", patterns[i,1], s) | |
s <- gsub("\\@", patterns[i,2], s) | |
s <- gsub("\\.", patterns[i,3], s) | |
s <- gsub("\\*", patterns[i,4], s) | |
if (isprime(s)) { | |
print(patterns[i,]) | |
print(s) | |
cat(paste(substring(s, 1+(0:15)*16, (1:16)*16), collapse="\n")) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://ja.wikipedia.org/wiki/%E3%83%9F%E3%83%A9%E3%83%BC%E2%80%93%E3%83%A9%E3%83%93%E3%83%B3%E7%B4%A0%E6%95%B0%E5%88%A4%E5%AE%9A%E6%B3%95 | |
class Integer | |
def prime? | |
n = self.abs() | |
return true if n == 2 | |
return false if n == 1 || n & 1 == 0 | |
d = n-1 | |
d >>= 1 while d & 1 == 0 | |
20.times do # 20 は上の説明の k に相当 | |
a = rand(n-2) + 1 | |
t = d | |
y = ModMath.pow(a,t,n) # 実装コードは下にある | |
while t != n-1 && y != 1 && y != n-1 | |
y = (y * y) % n | |
t <<= 1 | |
end | |
return false if y != n-1 && t & 1 == 0 | |
end | |
return true | |
end | |
end | |
module ModMath | |
def ModMath.pow(base, power, mod) | |
result = 1 | |
while power > 0 | |
result = (result * base) % mod if power & 1 == 1 | |
base = (base * base) % mod | |
power >>= 1; | |
end | |
result | |
end | |
end | |
Ruby = [ | |
" o o o o ", | |
" o o o o o ", | |
"ooooooooooo o o o oooooooo b ", | |
" o ooooooooo o o b ", | |
" ooooooooo o ooooo b ", | |
" o ooooooooooo o o r rr bbbb ", | |
"ooooooooooo o o ooo ooooo rr r b b", | |
" o o oo o o o o o r b b", | |
" oo o o oo oo o o o o d r b b", | |
"oo o o o oo o o ooooo ddd r b b", | |
" o o oo o o d r bbbb ", | |
" ooooo oo oooo o ooooooo " | |
].join("_") | |
(0..9).to_a.permutation(3).each do |o, drb, space| | |
str = Ruby. | |
gsub("o", o.to_s). | |
gsub("d", drb.to_s). | |
gsub("r", drb.to_s). | |
gsub("b", drb.to_s). | |
gsub(" ", space.to_s) | |
n = str.to_i | |
if n.prime? | |
p [o, drb, space] | |
puts "n = #{n}" | |
puts str | |
puts str.length | |
puts str.split("_").join("\n").split("").join(",") | |
end | |
end | |
#=> | |
" | |
1,1,1,1,1,7,1,1,1,1,1,1,1,1,1,1,7,1,1,1,1,1,1,1,1,1,1,1,1,7,1,1,1,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
1,1,1,1,1,7,1,1,1,1,1,1,1,1,1,1,7,1,1,7,1,1,1,1,1,1,1,1,1,7,1,1,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
7,7,7,7,7,7,7,7,7,7,7,1,1,1,1,7,1,1,1,1,7,1,1,1,7,1,1,7,7,7,7,7,7,7,7,1,1,1,1,1,1,1,1,1,1,1,1,1,9,1,1,1,1, | |
1,1,1,1,1,7,1,1,1,1,1,1,1,7,7,7,7,7,7,7,7,7,1,1,1,7,1,1,1,1,1,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,1,1,1,1, | |
1,7,7,7,7,7,7,7,7,7,1,1,1,1,1,1,1,7,1,1,1,1,1,1,1,1,1,1,1,7,7,7,7,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,1,1,1,1, | |
1,1,1,1,1,7,1,1,1,1,1,1,7,7,7,7,7,7,7,7,7,7,7,1,1,1,1,1,1,7,1,1,1,7,1,1,1,1,1,1,1,1,9,1,9,9,1,1,9,9,9,9,1, | |
7,7,7,7,7,7,7,7,7,7,7,1,1,1,1,1,7,1,1,1,7,1,1,1,7,7,7,1,1,7,7,7,7,7,1,1,1,1,1,1,1,1,9,9,1,1,9,1,9,1,1,1,9, | |
1,1,1,1,7,1,7,1,1,1,1,1,1,1,7,7,1,1,1,7,1,7,1,1,1,1,7,1,1,7,1,1,1,7,1,1,1,1,1,1,1,1,9,1,1,1,1,1,9,1,1,1,9, | |
1,1,7,7,1,1,7,1,1,1,7,1,7,7,1,1,1,7,7,1,1,1,7,1,1,1,7,1,1,7,1,1,1,7,1,1,1,1,9,1,1,1,9,1,1,1,1,1,9,1,1,1,9, | |
7,7,1,7,1,1,1,7,1,7,1,1,1,1,1,7,7,1,1,1,7,1,1,1,1,1,7,1,1,7,7,7,7,7,1,1,1,9,9,9,1,1,9,1,1,1,1,1,9,1,1,1,9, | |
1,1,1,7,1,1,1,1,7,1,1,1,1,1,1,1,1,1,7,7,1,1,1,1,1,7,1,7,1,1,1,1,1,1,1,1,1,1,9,1,1,1,9,1,1,1,1,1,9,9,9,9,1, | |
1,7,7,7,7,7,1,1,1,7,7,1,1,1,7,7,7,7,1,1,1,1,1,1,7,1,1,1,7,7,7,7,7,7,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://ja.wikipedia.org/wiki/%E3%83%9F%E3%83%A9%E3%83%BC%E2%80%93%E3%83%A9%E3%83%93%E3%83%B3%E7%B4%A0%E6%95%B0%E5%88%A4%E5%AE%9A%E6%B3%95 | |
class Integer | |
def prime? | |
n = self.abs() | |
return true if n == 2 | |
return false if n == 1 || n & 1 == 0 | |
d = n-1 | |
d >>= 1 while d & 1 == 0 | |
20.times do # 20 は上の説明の k に相当 | |
a = rand(n-2) + 1 | |
t = d | |
y = ModMath.pow(a,t,n) # 実装コードは下にある | |
while t != n-1 && y != 1 && y != n-1 | |
y = (y * y) % n | |
t <<= 1 | |
end | |
return false if y != n-1 && t & 1 == 0 | |
end | |
return true | |
end | |
end | |
module ModMath | |
def ModMath.pow(base, power, mod) | |
result = 1 | |
while power > 0 | |
result = (result * base) % mod if power & 1 == 1 | |
base = (base * base) % mod | |
power >>= 1; | |
end | |
result | |
end | |
end | |
Ruby = [ | |
"RR b ", | |
"R R b ", | |
"R R u u bb y y", | |
"RR u u b b y y", | |
"R R u u b b yy", | |
"R R uuu bb y", | |
" yy " | |
].join("_") | |
(0..9).to_a.permutation(2).each do |a, b| | |
str = Ruby.gsub(/[Ruby]/, a.to_s).gsub(" ", b.to_s) | |
n = str.to_i | |
if n.prime? | |
puts "n = #{n}" | |
puts str.split("_").join("\n") | |
end | |
end | |
#=> | |
# n = 443333334333333434333334333333434343434433434443343434343434434343434343344434344434433334333333333333443 | |
# 443333334333333 | |
# 434333334333333 | |
# 434343434433434 | |
# 443343434343434 | |
# 434343434343344 | |
# 434344434433334 | |
# 333333333333443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gmp) | |
library(gtools) | |
SUPER_MARIO <- paste0( | |
" ... ", | |
" ..*..", | |
" @@@@@..**.", | |
" @@@@@@@.....", | |
" @@@@@@@@*****", | |
" @@@@@@@@@@@**", | |
" ***..*...****", | |
" *..*..*.....**", | |
" *..**........*", | |
" *..**...*....*", | |
" **.....******* ", | |
" ****....****.* ", | |
" **........** ", | |
" @@@@**@**** ", | |
" ******@@*@*** ", | |
"********@**@** ", | |
"********@@*@* ", | |
"**..****@@**@ ", | |
"*....**@@@@*. ", | |
".....*@@@.@@@ ", | |
".....@@@@@@@@ ", | |
". ..@@@@@@@@@ *", | |
" ..@@@@@@@@@@ **", | |
" @@@@@@@@@****", | |
" *@@@@@@@@****", | |
"***@**@@@@@@****", | |
"***@@@**@@@@****", | |
"***@@@@@ @@****", | |
"***@@@@@ ", | |
"***@@@@ ", | |
"** ", | |
"* " | |
) | |
patterns <- permutations(n=10,r=4,v=0:9) | |
for (i in 1:nrow(patterns)) { | |
s <- SUPER_MARIO | |
s <- gsub(" ", patterns[i,1], s) | |
s <- gsub("\\@", patterns[i,2], s) | |
s <- gsub("\\.", patterns[i,3], s) | |
s <- gsub("\\*", patterns[i,4], s) | |
if (isprime(s)) { | |
print(patterns[i,]) | |
print(s) | |
cat(paste(substring(s, 1+(0:31)*16, (1:32)*16), collapse="\n")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment