Skip to content

Commit

Permalink
Deploy gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 15, 2023
0 parents commit 32aaa20
Show file tree
Hide file tree
Showing 54 changed files with 467,750 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80

[Makefile]
indent_style = tab
indent_size = 8
max_line_length = off

[.github/workflows/build.yml]
indent_size = 2
max_line_length = off

[t/tests.json]
max_line_length = off
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto

Makefile linguist-detectable=false
words.txt linguist-vendored
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## OS files ##
.directory
[Dd]esktop.ini
Thumbs.db
.DS_Store
._*

## Editor files ##
.idea/
[._]*.sw[a-p]
[._]sw[a-p]
.netrwhist
.lvimrc
tags
*.iml
*~

## Language files ##
node_modules/
__pycache__/
nimcache/
META-INF/
build/
out/
octave-workspace
package.json
package-lock.json
yarn.lock
*.py[cod]
*.class
*.out
*.o
*.dill

## Package files ##
*.deb
*.zip
*.tar
*.tgz
*.gz
*.xz
*.bz2
16 changes: 16 additions & 0 deletions Awk/Awk.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN {
invalid = "[GKMQVWXZIOgkmqvwxzio]"

while ((getline < "words.txt") > 0) {
wlen = length($0)
if (wlen == maxlen && $0 !~ invalid) {
longest[++i] = $0
} else if (wlen > maxlen && $0 !~ invalid) {
delete longest
longest[++i] = $0
maxlen = wlen
}
}

for (l in longest) print longest[l]
}
21 changes: 21 additions & 0 deletions Awk/Gawk.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@include "readfile"

BEGIN {
IGNORECASE = 1
invalid = "[gkmqvwxzio]"
split(readfile("words.txt"), words, "\n")

for (i = 1; i <= length(words); ++i) {
word = words[i]
wlen = length(word)
if (wlen == maxlen && word !~ invalid) {
longest[++i] = word
} else if (wlen > maxlen && word !~ invalid) {
delete longest
longest[++i] = word
maxlen = wlen
}
}

for (l in longest) print longest[l]
}
41 changes: 41 additions & 0 deletions BENCHMARKS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| `Rust/rust.out` | 16.5 ± 0.1 | 16.4 | 16.7 | 1.00 |
| `C/C.out` | 20.1 ± 0.3 | 19.9 | 20.7 | 1.22 ± 0.02 |
| `Go/Go.out` | 21.8 ± 1.8 | 20.2 | 25.5 | 1.32 ± 0.11 |
| `C/C++.out` | 24.5 ± 0.3 | 24.2 | 24.8 | 1.48 ± 0.02 |
| `Crystal/Crystal.out` | 35.0 ± 0.4 | 34.8 | 35.8 | 2.12 ± 0.03 |
| `Pascal/Pascal.out` | 45.8 ± 0.9 | 45.4 | 47.9 | 2.78 ± 0.06 |
| `php -n PHP/PHP.php` | 82.0 ± 0.3 | 81.7 | 82.4 | 4.97 ± 0.04 |
| `C/Vala.out` | 88.2 ± 0.5 | 87.9 | 89.4 | 5.35 ± 0.05 |
| `Nim/Nim.out` | 90.8 ± 0.7 | 90.2 | 92.3 | 5.50 ± 0.06 |
| `Dart/Dart.out` | 93.4 ± 0.7 | 92.5 | 94.3 | 5.66 ± 0.06 |
| `D/D.out` | 93.5 ± 0.1 | 93.3 | 93.7 | 5.67 ± 0.04 |
| `mono CSharp/C#.out` | 120.3 ± 0.9 | 119.5 | 122.1 | 7.29 ± 0.08 |
| `ruby Ruby/Ruby.rb` | 149.3 ± 0.7 | 148.4 | 150.5 | 9.05 ± 0.08 |
| `perl Perl/Perl.pl` | 153.3 ± 0.2 | 153.1 | 153.6 | 9.29 ± 0.07 |
| `node JavaScript/JavaScript.js` | 156.1 ± 4.1 | 151.5 | 164.2 | 9.46 ± 0.25 |
| `awk -f Awk/Awk.awk` | 157.8 ± 2.3 | 156.4 | 162.9 | 9.57 ± 0.15 |
| `python3 Python/Python.py` | 170.8 ± 8.3 | 164.4 | 187.6 | 10.35 ± 0.51 |
| `lsc JavaScript/LiveScript.ls` | 229.8 ± 2.7 | 225.0 | 232.9 | 13.94 ± 0.19 |
| `java -cp Java Java7SegmentDisplays` | 243.2 ± 29.1 | 216.4 | 300.7 | 14.75 ± 1.77 |
| `lua5.3 Lua/Lua.lua` | 276.6 ± 2.4 | 275.0 | 281.9 | 16.77 ± 0.19 |
| `gawk -f Awk/Gawk.awk` | 328.6 ± 0.6 | 327.9 | 329.2 | 19.92 ± 0.14 |
| `julia Julia/Julia.jl` | 339.7 ± 1.4 | 338.4 | 342.2 | 20.60 ± 0.17 |
| `kotlin -cp Java Kotlin7SegmentDisplays` | 370.2 ± 4.1 | 364.3 | 375.6 | 22.45 ± 0.29 |
| `escript -c Erlang/erlang.erl` | 423.2 ± 7.2 | 414.3 | 436.9 | 25.66 ± 0.47 |
| `fennel --no-fennelrc Lua/Fennel.fnl` | 427.4 ± 3.1 | 424.0 | 433.5 | 25.91 ± 0.26 |
| `elixir Erlang/elixir.ex` | 574.3 ± 7.2 | 569.0 | 590.0 | 34.82 ± 0.50 |
| `coffee JavaScript/CoffeeScript.coffee` | 582.1 ± 4.3 | 577.2 | 588.8 | 35.29 ± 0.36 |
| `psql -d 7SegmentDisplays -qtAX -f SQL/PostgreSQL.sql` | 665.8 ± 3.0 | 661.0 | 670.7 | 40.36 ± 0.33 |
| `sqlite3 /tmp/7SegmentDisplays.db <SQL/SQLite.sql` | 673.8 ± 2.5 | 671.3 | 678.6 | 40.85 ± 0.32 |
| `scala -cp Java Scala7SegmentDisplays` | 707.9 ± 9.6 | 698.6 | 724.8 | 42.92 ± 0.65 |
| `Rscript --vanilla R/R.r` | 904.8 ± 5.0 | 898.2 | 910.6 | 54.86 ± 0.48 |
| `groovy Java/Groovy.groovy 2>/dev/null` | 967.8 ± 22.7 | 944.3 | 1007.3 | 58.68 ± 1.43 |
| `deno run -q --allow-read --no-config --no-lock JavaScript/TypeScript.ts` | 979.7 ± 11.4 | 966.0 | 995.9 | 59.40 ± 0.81 |
| `mysql 7SegmentDisplays -Ns <SQL/MySQL.sql` | 1727.7 ± 7.0 | 1714.7 | 1737.6 | 104.75 ± 0.83 |
| `zsh -f Shell/Zsh.sh` | 3042.2 ± 21.3 | 3009.1 | 3076.8 | 184.44 ± 1.81 |
| `bash --noprofile --norc Shell/Bash.sh` | 5232.0 ± 68.0 | 5133.8 | 5355.9 | 317.20 ± 4.66 |
| `perl6 Perl/Perl6.p6` | 5760.9 ± 172.1 | 5574.6 | 6016.3 | 349.27 ± 10.71 |
| `octave -f Octave/Octave.m 2>/dev/null` | 7498.6 ± 12.7 | 7478.1 | 7512.3 | 454.62 ± 3.22 |
| `cmake -P CMake/CMake.cmake 2>&1` | 8669.6 ± 87.7 | 8586.5 | 8840.4 | 525.61 ± 6.43 |
26 changes: 26 additions & 0 deletions C/C++.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <fstream>
#include <iostream>
#include <regex>

int main() {
std::vector<std::string> longest;
std::regex invalid(".*[gkmqvwxzio].*", std::regex_constants::icase);
std::ifstream words("words.txt");
std::string word;
unsigned long wlen = 0, maxlen = 0;

while (!words.eof()) {
getline(words, word);
wlen = word.length();
if (wlen == maxlen && !regex_match(word, invalid)) {
longest.push_back(word);
} else if (wlen > maxlen && !regex_match(word, invalid)) {
longest.clear();
longest.push_back(word);
maxlen = wlen;
}
}
words.close();

for (const auto &l : longest) std::cout << l << std::endl;
}
37 changes: 37 additions & 0 deletions C/C.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define VALID(word) regexec(&invalid, word, 0, NULL, 0) == REG_NOMATCH

int main() {
char *word, **tmp, **words = NULL;
FILE *txt = fopen("words.txt", "r");
size_t maxlen = 0, wlen = 0;
int num = 0;
regex_t invalid;
regcomp(&invalid, ".*[gkmqvwxzio].*", REG_ICASE|REG_NOSUB);

while (getline(&word, &wlen, txt) != -1) {
wlen = strlen(word);
if(wlen == maxlen && VALID(word)) {
tmp = words;
words = (char **) realloc(tmp, wlen * ++num);
*(words + num - 1) = (char *) malloc(wlen);
strncpy(*(words + num - 1), word, wlen);
} else if(wlen > maxlen && VALID(word)) {
words = (char **) realloc(words, wlen);
*words = (char *) malloc(wlen);
strncpy(*words, word, wlen);
maxlen = wlen;
num = 1;
}
}
fclose(txt);
free(word);
regfree(&invalid);

for (int i = 0; i < num; ++i) printf("%s", *(words + i));
free(words);
}
22 changes: 22 additions & 0 deletions C/Vala.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
int main() {
var longest = new Array<string>();
var invalid = new Regex("[gkmqvwxzio]", RegexCompileFlags.CASELESS);
var words = FileStream.open("words.txt", "r");
string word;
ulong wlen = 0, maxlen = 0;

while ((word = words.read_line()) != null) {
wlen = word.length;
if (wlen == maxlen && !invalid.match(word)) {
longest.append_val(word);
} else if (wlen > maxlen && !invalid.match(word)) {
longest.set_size(0);
longest.append_val(word);
maxlen = wlen;
}
}

for (int i = 0; i < longest.length; ++i)
stdout.printf("%s\n", longest.index(i));
return 0;
}
17 changes: 17 additions & 0 deletions CMake/CMake.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
file(STRINGS "words.txt" words)
set(maxlen "0")

foreach(word ${words})
string(LENGTH ${word} wlen)
string(REGEX MATCH ".*[GKMQVWXZIOgkmqvwxzio].*" invalid ${word})
if(wlen EQUAL maxlen AND NOT invalid)
list(APPEND longest ${word})
elseif(wlen GREATER maxlen AND NOT invalid)
set(longest ${word})
set(maxlen ${wlen})
endif()
endforeach()

foreach(l ${longest})
message(${l})
endforeach()
42 changes: 42 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Contributing

## Rules & guidelines

* Make sure your code conforms to [`.editorconfig`](.editorconfig).
* Don't alter the coding style of existing files.
* Keep the implementations short and simple.
* Words containing any of `gkmqvwxzio` are invalid.
* The program's working directory must be the project root.
* You can skip checking for `words.txt`'s existence.
* If possible, separate the code into 3 or 4 sections (with a blank line):

0. Importing/including (if necessary).
1. Declaring variables & reading the file.
2. Finding the longest words.
3. Printing the longest words.
* If possible, use the following variable names for consistency:

* `words`: List/array of words read from `words.txt`.
* `longest`: List/array of the longest words.
* `invalid`: Regular expression of invalid letters.
* `maxlen`: Length of the longest word(s).

## Expected output

All implementations should produce the following output:

```
supertranscendentness
three-and-a-halfpenny
```

## Adding a new language

* Name the file according to the language it was written in.
* Place the file inside a folder named after the language family.
* Add the new language to the [README](README.md#languages) (`make langs`).
* Add a new target for the language to the [Makefile](Makefile), if needed.
* Add any required packages or steps to the [workflow](.github/workflows/build.yml).
* Add any compiler/editor-generated files to [`.gitignore`](.gitignore).
* Add a new test for the language in [`t/tests.json`](t/tests.json).
* If it cannot be tested, explain why in a comment within the file.
24 changes: 24 additions & 0 deletions CSharp/C#.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class CS7SegmentDisplays {
static void Main(string[] args) {
var invalid = new Regex("(?i)[gkmqvwxzio]");
var longest = new List<string>();
var maxlen = 0;

foreach (var word in File.ReadLines("words.txt")) {
var wlen = word.Length;
if (wlen == maxlen && !invalid.Match(word).Success) {
longest.Add(word);
} else if (wlen > maxlen && !invalid.Match(word).Success) {
longest.Clear();
longest.Add(word);
maxlen = wlen;
}
}

longest.ForEach(System.Console.WriteLine);
}
}
14 changes: 14 additions & 0 deletions Crystal/Crystal.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
longest = [] of String
invalid = /[gkmqvwxzio]/i
maxlen = 0

File.open("words.txt").each_line do |word|
if word.size == maxlen && word !~ invalid
longest << word
elsif word.size > maxlen && word !~ invalid
longest.clear << word
maxlen = word.size
end
end

puts longest.join("\n")
21 changes: 21 additions & 0 deletions D/D.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import std.stdio, std.container, std.conv, std.regex;

void main() {
auto invalid = regex(r"(?i)[gkmqvwxzio]");
auto longest = Array!string();
auto maxlen = 0;

foreach (ref line; File("words.txt").byLine()) {
auto word = to!string(line);
auto wlen = to!int(word.length);
if (wlen == maxlen && !word.matchAll(invalid)) {
longest.insertBack(word);
} else if (wlen > maxlen && !word.matchAll(invalid)) {
longest.clear();
longest.insertBack(word);
maxlen = wlen;
}
}

foreach (l; longest) writeln(l);
}
19 changes: 19 additions & 0 deletions Dart/Dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'dart:io';

main() async {
final longest = List<String>.empty(growable: true);
final invalid = RegExp(r'[gkmqvwxio]', caseSensitive: false);
var maxlen = 0;

(await File('words.txt').readAsLines()).forEach((word) {
if (word.length == maxlen && !invalid.hasMatch(word)) {
longest.add(word);
} else if (word.length > maxlen && !invalid.hasMatch(word)) {
longest.clear();
longest.add(word);
maxlen = word.length;
}
});

print(longest.join('\n'));
}
Loading

0 comments on commit 32aaa20

Please sign in to comment.