add somemore stuff.

This commit is contained in:
matt 2023-08-02 11:27:21 -07:00
parent d063f452d1
commit ab4974855a
7 changed files with 199 additions and 8 deletions

5
.classpath Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path="bin/default"/>
</classpath>

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.gradle
/build/
/bin/
# Ignore Gradle GUI config
gradle-app.setting

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>project</name>
<comment>Project java-projects created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/usr/lib/jvm/java-11-openjdk-amd64
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true

View File

@ -23,7 +23,7 @@ dependencies {
}
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
implementation 'org.springframework.boot:spring-boot-devtools:2.2.6.RELEASE'
compile('org.springframework.boot:spring-boot-devtools:2.2.6.RELEASE')
sourceSets {
main {

60
dict1.txt Normal file
View File

@ -0,0 +1,60 @@
abash
aura
bar
barb
bee
beg
blush
bog
bogus
bough
bow
brew
briar
brow
brush
bug
bugs
bus
but
egg
ego
erg
ghost
go
goes
gorge
gosh
grew
grow
grub
gush
he
her
here
hew
hog
hose
how
hub
hug
huh
hush
owe
rub
sew
she
shrub
shrug
sir
sub
surge
swore
web
wee
were
whore
whose
woe
wore
worse

View File

@ -1,5 +1,7 @@
package com.matthewjensen.project;
import com.matthewjensen.project.modules.Anagrams;
import com.matthewjensen.project.modules.LetterInventory;
import com.matthewjensen.project.modules.AnagramMain;
import java.io.FileNotFoundException;
@ -7,6 +9,9 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.*;
import java.io.*;
import org.slf4j.*;
@SpringBootApplication
public class ProjectApplication {
@ -18,16 +23,100 @@ public class ProjectApplication {
}
@RestController
class TwentyQuestions {
private static final Logger logger = LoggerFactory.getLogger(TwentyQuestions.class);
@RequestMapping("/")
public void home() {
if (1 == 1) {
logger.info("Hello mobile user!");
} else if (3 == 3) {
logger.info("Hello tablet user!");
} else {
logger.info("Hello desktop user!");
}
}
// dictionary file to use for input (change to dict2, dict3)
private static final String DICTIONARY_FILE = "dict1.txt";
// set to true to test runtime and # of letter inventories created
private static final boolean TIMING = true;
private static final boolean DEBUG = true;
@RequestMapping("/20questions")
String index() {
//AnagramMain anagram = new AnagramMain();
public String index() throws FileNotFoundException {
System.out.println("Welcome to the CS 145 anagram solver.");
System.out.println("Using dictionary file " + DICTIONARY_FILE + ".");
// read dictionary into a set
Scanner input = new Scanner(new File(DICTIONARY_FILE));
Set<String> dictionary = new TreeSet<String>();
while (input.hasNextLine()) {
dictionary.add(input.nextLine());
}
dictionary = Collections.unmodifiableSet(dictionary); // read-only
// create Anagrams object for, well, solving anagrams
Anagrams solver = new Anagrams(dictionary);
// get first phrase to solve
Scanner console = new Scanner(System.in);
String phrase = getPhrase(console);
//String[] args = new String[4];
//try {
// anagram.main(args);
//} catch (FileNotFoundException e){
//}
int i = 0;
// loop to get/solve each phrase
while (phrase.length() > 0 || i > 1) {
i++;
System.out.println("All words found in \"" + phrase + "\":");
Set<String> allWords = solver.getWords(phrase);
System.out.println(allWords);
System.out.println();
System.out.print("Max words to include (Enter for no max)? ");
String line;
if (DEBUG) {
line = "4";
} else {
line = console.nextLine().trim();
}
long startTime = System.currentTimeMillis();
if (line.length() > 0) {
// use a max
int max = new Scanner(line).nextInt();
solver.print(phrase, max); // print all anagrams of phrase
} else {
// no max
solver.print(phrase); // print all anagrams of phrase
}
long endTime = System.currentTimeMillis();
System.out.println();
// 12247 ms elapsed, 2594392 unique LetterInventory object(s) created
if (TIMING) {
long elapsed = endTime - startTime;
int inventories = LetterInventory.getInstanceCount();
System.out.println(elapsed + " ms elapsed, " + inventories +
" unique LetterInventory object(s) created");
LetterInventory.resetInstanceCount();
}
// get next phrase to solve
phrase = getPhrase(console);
}
return "Hello There";
}
// Helper to prompt for a phrase to generate anagrams.
public static String getPhrase(Scanner console) {
return "hello";
/*
System.out.println();
System.out.print("Phrase to scramble (Enter to quit)? ");
String phrase = console.nextLine().trim();
if (DEBUG) {
phrase = "barbara bush";
}
return phrase;
*/
}
}