-
Notifications
You must be signed in to change notification settings - Fork 20
Ocelots - Ya-Juan Ruan #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b4aff5d
0d138c8
1965ed3
59ec567
f191d4c
aeefa09
96f7cbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| }, | ||
| "dependencies": { | ||
| "core-js": "^3.8.0", | ||
| "package.json": "^2.0.1", | ||
| "vorpal": "^1.12.0" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,116 @@ | ||
| export const drawLetters = () => { | ||
| // Implement this method for wave 1 | ||
| const letterMap = { | ||
| 'A': 9, | ||
| 'B': 2, | ||
| 'C': 2, | ||
| 'D': 4, | ||
| 'E': 12, | ||
| 'F': 2, | ||
| 'G': 3, | ||
| 'H': 2, | ||
| 'I': 9, | ||
| 'J': 1, | ||
| 'K': 1, | ||
| 'L': 4, | ||
| 'M': 2, | ||
| 'N': 6, | ||
| 'O': 8, | ||
| 'P': 2, | ||
| 'Q': 1, | ||
| 'R': 6, | ||
| 'S': 4, | ||
| 'T': 6, | ||
| 'U': 4, | ||
| 'V': 2, | ||
| 'W': 2, | ||
| 'X': 1, | ||
| 'Y': 2, | ||
| 'Z': 1 | ||
| }; | ||
|
|
||
| export const usesAvailableLetters = (input, lettersInHand) => { | ||
| // Implement this method for wave 2 | ||
| const old_score_chart = { | ||
| "A": 1, "E": 1, "I": 1, "O": 1, "U": 1, "L": 1, "N": 1, "R": 1, "S": 1, "T": 1, "D": 2, "G": 2, "B": 3, | ||
| "C": 3, "M": 3, "P": 3, "F": 4, "H": 4, "V": 4, "W": 4, "Y": 4, "K": 5, "J": 8, "X": 8, "Q": 10, "Z": 10 | ||
| }; | ||
|
|
||
| export const scoreWord = (word) => { | ||
| // Implement this method for wave 3 | ||
| }; | ||
| export class Adagrams{ | ||
| constructor(){ | ||
| this.letterPool = []; | ||
| for (let alphabet in letterMap){ | ||
| let times = letterMap[alphabet]; | ||
| for (let i=0; i<times; ++i) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh, this is how I think about setting up the pool, with the appropriate stats for picking a random letter with a given frequency distribution for each letter, too! |
||
| this.letterPool.push(alphabet); | ||
| } | ||
| this.score_chart = new Map(Object.entries(old_score_chart)); | ||
| } | ||
|
|
||
| export const highestScoreFrom = (words) => { | ||
| // Implement this method for wave 4 | ||
| }; | ||
| drawLetters(){ | ||
| const letterBank = []; | ||
| let length = this.letterPool.length; | ||
|
|
||
| while (letterBank.length < 10){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loops makes sense, and I don't think you really have to worry about it here, but when I see |
||
| let index = Math.floor(Math.random()*length); | ||
| letterBank.push(this.letterPool[index]); | ||
| length --; | ||
| [this.letterPool[index], this.letterPool[length]] = [this.letterPool[length],this.letterPool[index]]; | ||
| } | ||
| return letterBank; | ||
| }; | ||
|
|
||
| usesAvailableLetters(input, lettersInHand){ | ||
| const letterCount = new Map(); | ||
| for (const letter of lettersInHand){ | ||
| let count = letterCount.get(letter); | ||
| if (count === undefined){ | ||
| count = 0; | ||
| } | ||
| count ++; | ||
| letterCount.set(letter, count); | ||
| } | ||
|
|
||
| for (const cha of input){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might like to see something like 'inputLetter'-- I think 'cha' is short for 'character', here? ('character' may be a reserved word in javascript-- I'd have to double check) |
||
| let cur_count = letterCount.get(cha); | ||
| if (cur_count === undefined || cur_count === 0){ | ||
| return false; | ||
| } | ||
| cur_count --; | ||
| letterCount.set(cha, cur_count); | ||
| } | ||
| return true; | ||
|
|
||
| }; | ||
|
|
||
| scoreWord(word){ | ||
| let totalScore = 0; | ||
| for (let cha of word){ | ||
| cha = cha.toUpperCase(); | ||
| let score = this.score_chart.get(cha); | ||
| totalScore += score; | ||
| } | ||
| if (word.length > 6){ | ||
| totalScore += 8; | ||
| } | ||
| return totalScore; | ||
| }; | ||
|
|
||
| highestScoreFrom(words){ | ||
| let cur_winner; | ||
| let cur_score = 0; | ||
|
|
||
| for (const word of words){ | ||
| let score = this.scoreWord(word); | ||
| if (score > cur_score){ | ||
| cur_winner = word; | ||
| cur_score = score; | ||
| } | ||
| else if (score == cur_score){ | ||
| if (cur_winner.length === 10){ | ||
| continue; | ||
| } | ||
| else if (word.length === 10 || word.length < cur_winner.length){ | ||
| cur_winner = word; | ||
| } | ||
| } | ||
| } | ||
| return {word: cur_winner, score: cur_score}; | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice use of OOP!