new languages

This commit is contained in:
William Ball 2020-07-13 09:06:43 -07:00
parent 4f8d69c769
commit b44640eec7
812 changed files with 2000 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
__pycache__ __pycache__
*/Cargo.lock */Cargo.lock
*/target/* */target/*
cpp/a.out
java/*.class

BIN
cpp/a.out

Binary file not shown.

View file

@ -53,7 +53,7 @@ public:
}; };
auto next(ull x) -> std::vector<ull> { auto next(ull x) -> std::vector<ull> {
std::vector<ull> new_xs = {}; std::vector<ull> new_xs();
ull temp = x * 10; ull temp = x * 10;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
auto temp2 = temp + i; auto temp2 = temp + i;

21
java/Main.java Normal file
View file

@ -0,0 +1,21 @@
import java.util.ArrayList;
public class Main
{
public static void main(String[] args)
{
Util.init();
ArrayList<Long> vals = new ArrayList<Long>();
vals.add(2l);
vals.add(3l);
vals.add(5l);
vals.add(7l);
Tree tree = new Tree(0, vals);
for (int i = 0; i < 20; i++) {
tree.step();
Util.printList(tree.longestPath());
}
}
}

63
java/Tree.java Normal file
View file

@ -0,0 +1,63 @@
import java.util.ArrayList;
class Tree
{
private long value;
private ArrayList<Tree> children;
public Tree(long tree_value, ArrayList<Long> tree_children)
{
value = tree_value;
children = new ArrayList<Tree>();
for (long child : tree_children) {
children.add(new Tree(child, new ArrayList<Long>()));
}
}
public void step()
{
if (children.isEmpty()) {
ArrayList<Long> xs = next(value);
for (long val : xs) {
children.add(new Tree(val, new ArrayList<Long>()));
}
return;
}
for (Tree child : children) {
child.step();
}
}
public ArrayList<Long> longestPath()
{
ArrayList<Long> retval = new ArrayList<Long>();
if (children.isEmpty()) {
retval.add(value);
return retval;
}
int max_length = 0;
for (Tree child : children) {
ArrayList<Long> temp = child.longestPath();
if (temp.size() > max_length) {
max_length = temp.size();
retval = temp;
}
}
retval.add(0, value);
return retval;
}
/* modify this function to change functionality */
public ArrayList<Long> next(long val)
{
ArrayList<Long> new_xs = new ArrayList<Long>();
long temp = val * 10;
for (int i = 0; i < 10; i++) {
long temp2 = temp + i;
if (Util.isPrime(temp2)) {
new_xs.add(temp2);
}
}
return new_xs;
}
}

57
java/Util.java Normal file
View file

@ -0,0 +1,57 @@
import java.util.HashMap;
import java.util.ArrayList;
class Util
{
private static HashMap<Long, Boolean> primes;
private static HashMap<Long, Boolean> squareFree;
public static void init()
{
primes = new HashMap<Long, Boolean>();
squareFree = new HashMap<Long, Boolean>();
}
public static boolean isPrime(long val)
{
if (primes.containsKey(val)) {
return primes.get(val);
}
for (int i = 2; i * i <= val; i++) {
if (val % i == 0) {
primes.put(val, false);
return false;
}
}
primes.put(val, true);
return true;
}
public static boolean isSquareFree(long val)
{
if (squareFree.containsKey(val)) {
return squareFree.get(val);
}
for (int i = 2; i * i <= val; i++) {
if (isPrime(i)) {
if (val % (i * i) == 0) {
squareFree.put(val, false);
return false;
}
}
}
squareFree.put(val, true);
return true;
}
public static void printList(ArrayList<Long> ls)
{
System.out.print("[");
for (int i = 0; i < ls.size() - 1; i++) {
System.out.print(ls.get(i));
System.out.print(", ");
}
System.out.print(ls.get(ls.size() - 1));
System.out.print("]\n");
}
}

91
rust/append_digit_primes/Cargo.lock generated Normal file
View file

@ -0,0 +1,91 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "append_digit_primes"
version = "0.1.0"
dependencies = [
"primal",
]
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "hamming"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65043da274378d68241eb9a8f8f8aa54e349136f7b8e12f63e3ef44043cc30e1"
[[package]]
name = "num-integer"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [
"autocfg",
]
[[package]]
name = "primal"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bf9e0aea92a2e2a931fafb1b5d4c6e438197bbca4943a9984b3327fb8e3b5d0"
dependencies = [
"primal-check",
"primal-estimate",
"primal-sieve",
]
[[package]]
name = "primal-bit"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2837edc85364907810b0ec880f1010dab1a9cc6e75bacb3655c7fd22e125ec1b"
dependencies = [
"hamming",
]
[[package]]
name = "primal-check"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01419cee72c1a1ca944554e23d83e483e1bccf378753344e881de28b5487511d"
dependencies = [
"num-integer",
]
[[package]]
name = "primal-estimate"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12e07b550a7cbfcaa567bcd28042919548016ad615b5731633fa5239992d853f"
[[package]]
name = "primal-sieve"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd0113d948c8f955a7ae96520023fe1e730eadbf26e67c4452f801a485e9d357"
dependencies = [
"primal-bit",
"primal-estimate",
"smallvec",
]
[[package]]
name = "smallvec"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"

View file

@ -0,0 +1 @@
{"rustc_fingerprint":16498748141553911445,"outputs":{"1164083562126845933":["rustc 1.44.1 (c7087fe00 2020-06-17)\nbinary: rustc\ncommit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7\ncommit-date: 2020-06-17\nhost: x86_64-unknown-linux-gnu\nrelease: 1.44.1\nLLVM version: 9.0\n",""],"4476964694761187371":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/wball1/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""]},"successes":{}}

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":16069784454168883861,"profile":14996655781355331481,"path":1036222786711178230,"deps":[[17532073805171608632,"primal",false,9204999295791793942]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/append_digit_primes-9de3e27113fff165/dep-bin-append_digit_primes-9de3e27113fff165"}}],"rustflags":[],"metadata":18079067696405074419}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1,2 @@
{"message":"unreachable statement","code":{"code":"unreachable_code","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":1963,"byte_end":1999,"line_start":76,"line_end":76,"column_start":5,"column_end":41,"is_primary":true,"text":[{"text":" let mut tree = Tree::new(0, primes);","highlight_start":5,"highlight_end":41}],"label":"unreachable statement","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"src/main.rs","byte_start":1951,"byte_end":1957,"line_start":75,"line_end":75,"column_start":5,"column_end":11,"is_primary":false,"text":[{"text":" return;","highlight_start":5,"highlight_end":11}],"label":"any code following this expression is unreachable","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(unreachable_code)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unreachable statement\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:76:5\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m75\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m return;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m------\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12many code following this expression is unreachable\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m76\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m let mut tree = Tree::new(0, primes);\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33munreachable statement\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unreachable_code)]` on by default\u001b[0m\n\n"}
{"message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 1 warning emitted\u001b[0m\n\n"}

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":16069784454168883861,"profile":14891217944882224483,"path":1036222786711178230,"deps":[[17532073805171608632,"primal",false,13217636610115768858]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/append_digit_primes-bb5a9520ac000bc4/dep-bin-append_digit_primes-bb5a9520ac000bc4"}}],"rustflags":[],"metadata":18079067696405074419}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":8574161726611873773,"profile":9935990280773120926,"path":2231583120935216222,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/autocfg-1448277b90571096/dep-lib-autocfg-1448277b90571096"}}],"rustflags":[],"metadata":13102859075309379048}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":2322925091997197464,"profile":14672114853574311971,"path":9881501164722877471,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/hamming-957161835e554605/dep-lib-hamming-957161835e554605"}}],"rustflags":[],"metadata":11435927085409730030}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":2322925091997197464,"profile":9935990280773120926,"path":9881501164722877471,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/hamming-f7cd00fddb2c0dde/dep-lib-hamming-f7cd00fddb2c0dde"}}],"rustflags":[],"metadata":11435927085409730030}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[\"default\", \"std\"]","target":7800718724727423882,"profile":9935990280773120926,"path":18360201026855538313,"deps":[[74873448883125965,"num_traits",false,5214679006096731788],[13053465359523334410,"build_script_build",false,2720251519998876714]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/num-integer-10062f162ce3dcba/dep-lib-num_integer-10062f162ce3dcba"}}],"rustflags":[],"metadata":58200369117550911}

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"","target":0,"profile":0,"path":0,"deps":[[13053465359523334410,"build_script_build",false,4308177619064313783]],"local":[{"RerunIfChanged":{"output":"debug/build/num-integer-5388b70d3d6e3c6d/output","paths":["build.rs"]}}],"rustflags":[],"metadata":0}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[\"default\", \"std\"]","target":7800718724727423882,"profile":14672114853574311971,"path":18360201026855538313,"deps":[[74873448883125965,"num_traits",false,4185534626512219472],[13053465359523334410,"build_script_build",false,2720251519998876714]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/num-integer-7ffaa77c542a0231/dep-lib-num_integer-7ffaa77c542a0231"}}],"rustflags":[],"metadata":58200369117550911}

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[\"default\", \"std\"]","target":10088282520713642473,"profile":9935990280773120926,"path":17268280674213731948,"deps":[[9245478811527615946,"autocfg",false,10666881358045532869]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/num-integer-86e8599f0ba8be3b/dep-build-script-build_script_build-86e8599f0ba8be3b"}}],"rustflags":[],"metadata":58200369117550911}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[\"std\"]","target":16894502179009968931,"profile":9935990280773120926,"path":12734757048507417164,"deps":[[74873448883125965,"build_script_build",false,1177636347299814283]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/num-traits-2d7b6f05babe375a/dep-lib-num_traits-2d7b6f05babe375a"}}],"rustflags":[],"metadata":14621636500951049976}

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"","target":0,"profile":0,"path":0,"deps":[[74873448883125965,"build_script_build",false,7876043645613464414]],"local":[{"RerunIfChanged":{"output":"debug/build/num-traits-30608ef2ad545d45/output","paths":["build.rs"]}}],"rustflags":[],"metadata":0}

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[\"std\"]","target":10088282520713642473,"profile":9935990280773120926,"path":8738564288946884329,"deps":[[9245478811527615946,"autocfg",false,10666881358045532869]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/num-traits-91eaf6e1267a55a4/dep-build-script-build_script_build-91eaf6e1267a55a4"}}],"rustflags":[],"metadata":14621636500951049976}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[\"std\"]","target":16894502179009968931,"profile":14672114853574311971,"path":12734757048507417164,"deps":[[74873448883125965,"build_script_build",false,1177636347299814283]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/num-traits-a49c1dcf894963a0/dep-lib-num_traits-a49c1dcf894963a0"}}],"rustflags":[],"metadata":14621636500951049976}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":4513600356512600704,"profile":9935990280773120926,"path":9794512189424769904,"deps":[[2637431931613344447,"primal_check",false,2927607459513826153],[14235317146973303535,"primal_sieve",false,8315863365335421],[16083193364972783737,"primal_estimate",false,1336457528261984209]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-88dc58402c39eabd/dep-lib-primal-88dc58402c39eabd"}}],"rustflags":[],"metadata":10541863805242775778}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":4659132901410725190,"profile":14672114853574311971,"path":8929134705354873327,"deps":[[8531466953748503375,"hamming",false,17880257272659949969]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-bit-63b2ee174012490a/dep-lib-primal_bit-63b2ee174012490a"}}],"rustflags":[],"metadata":16167354259392498579}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":4659132901410725190,"profile":9935990280773120926,"path":8929134705354873327,"deps":[[8531466953748503375,"hamming",false,1277698422196251306]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-bit-96677df9de002578/dep-lib-primal_bit-96677df9de002578"}}],"rustflags":[],"metadata":16167354259392498579}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":9822319782654175482,"profile":14672114853574311971,"path":13545799632343095798,"deps":[[13053465359523334410,"num_integer",false,1618221454193905130]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-check-2b3ef3828a3c368f/dep-lib-primal_check-2b3ef3828a3c368f"}}],"rustflags":[],"metadata":7493097427140581252}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":9822319782654175482,"profile":9935990280773120926,"path":13545799632343095798,"deps":[[13053465359523334410,"num_integer",false,14892837767277708699]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-check-45820c184352cf6a/dep-lib-primal_check-45820c184352cf6a"}}],"rustflags":[],"metadata":7493097427140581252}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":4513600356512600704,"profile":14672114853574311971,"path":9794512189424769904,"deps":[[2637431931613344447,"primal_check",false,5982062772994249340],[14235317146973303535,"primal_sieve",false,6852871306016931807],[16083193364972783737,"primal_estimate",false,7940873931919041175]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-e459515e4c44e256/dep-lib-primal-e459515e4c44e256"}}],"rustflags":[],"metadata":10541863805242775778}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":6950886450152894389,"profile":9935990280773120926,"path":14615040360027345179,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-estimate-501c201e57ed9082/dep-lib-primal_estimate-501c201e57ed9082"}}],"rustflags":[],"metadata":8867417447345094579}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":6950886450152894389,"profile":14672114853574311971,"path":14615040360027345179,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-estimate-6baf1b15c117fa9d/dep-lib-primal_estimate-6baf1b15c117fa9d"}}],"rustflags":[],"metadata":8867417447345094579}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

View file

@ -0,0 +1 @@
{"rustc":11295616921483704964,"features":"[]","target":4535063106481711439,"profile":14672114853574311971,"path":3258652851284269613,"deps":[[6317022804318982941,"smallvec",false,15494086491084722216],[16083193364972783737,"primal_estimate",false,7940873931919041175],[16094930107278604660,"primal_bit",false,12136058274187708498]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/primal-sieve-8771fba927dfbc70/dep-lib-primal_sieve-8771fba927dfbc70"}}],"rustflags":[],"metadata":5969421905829136718}

View file

@ -0,0 +1 @@
This file has an mtime of when this was started.

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