Compare commits
17 Commits
c6c387d17f
...
master
Author | SHA1 | Date | |
---|---|---|---|
ed83a3afc3 | |||
6b8afd49b9 | |||
3903a79785 | |||
8d60e1b905 | |||
f11b705ef0 | |||
d54e53eff9 | |||
953021438f | |||
0fbf5ed250 | |||
27fd0bf2ea | |||
|
2a2623a652 | ||
|
a6355b2629 | ||
|
604de1528d | ||
|
cb4a6a8081 | ||
|
62c2c8f47b | ||
|
6cc3b0ad82 | ||
|
80dbb818a8 | ||
|
b25e8b7c11 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
output/
|
||||||
|
.*.cache/
|
52
.phpcs.xml
Normal file
52
.phpcs.xml
Normal 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
33
CT.rb
@ -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
|
|
@ -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
|
|
@ -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
13
composer.json
Normal 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
20
composer.lock
generated
Normal 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"
|
||||||
|
}
|
100
data/primes/primes100.txt
Normal file
100
data/primes/primes100.txt
Normal 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
1000
data/primes/primes1000.txt
Normal file
File diff suppressed because it is too large
Load Diff
10000
data/primes/primes10000.txt
Normal file
10000
data/primes/primes10000.txt
Normal file
File diff suppressed because it is too large
Load Diff
1000000
data/primes/primes1000000.txt
Normal file
1000000
data/primes/primes1000000.txt
Normal file
File diff suppressed because it is too large
Load Diff
24
phpunit.xml
Normal file
24
phpunit.xml
Normal 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>
|
BIN
solutions/Generic/Fibonacci/a.exe
Normal file
BIN
solutions/Generic/Fibonacci/a.exe
Normal file
Binary file not shown.
51
solutions/Generic/Fibonacci/solve.c
Normal file
51
solutions/Generic/Fibonacci/solve.c
Normal 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;
|
||||||
|
}
|
BIN
solutions/Generic/Fibonacci/solve.exe
Normal file
BIN
solutions/Generic/Fibonacci/solve.exe
Normal file
Binary file not shown.
@ -14,3 +14,6 @@ solutions:
|
|||||||
solve.c:
|
solve.c:
|
||||||
desc: ANSI C solution (Tested with TCC)
|
desc: ANSI C solution (Tested with TCC)
|
||||||
language: c
|
language: c
|
||||||
|
solve.js:
|
||||||
|
desc: NodeJS solution
|
||||||
|
language: js
|
1
solutions/Generic/HelloWorld/solve.js
Normal file
1
solutions/Generic/HelloWorld/solve.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
console.log("Hello World");
|
20
solutions/Generic/MultiTable/solve.c
Normal file
20
solutions/Generic/MultiTable/solve.c
Normal 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;
|
||||||
|
}
|
10
solutions/Generic/Seive/desc.yml
Normal file
10
solutions/Generic/Seive/desc.yml
Normal 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
|
22
solutions/Generic/Seive/solve.c
Normal file
22
solutions/Generic/Seive/solve.c
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,3 +21,6 @@ solutions:
|
|||||||
solve.js:
|
solve.js:
|
||||||
desc: NodeJS solution
|
desc: NodeJS solution
|
||||||
language: javascript
|
language: javascript
|
||||||
|
solve.lua:
|
||||||
|
desc: Basic solution
|
||||||
|
language: lua
|
7
solutions/ProjectEuler/001/solve.lua
Normal file
7
solutions/ProjectEuler/001/solve.lua
Normal 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)
|
@ -22,3 +22,6 @@ solutions:
|
|||||||
solve.js:
|
solve.js:
|
||||||
desc: NodeJS solution
|
desc: NodeJS solution
|
||||||
language: javascript
|
language: javascript
|
||||||
|
solve.lua:
|
||||||
|
desc: Basic solution
|
||||||
|
language: lua
|
@ -5,7 +5,7 @@ fib = new Array( 1, 2, 3 );
|
|||||||
fib[2] = fib[0] + fib[1];
|
fib[2] = fib[0] + fib[1];
|
||||||
if(fib[2] % 2 == 0)
|
if(fib[2] % 2 == 0)
|
||||||
sum += fib[2];
|
sum += fib[2];
|
||||||
fib[0] = fib[1];
|
fib[0] = fib[1];
|
||||||
fib[1] = fib[2];
|
fib[1] = fib[2];
|
||||||
}
|
}
|
||||||
console.log(sum );
|
console.log(sum );
|
11
solutions/ProjectEuler/002/solve.lua
Normal file
11
solutions/ProjectEuler/002/solve.lua
Normal 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 )
|
@ -15,3 +15,6 @@ solutions:
|
|||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Basic solution in Ruby
|
desc: Basic solution in Ruby
|
||||||
language: ruby
|
language: ruby
|
||||||
|
solve.js:
|
||||||
|
desc: Basic solution for NodeJS
|
||||||
|
language: js
|
11
solutions/ProjectEuler/005/solve.js
Normal file
11
solutions/ProjectEuler/005/solve.js
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
solutions/ProjectEuler/005/solve.lua
Normal file
12
solutions/ProjectEuler/005/solve.lua
Normal 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
|
13
solutions/ProjectEuler/005/solve.rb
Normal file
13
solutions/ProjectEuler/005/solve.rb
Normal 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
|
@ -19,6 +19,9 @@ solutions:
|
|||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Basic Ruby solution
|
desc: Basic Ruby solution
|
||||||
language: ruby
|
language: ruby
|
||||||
solve.rb:
|
solve.c:
|
||||||
desc: ANSI C solution (Tested with TCC)
|
desc: ANSI C solution (Tested with TCC)
|
||||||
language: c
|
language: c
|
||||||
|
solve.js:
|
||||||
|
desc: Javascript solution for NodeJS
|
||||||
|
language: javascript
|
9
solutions/ProjectEuler/006/solve.js
Normal file
9
solutions/ProjectEuler/006/solve.js
Normal 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);
|
||||||
|
|
@ -11,6 +11,8 @@ solutions:
|
|||||||
solve.php:
|
solve.php:
|
||||||
desc: Expects the haystack as stdin with optional newlines
|
desc: Expects the haystack as stdin with optional newlines
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\008\input
|
||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Expects the haystack as stdin with optional newlines
|
desc: Expects the haystack as stdin with optional newlines
|
||||||
language: ruby
|
language: ruby
|
||||||
|
parameters: < ProjectEuler\008\input
|
@ -16,5 +16,5 @@ solutions:
|
|||||||
desc: Basic solution
|
desc: Basic solution
|
||||||
language: ruby
|
language: ruby
|
||||||
solve.c:
|
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
|
language: c
|
@ -13,6 +13,8 @@ solutions:
|
|||||||
solve.php:
|
solve.php:
|
||||||
desc: Expects the matrix as stdin
|
desc: Expects the matrix as stdin
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\011\input
|
||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Expects the matrix as stdin
|
desc: Expects the matrix as stdin
|
||||||
language: ruby
|
language: ruby
|
||||||
|
parameters: < ProjectEuler\011\input
|
@ -12,6 +12,8 @@ solutions:
|
|||||||
solve.php:
|
solve.php:
|
||||||
desc: Expects input on STDIN
|
desc: Expects input on STDIN
|
||||||
language: php
|
language: php
|
||||||
|
parameters: < ProjectEuler\013\input
|
||||||
solve.rb:
|
solve.rb:
|
||||||
desc: Expects input on STDIN
|
desc: Expects input on STDIN
|
||||||
language: ruby
|
language: ruby
|
||||||
|
parameters: < ProjectEuler\013\input
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user