Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
37
Task/Magic-constant/C-sharp/magic-constant.cs
Normal file
37
Task/Magic-constant/C-sharp/magic-constant.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
|
||||
public class MagicConstant {
|
||||
|
||||
private const int OrderFirstMagicSquare = 3;
|
||||
|
||||
public static void Main(string[] args) {
|
||||
Console.WriteLine("The first 20 magic constants:");
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
Console.Write(" " + MagicConstantValue(Order(i)));
|
||||
}
|
||||
Console.WriteLine("\n");
|
||||
|
||||
Console.WriteLine("The 1,000th magic constant: " + MagicConstantValue(Order(1_000)) + "\n");
|
||||
|
||||
Console.WriteLine("Order of the smallest magic square whose constant is greater than:");
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
string powerOf10 = "10^" + i + ":";
|
||||
Console.WriteLine($"{powerOf10,6}{MinimumOrder(i),8}");
|
||||
}
|
||||
}
|
||||
|
||||
// Return the magic constant for a magic square of the given order
|
||||
private static int MagicConstantValue(int n) {
|
||||
return n * (n * n + 1) / 2;
|
||||
}
|
||||
|
||||
// Return the smallest order of a magic square such that its magic constant is greater than 10 to the given power
|
||||
private static int MinimumOrder(int n) {
|
||||
return (int)Math.Exp((Math.Log(2.0)+ n * Math.Log(10.0)) / 3) + 1;
|
||||
}
|
||||
|
||||
// Return the order of the magic square at the given index
|
||||
private static int Order(int index) {
|
||||
return OrderFirstMagicSquare + index - 1;
|
||||
}
|
||||
}
|
||||
22
Task/Magic-constant/EasyLang/magic-constant.easy
Normal file
22
Task/Magic-constant/EasyLang/magic-constant.easy
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
func a n .
|
||||
n += 2
|
||||
return n * (n * n + 1) / 2
|
||||
.
|
||||
func inva x .
|
||||
while k * (k * k + 1) / 2 + 2 < x
|
||||
k += 1
|
||||
.
|
||||
return k
|
||||
.
|
||||
write "The first 20 magic constants: "
|
||||
for n to 20
|
||||
write a n & " "
|
||||
.
|
||||
print ""
|
||||
print ""
|
||||
print "The 1,000th magic constant: " & a 1000
|
||||
print ""
|
||||
print "Smallest magic square with constant greater than:"
|
||||
for e to 10
|
||||
print "10^" & e & ": " & inva pow 10 e
|
||||
.
|
||||
Loading…
Add table
Add a link
Reference in a new issue