Skip to content

Commit

Permalink
Solve p836 in all languages
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 30, 2024
1 parent 342935a commit 56d0505
Show file tree
Hide file tree
Showing 46 changed files with 323 additions and 67 deletions.
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,29 @@ LivInTheLookingGlass’s Project Euler solutions
+------------+-------------------------+--------+-------------------+
| Language | Version | Solved | Status |
+============+=========================+========+===================+
| C | C99+ in: ``gcc``, |br| | 19 | |Ci| |br| |
| C | C99+ in: ``gcc``, |br| | 20 | |Ci| |br| |
| | ``clang``, ``msvc``, | | |C-Cov| |br| |
| | |br| ``pcc``, ``tcc`` | | |CodeQL| |
+------------+-------------------------+--------+-------------------+
| C++ | C++98+ in |br| | 12 | |Cpi| |br| |
| C++ | C++98+ in |br| | 13 | |Cpi| |br| |
| | ``gcc``, ``clang`` |br| | | |Cp-Cov| |br| |
| | C++14+ in ``msvc`` | | |CodeQL| |
+------------+-------------------------+--------+-------------------+
| C# | .NET 2+ | 8 | |C#i| |br| |
| C# | .NET 2+ | 9 | |C#i| |br| |
| | | | |Cs-Cov| |br| |
| | | | |CodeQL| |
+------------+-------------------------+--------+-------------------+
| JavaScript | Node 12+ |br| | 8 | |JavaScript| |br| |
| JavaScript | Node 12+ |br| | 9 | |JavaScript| |br| |
| | Bun 0.6.10+ | | |Js-Cov| |br| |
| | | | |CodeQL| |br| |
| | | | |ESLint| |
+------------+-------------------------+--------+-------------------+
| Python | CPython 3.6+ |br| | 78 | |Python| |br| |
| Python | CPython 3.6+ |br| | 79 | |Python| |br| |
| | Pypy 3.6+ |br| | | |Py-Cov| |br| |
| | GraalPy 23.1+ | | |CodeQL| |br| |
| | | | |PythonLint| |
+------------+-------------------------+--------+-------------------+
| Rust | 1.69+ | 24 | |Rust| |br| |
| Rust | 1.69+ | 25 | |Rust| |br| |
| | | | |Rs-Cov| |br| |
| | | | |RustClippy| |
+------------+-------------------------+--------+-------------------+
Expand Down
20 changes: 2 additions & 18 deletions c/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,37 +164,21 @@ Problems Solved
---------------

- ☒ `1 <./p0001.c>`__

- ☒ `2 <./p0002.c>`__

- ☒ `3 <./p0003.c>`__

- ☒ `4 <./p0004.c>`__

- ☒ `5 <./p0005.c>`__

- ☒ `6 <./p0006.c>`__

- ☒ `7 <./p0007.c>`__

- ☒ `8 <./p0008.c>`__

- ☒ `9 <./p0009.c>`__

- ☒ `10 <./p0010.c>`__

- ☒ `11 <./p0011.c>`__

- ☐ `12 <./p0012.c>`__

- ☒ `12 <./p0012.c>`_
- ☒ `13 <./p0013.c>`__

- ☒ `14 <./p0014.c>`__

- ☒ `15 <./p0015.c>`__

- ☒ `16 <./p0016.c>`__

- ☒ `34 <./p0034.c>`__

- ☒ `76 <./p0076.c>`__
- ☒ `836 <./p0836.c>`__
32 changes: 32 additions & 0 deletions c/p0836.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Project Euler Problem 836
Alright, this was funny
Problem:
Let A be an **affine plane** over a **radically integral local field** F with residual characteristic p.
We consider an **open oriented line section** U of A with normalized Haar measure m.
Define f(m,p) as the maximal possible discriminant of the **jacobian** associated to the
**orthogonal kernel embedding** of U into A.
Find f(20230401, 57). Give as your answer the concatenation of the first letters of each bolded word.
*/
#ifndef EULER_P0836
#define EULER_P0836
#include <stdio.h>

char *p0836() {
return "aprilfoolsjoke";
}

#ifndef UNITY_END
int main(int argc, char const *argv[]) {
char *answer = p0836();
printf("%s", answer);
return 0;
}
#endif
#endif
1 change: 1 addition & 0 deletions c/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "p0017.c"
#include "p0034.c"
#include "p0076.c"
#include "p0836.c"

typedef struct {
unsigned int id;
Expand Down
1 change: 1 addition & 0 deletions c/test_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
17: 21124,
34: 40730,
76: 190569291,
836: "aprilfoolsjoke",
}

# this is the set of problems where I have the right answer but wrong solution
Expand Down
1 change: 1 addition & 0 deletions cplusplus/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,4 @@ Problems Solved
- ☒ `17 <./p0017.cpp>`__
- ☒ `34 <./p0034.cpp>`__
- ☒ `76 <./p0076.cpp>`__
- ☒ `836 <./p0836.cpp>`__
31 changes: 31 additions & 0 deletions cplusplus/p0836.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Project Euler Problem 836
Alright, this was funny
Problem:
Let A be an **affine plane** over a **radically integral local field** F with residual characteristic p.
We consider an **open oriented line section** U of A with normalized Haar measure m.
Define f(m,p) as the maximal possible discriminant of the **jacobian** associated to the
**orthogonal kernel embedding** of U into A.
Find f(20230401, 57). Give as your answer the concatenation of the first letters of each bolded word.
*/
#ifndef EULER_P0836
#define EULER_P0836
#include <iostream>

std::string p0836() {
return "aprilfoolsjoke";
}

#ifndef UNITY_END
int main(int argc, char const *argv[]) {
std::cout << p0836() << std::endl;
return 0;
}
#endif
#endif
1 change: 1 addition & 0 deletions cplusplus/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "p0017.cpp"
#include "p0034.cpp"
#include "p0076.cpp"
#include "p0836.cpp"

typedef struct {
unsigned int id;
Expand Down
1 change: 1 addition & 0 deletions cplusplus/test_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
17: 21124,
34: 40730,
76: 190569291,
836: "aprilfoolsjoke",
}

# this is the set of problems where I have the right answer but wrong solution
Expand Down
5 changes: 3 additions & 2 deletions csharp/Euler.Test/test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ public static IEnumerable<object[]> Data()
yield return new object[] { typeof(p0009), 31875000 };
yield return new object[] { typeof(p0011), 70600674 };
yield return new object[] { typeof(p0017), 21124 };
yield return new object[] { typeof(p0836), "aprilfoolsjoke" };
}

[Theory]
[MemberData(nameof(Data))]
public async Task EulerTest_Problem(Type problem, Int64 expected)
public async Task EulerTest_Problem(Type problem, object expected)
{
IEuler? prob;
prob = (IEuler?)Activator.CreateInstance(problem);
Assert.NotNull(prob);
Stopwatch sw = Stopwatch.StartNew();
Int64 result = await prob.Answer();
object result = await prob.Answer();

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (8, ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (7, ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (9, ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (6, ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (2, ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (6, macos-13)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (3, ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (5, ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 30 in csharp/Euler.Test/test.cs

View workflow job for this annotation

GitHub Actions / csharp (6, windows-latest)

Dereference of a possibly null reference.
sw.Stop();
Assert.Equal(expected, result);
Assert.True(sw.Elapsed <= oneMinute);
Expand Down
6 changes: 3 additions & 3 deletions csharp/Euler/p0000_template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace Euler
{
public interface IEuler
{
public Task<Int64> Answer();
public Task<object> Answer();
}
public class p0000 : IEuler
{
public Task<Int64> Answer()
public Task<object> Answer()
{
return Task.FromResult<Int64>(0);
return Task.FromResult<object>(0);
}
}
}
4 changes: 2 additions & 2 deletions csharp/Euler/p0001.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Euler
{
public class p0001 : IEuler
{
public Task<Int64> Answer()
public Task<object> Answer()
{
int answer = 0;
for (int i = 0; i < 1000; i += 3)
Expand All @@ -30,7 +30,7 @@ public Task<Int64> Answer()
for (int i = 0; i < 1000; i += 15)
answer -= i;

return Task.FromResult<Int64>(answer);
return Task.FromResult<object>(answer);
}
}
}
6 changes: 3 additions & 3 deletions csharp/Euler/p0002.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace Euler
{
public class p0002 : IEuler
{
public Task<Int64> Answer()
public Task<object> Answer()
{
Int64 answer = 0,
int answer = 0,
i = 2,
j = 8,
tmp = 0;
Expand All @@ -35,7 +35,7 @@ public Task<Int64> Answer()
j = tmp;
}

return Task.FromResult<Int64>(answer);
return Task.FromResult<object>(answer);
}
}
}
10 changes: 5 additions & 5 deletions csharp/Euler/p0004.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ private static string Reverse(string s)
return new string(charArray);
}

private static bool IsPalindrome(Int64 x)
private static bool IsPalindrome(int x)
{
string rep = x.ToString();
return rep == Reverse(rep);
}

public Task<Int64> Answer()
public Task<object> Answer()
{
Int64 answer = 0;
int answer = 0;
for (int v = 101; v < 1000; v++)
{
for (int u = 100; u < v; u++)
{
Int64 p = u * v;
int p = u * v;
if (IsPalindrome(p) && p > answer)
{
answer = p;
}
}
}

return Task.FromResult<Int64>(answer);
return Task.FromResult<object>(answer);
}
}
}
8 changes: 4 additions & 4 deletions csharp/Euler/p0006.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ namespace Euler
{
public class p0006 : IEuler
{
public Task<Int64> Answer()
public Task<object> Answer()
{
Int64 sum_of_squares = 0,
int sum_of_squares = 0,
sum = 0;
for (int i = 1; i < 101; i++)
{
sum += i;
sum_of_squares += i * i;
}
Int64 square_of_sum = sum * sum;
return Task.FromResult<Int64>(square_of_sum - sum_of_squares);
int square_of_sum = sum * sum;
return Task.FromResult<object>(square_of_sum - sum_of_squares);
}
}
}
4 changes: 2 additions & 2 deletions csharp/Euler/p0008.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Euler
public class p0008 : IEuler
{
private const int MAX = 500;
public Task<Int64> Answer()
public Task<object> Answer()
{
String str = String.Concat(
"73167176531330624919225119674426574742355349194934",
Expand Down Expand Up @@ -78,7 +78,7 @@ public Task<Int64> Answer()
answer = prod;
}
}
return Task.FromResult<Int64>(answer);
return Task.FromResult<object>(answer);
}
}
}
4 changes: 2 additions & 2 deletions csharp/Euler/p0009.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Euler
{
public class p0009 : IEuler
{
public Task<Int64> Answer()
public Task<object> Answer()
{
for (int c = 3; ; c++)
{
Expand All @@ -32,7 +32,7 @@ public Task<Int64> Answer()
int a_square = a * a;
if (a_square + b_square == c_square && a + b + c == 1000)
{
return Task.FromResult<Int64>(a * b * c);
return Task.FromResult<object>(a * b * c);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions csharp/Euler/p0011.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace Euler
{
public class p0011 : IEuler
{
public Task<Int64> Answer()
public Task<object> Answer()
{
Int64 answer = 0, tmp;
int answer = 0, tmp;
for (byte i = 0; i < 20; i++)
{
for (byte j = 0; j < 17; j++)
Expand All @@ -50,7 +50,7 @@ public Task<Int64> Answer()
answer = Math.Max(answer, tmp);
}
}
return Task.FromResult<Int64>(answer);
return Task.FromResult<object>(answer);
}

byte[][] grid = new byte[20][]{
Expand Down
10 changes: 5 additions & 5 deletions csharp/Euler/p0017.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ namespace Euler
{
public class p0017 : IEuler
{
public Task<Int64> Answer()
public Task<object> Answer()
{
Int64 answer = 0;
for (Int64 x = 1; x < 1001; x += 1)
int answer = 0;
for (int x = 1; x < 1001; x += 1)
{
string str = to_string(x);
answer += str.Replace(" ", "").Replace("-", "").Length;
}
return Task.FromResult<Int64>(answer);
return Task.FromResult<object>(answer);
}

static String to_string(Int64 n)
static String to_string(int n)
{
if (n >= 1000)
{
Expand Down
Loading

0 comments on commit 56d0505

Please sign in to comment.