Factorial primes: Difference between revisions
Content deleted Content added
→{{header|ALGOL 68}}: Tweak again |
Added LOLCODE |
||
Line 94:
(i.28x here would have given us an eleventh prime, but the task asked for the first 10, and the stretch goal requires considerable patience.)
=={{header|LOLCODE}}==
<lang lolcode>OBTW find some factorial primes - primes that are f - 1 or f + 1
for some factorial f
TLDR
HAI 1.3
HOW IZ I TESTIN YR P BTW PRIMALITY TEST WITH TRIAL DIVISHUN
DIFFRINT 3 AN SMALLR OF 3 AN P, O RLY?
YA RLY
FOUND YR BOTH SAEM P AN 2
NO WAI
BOTH SAEM 0 AN MOD OF P AN 2, O RLY?
YA RLY
FOUND YR FAIL
NO WAI
I HAS A IZPRIME ITZ WIN
I HAS A N ITZ 3
I HAS A NSKWARED ITZ 9
IM IN YR PRIMELOOP UPPIN YR I TIL DIFFRINT NSKWARED AN SMALLR OF P AN NSKWARED
DIFFRINT 0 MOD OF P AN N, O RLY?
YA RLY
N R SUM OF N AN 2
NSKWARED R PRODUKT OF N AN N
NO WAI
IZPRIME R FAIL
NSKWARED R SUM OF P AN 1
OIC
IM OUTTA YR PRIMELOOP
FOUND YR IZPRIME
OIC
OIC
IF U SAY SO
HOW IZ I PADDIN YR FPNUMBR
I HAS A PAD ITZ ""
BOTH SAEM FPNUMBR AN SMALLR OF FPNUMBR AN 9, O RLY?
YA RLY
PAD R " "
OIC
FOUND YR SMOOSH PAD AN FPNUMBR MKAY
IF U SAY SO
HOW IZ I SHOWIN YR FPNUMBR AN YR N AN YR HOWDIFF AN YR FP
VISIBLE SMOOSH I IZ PADDIN YR FPNUMBR MKAY ...
AN ":: " AN I IZ PADDIN YR N MKAY ...
AN "! " AN HOWDIFF AN " 1 = " AN FP ...
MKAY
IF U SAY SO
I HAS A F ITZ 1
I HAS A N ITZ 0
I HAS A KOWNT ITZ 0
IM IN YR FPLOOP UPPIN YR I TIL BOTH SAEM KOWNT AN 10
N R SUM OF N AN 1
F R PRODUKT OF F AN N
I IZ TESTIN YR DIFF OF F AN 1 MKAY, O RLY?
YA RLY
KOWNT R SUM OF KOWNT AN 1
I IZ SHOWIN YR KOWNT AN YR N AN YR "-" AN YR DIFF OF F AN 1 MKAY
OIC
I IZ TESTIN YR SUM OF F AN 1 MKAY, O RLY?
YA RLY
KOWNT R SUM OF KOWNT AN 1
I IZ SHOWIN YR KOWNT AN YR N AN YR "+" AN YR SUM OF F AN 1 MKAY
OIC
IM OUTTA YR FPLOOP
KTHXBYE
</lang>
{{out}}
<pre>
1: 1! + 1 = 2
2: 2! + 1 = 3
3: 3! - 1 = 5
4: 3! + 1 = 7
5: 4! - 1 = 23
6: 6! - 1 = 719
7: 7! - 1 = 5039
8: 11! + 1 = 39916801
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199
</pre>
=={{header|Raku}}==
|