Compare commits

...

17 Commits

Author SHA1 Message Date
ed83a3afc3 Gitignore 2024-07-31 07:16:44 +00:00
6b8afd49b9 More progress 2024-07-23 09:13:29 +00:00
3903a79785 Solve ProjectEuler 049 and 050. 2024-07-02 07:46:37 +00:00
8d60e1b905 Restructuring 2024-07-01 13:49:44 +00:00
f11b705ef0 Problem ProjectEuler 044 2024-06-28 09:20:29 +00:00
d54e53eff9 Comments 2024-06-28 08:34:27 +00:00
953021438f More solutions 2024-06-28 08:34:07 +00:00
0fbf5ed250 Removing invalid previous solutions 2024-06-26 13:23:30 +00:00
27fd0bf2ea Few more challenges on ProjectEuler 2024-06-26 13:16:36 +00:00
FuryFire
2a2623a652 Added a few generic problems\nSolved Euler027 2016-02-23 15:55:26 +01:00
FuryFire
a6355b2629 Removed incomplete solution 2012-12-17 12:20:18 +01:00
FuryFire
604de1528d Solved ProjectEuler/039,041,042 2012-12-17 12:17:09 +01:00
FuryFire
cb4a6a8081 Solved ProjectEuler/038,104 2011-04-26 16:07:20 +02:00
FuryFire
62c2c8f47b Solved ProjectEuler/035 2012-04-25 15:26:13 +02:00
FuryFire
6cc3b0ad82 Solved ProjectEuler/028,048 2011-04-24 16:22:52 +02:00
FuryFire
80dbb818a8 Begun adding support for a global settings.yml file 2011-04-12 14:12:02 +02:00
FuryFire
b25e8b7c11 Added a few lua solutions - Updated the CT script to include additional parameters 2012-04-11 14:49:45 +02:00
203 changed files with 1013832 additions and 75 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
output/
.*.cache/

52
.phpcs.xml Normal file
View File

@ -0,0 +1,52 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>Coding standard</description>
<file>src/</file>
<file>tests/</file>
<rule ref="PSR1">
<exclude name="Generic.Files.LineLength"/>
</rule>
<rule ref="PSR2"></rule>
<rule ref="PSR12"></rule>
<rule ref="Generic">
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/>
<exclude name="Generic.Files.LowercasedFilename.NotFound"/>
<exclude name="Generic.PHP.ClosingPHPTag.NotFound"/>
<exclude name="Generic.Files.EndFileNoNewline.Found"/>
<exclude name="Generic.Files.EndFileNoNewline.Found"/>
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/>
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine"/>
<exclude name="Generic.Classes.OpeningBraceSameLine.BraceOnNewLine"/>
<exclude name="Generic.PHP.LowerCaseConstant.Found"/>
<exclude name="Generic.Formatting.SpaceAfterCast"/>
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="Generic.NamingConventions.AbstractClassNamePrefix.Missing"/>
<exclude name="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed"/>
<exclude name="Generic.NamingConventions.InterfaceNameSuffix.Missing"/>
<exclude name="Generic.Commenting.Todo.TaskFound"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUse"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed"/>
<exclude name="Generic.Formatting.SpaceBeforeCast.NoSpace"/>
<exclude name="Generic.CodeAnalysis.UselessOverridingMethod.Found"/>
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace"/>
</rule>
<!-- Ban some functions -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="sizeof" value="count"/>
<element key="delete" value="unset"/>
<element key="print" value="echo"/>
<element key="is_null" value="null"/>
<element key="create_function" value="null"/>
</property>
</properties>
</rule>
</ruleset>

33
CT.rb
View File

@ -1,33 +0,0 @@
require "yaml"
require 'erb'
problem = YAML::load_file(ARGV[0] + "/desc.yml")
output = ERB.new(IO.read('template.rt'))
puts output.result()
if(ARGV[1] == 'table')
require 'terminal-table'
files = Dir[ARGV[0]+"/**/*/desc.yml"]
files.sort
entry = []
files.each do |file|
yaml = YAML::load_file(file)
nested = file.split('/')
count = 0
if( yaml['solution'] and yaml['solutions'])
yaml['solutions'].each do |sol|
count += 1
end
end
entry << {'title'=>yaml['title'],'code'=>nested[-2].to_s,'solved'=>count}
end
rows = []
entry.each do |e|
solvedstring = (e['solved'] == 0) ? "No" : "Yes("+e['solved'].to_s+")"
row = [e['code'],e['title'],solvedstring]
rows << row
end
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
puts table
end

View File

@ -1,10 +0,0 @@
max = 0;
(100..1000).each do |num1|
(100..1000).each do |num2|
sum = num1 * num2
if( sum > max and sum.to_s.reverse == sum.to_s)
max = sum
end
end
end
print max

View File

@ -1,6 +0,0 @@
<?php
function pandigital($number) {
$array = count_chars($number,1);
ksort($array);
if($array == array(49=>1,50=>1,51=>1,52=>1,53=>1,54=>1,55=>1,56=>1,57=>1)) { return true;} else { return false; }
}

13
composer.json Normal file
View File

@ -0,0 +1,13 @@
{
"name": "furyfire/codingtests",
"description": "Solutions for online coding challenges. (Support library for PHP)",
"homepage": "https://jcktrue.dk",
"require": {
"php": "^8.1"
},
"autoload": {
"psr-4": {
"CodingTests\\": "src/"
}
}
}

20
composer.lock generated Normal file
View File

@ -0,0 +1,20 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1fec30c71407f68099d62f794946e565",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^8.1"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

1
ct.bat
View File

@ -1 +0,0 @@
ruby CT.rb %1 %2

100
data/primes/primes100.txt Normal file
View File

@ -0,0 +1,100 @@
1, 2, 2
2, 3, 1
3, 5, 2
4, 7, 2
5, 11, 4
6, 13, 2
7, 17, 4
8, 19, 2
9, 23, 4
10, 29, 6
11, 31, 2
12, 37, 6
13, 41, 4
14, 43, 2
15, 47, 4
16, 53, 6
17, 59, 6
18, 61, 2
19, 67, 6
20, 71, 4
21, 73, 2
22, 79, 6
23, 83, 4
24, 89, 6
25, 97, 8
26, 101, 4
27, 103, 2
28, 107, 4
29, 109, 2
30, 113, 4
31, 127, 14
32, 131, 4
33, 137, 6
34, 139, 2
35, 149, 10
36, 151, 2
37, 157, 6
38, 163, 6
39, 167, 4
40, 173, 6
41, 179, 6
42, 181, 2
43, 191, 10
44, 193, 2
45, 197, 4
46, 199, 2
47, 211, 12
48, 223, 12
49, 227, 4
50, 229, 2
51, 233, 4
52, 239, 6
53, 241, 2
54, 251, 10
55, 257, 6
56, 263, 6
57, 269, 6
58, 271, 2
59, 277, 6
60, 281, 4
61, 283, 2
62, 293, 10
63, 307, 14
64, 311, 4
65, 313, 2
66, 317, 4
67, 331, 14
68, 337, 6
69, 347, 10
70, 349, 2
71, 353, 4
72, 359, 6
73, 367, 8
74, 373, 6
75, 379, 6
76, 383, 4
77, 389, 6
78, 397, 8
79, 401, 4
80, 409, 8
81, 419, 10
82, 421, 2
83, 431, 10
84, 433, 2
85, 439, 6
86, 443, 4
87, 449, 6
88, 457, 8
89, 461, 4
90, 463, 2
91, 467, 4
92, 479, 12
93, 487, 8
94, 491, 4
95, 499, 8
96, 503, 4
97, 509, 6
98, 521, 12
99, 523, 2
100, 541, 18

1000
data/primes/primes1000.txt Normal file

File diff suppressed because it is too large Load Diff

10000
data/primes/primes10000.txt Normal file

File diff suppressed because it is too large Load Diff

1000000
data/primes/primes1000000.txt Normal file

File diff suppressed because it is too large Load Diff

24
phpunit.xml Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false" displayDetailsOnTestsThatTriggerWarnings="true">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
<logging>
<junit outputFile="output/test/junit.xml"/>
<testdoxHtml outputFile="output/test/index.html"/>
</logging>
<coverage>
<report>
<html outputDirectory="output/coverage" />
<clover outputFile ="output/coverage/clover.xml" />
</report>
</coverage>
</phpunit>

Binary file not shown.

View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <string.h>
#define SIZE 20
void add(char *a, char *b, char *result, int size) {
int i = 0;
for(i=0;i<size;i++) {
//We have overflow!
if((a[i] + b[i] + result[i] < a[i]) || (a[i] + b[i] + result[i] < b[i])) {
result[i+1]++;
}
result[i]+= a[i] + b[i];
}
}
int main( )
{
unsigned char prev[SIZE];
unsigned char current[SIZE];
unsigned char next[SIZE];
unsigned int i=0;
memset(prev,0x00,SIZE);
memset(current,0x00,SIZE);
memset(next,0x00,SIZE);
prev[0]=1;
current[0]=1;
next[0]=1;
for(i=2;i<100;i++) {
add(current,prev,next,SIZE);
memcpy(prev,current,SIZE);
memcpy(current,next,SIZE);
//prev = current;
//current = next;
int j;
for(j=0;j<SIZE;j++) {
printf("%d: %i\n",j,current[j]);
}
}
for(i=0;i<SIZE;i++) {
printf("%d: %i\n",i,current[i]);
}
return 0;
}

Binary file not shown.

View File

@ -13,4 +13,7 @@ solutions:
language: ruby
solve.c:
desc: ANSI C solution (Tested with TCC)
language: c
language: c
solve.js:
desc: NodeJS solution
language: js

View File

@ -0,0 +1 @@
console.log("Hello World");

View File

@ -0,0 +1,20 @@
#include <stdio.h>
#define SIZE_X 12
#define SIZE_Y 12
void main()
{
int x,y;
int MemorizeThis[SIZE_X][SIZE_Y];
for (x =1; x <= SIZE_X; x++)
{
for (y = 1; y <= SIZE_Y; y++)
{
MemorizeThis[x-1][y-1] = x * y;
printf("[%03d]", MemorizeThis[x-1][y-1]);
}
printf("\n");
}
printf("\n");
return;
}

View File

@ -0,0 +1,10 @@
title: Sieve of Eratosthenes
url: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
desc:Generate primes from 2 to 100
solution: Do i need to say more
solutions:
solve.c:
desc: ANSI C solution (Tested with TCC)
language: c

View File

@ -0,0 +1,22 @@
#include <stdio.h>
void main( )
{
unsigned char primes[100];
int p;
int j;
memset(&primes, 1, 50 );
for( p = 2; p<=10; p++) {
if (primes[p]) {
for(j = p*p; j <= 100; j+= p){
primes[j] = 0;
}
}
}
printf( "Primes:%d\n", sizeof(primes)) ;
for(p=0;p<sizeof(primes);p++) {
if(primes[p]) {
printf( "%d\n",p);
}
}
}

View File

@ -21,3 +21,6 @@ solutions:
solve.js:
desc: NodeJS solution
language: javascript
solve.lua:
desc: Basic solution
language: lua

View File

@ -0,0 +1,7 @@
sum = 0
for i=1,999 do
if i % 3 == 0 or i % 5 == 0 then
sum = sum + i
end
end
print(sum)

View File

@ -21,4 +21,7 @@ solutions:
language: c
solve.js:
desc: NodeJS solution
language: javascript
language: javascript
solve.lua:
desc: Basic solution
language: lua

View File

@ -5,7 +5,7 @@ fib = new Array( 1, 2, 3 );
fib[2] = fib[0] + fib[1];
if(fib[2] % 2 == 0)
sum += fib[2];
fib[0] = fib[1];
fib[0] = fib[1];
fib[1] = fib[2];
}
console.log(sum );

View File

@ -0,0 +1,11 @@
sum = 2
fib = {1, 2, 3}
while fib[2] < 4000000 do
fib[3] = fib[1] + fib[2]
if(fib[3] % 2 == 0) then
sum = sum + fib[3]
end
fib[1] = fib[2]
fib[2] = fib[3]
end
print (sum )

View File

@ -15,3 +15,6 @@ solutions:
solve.rb:
desc: Basic solution in Ruby
language: ruby
solve.js:
desc: Basic solution for NodeJS
language: js

View File

@ -0,0 +1,11 @@
for(i=20;true;i+=20) {
div = 19;
while(!(i % div)) {
div--;
if(div == 0) {
console.log( i );
process.exit(0);
}
}
}

View File

@ -0,0 +1,12 @@
i=0
while(true) do
i = i + 20
div = 19
while((i % div) == 0) do
div = div - 1
if(div == 0) then
print(i)
os.exit()
end
end
end

View File

@ -0,0 +1,13 @@
i = 0
while (true)
i = i + 20
div = 19
while((i % div) == 0)
div = div - 1
if(div == 0) then
puts i
exit
end
end
end

View File

@ -19,6 +19,9 @@ solutions:
solve.rb:
desc: Basic Ruby solution
language: ruby
solve.rb:
solve.c:
desc: ANSI C solution (Tested with TCC)
language: c
language: c
solve.js:
desc: Javascript solution for NodeJS
language: javascript

View File

@ -0,0 +1,9 @@
square = 0;
sum = 0;
for(num=1;num<101;num++) {
square += Math.pow(num,2);
sum += num;
}
console.log( Math.pow(sum,2) - square);

View File

@ -11,6 +11,8 @@ solutions:
solve.php:
desc: Expects the haystack as stdin with optional newlines
language: php
parameters: < ProjectEuler\008\input
solve.rb:
desc: Expects the haystack as stdin with optional newlines
language: ruby
language: ruby
parameters: < ProjectEuler\008\input

View File

@ -16,5 +16,5 @@ solutions:
desc: Basic solution
language: ruby
solve.c:
desc: ANSI C solution compiled with gcc-4.3.4
desc: C solution compiled with gcc-4.3.4 (Support for long long needed)
language: c

View File

@ -13,6 +13,8 @@ solutions:
solve.php:
desc: Expects the matrix as stdin
language: php
parameters: < ProjectEuler\011\input
solve.rb:
desc: Expects the matrix as stdin
language: ruby
language: ruby
parameters: < ProjectEuler\011\input

View File

@ -12,6 +12,8 @@ solutions:
solve.php:
desc: Expects input on STDIN
language: php
parameters: < ProjectEuler\013\input
solve.rb:
desc: Expects input on STDIN
language: ruby
parameters: < ProjectEuler\013\input

Some files were not shown because too many files have changed in this diff Show More