Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.7k
Project euler 22#1726
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
pomkarnath98 wants to merge22 commits intoTheAlgorithms:masterChoose a base branch frompomkarnath98:project-euler-22
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Project euler 22#1726
Changes fromall commits
Commits
Show all changes
22 commits Select commitHold shift + click to select a range
b7309f0
📦 NEW: Added solution for ProjectEuler-007
omkarnathparidad3a3b33
🐛 FIX: Spelling mistake fixes
omkarnathparidae9b5a6a
👌 IMPROVE: changed variable name from `inc` to `candidateValue` and t…
omkarnathparidae99c722
👌 IMPROVE: Modified the code
omkarnathparida5ac898f
Merge branch 'TheAlgorithms:master' into master
pomkarnath980f9f1ba
👌 IMPROVE: Added test case for ProjectEuler Problem001
omkarnathparida3caad5c
Merge branch 'TheAlgorithms:master' into master
pomkarnath98b7584fd
Merge branch 'TheAlgorithms:master' into master
pomkarnath986693f9c
Merge branch 'TheAlgorithms:master' into master
pomkarnath980830570
Merge branch 'TheAlgorithms:master' into master
pomkarnath984d7149c
Merge branch 'TheAlgorithms:master' into master
pomkarnath9853e3938
👌 IMPROVE: Added test cases for Project Euler Problem 4
omkarnathparida96224e7
👌 IMPROVE: auto prettier fixes
omkarnathparida718d515
Merge branch 'TheAlgorithms:master' into master
pomkarnath98396782d
Merge branch 'TheAlgorithms:master' into master
pomkarnath98944077b
Merge branch 'TheAlgorithms:master' into master
pomkarnath988d15caf
Merge branch 'TheAlgorithms:master' into master
pomkarnath9831aca33
📦 NEW: Project Euler 22 | Added solution and test cases
omkarnathparidad067a20
📦 NEW: Project Euler 22 | Added solution and test cases
omkarnathparidafb558fb
Updated Documentation in README.md
pomkarnath9815600f4
Merge branch 'master' into project-euler-22
omkarnathparida8d2c4b4
👌 IMPROVE: code improvement for codecov full coverage
omkarnathparidaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY", | ||
"LISA","NANCY","KAREN","BETTY","HELEN","SANDRA","DONNA","CAROL","RUTH","SHARON","MICHELLE", | ||
"LAURA","SARAH","KIMBERLY","DEBORAH","JESSICA","SHIRLEY","CYNTHIA","ANGELA","MELISSA","BRENDA", | ||
"AMY","ANNA","REBECCA","VIRGINIA","KATHLEEN","PAMELA","MARTHA","DEBRA","AMANDA","STEPHANIE", | ||
"CAROLYN","CHRISTINE","MARIE","JANET","CATHERINE","FRANCES","ANN","JOYCE","DIANE","ALICE", | ||
"JULIE","HEATHER","TERESA","DORIS","GLORIA","EVELYN","JEAN","CHERYL","MILDRED","KATHERINE", | ||
"JOAN","ASHLEY","JUDITH","ROSE","JANICE","KELLY","NICOLE","JUDY","CHRISTINA","KATHY", | ||
"THERESA","BEVERLY","DENISE","TAMMY","IRENE","JANE","LORI","RACHEL","MARILYN","ANDREA", | ||
"KATHRYN","LOUISE","SARA","ANNE","JACQUELINE","WANDA","BONNIE","JULIA","RUBY","LOIS", | ||
"TINA","PHYLLIS","NORMA","PAULA","DIANA","ANNIE","LILLIAN","EMILY","ROBIN","PEGGY", | ||
"CRYSTAL","GLADYS","RITA","DAWN","CONNIE","FLORENCE","TRACY","EDNA","TIFFANY","CARMEN", | ||
"ROSA","CINDY","GRACE","WENDY","VICTORIA","EDITH","KIM","SHERRY","SYLVIA","JOSEPHINE", | ||
"THELMA","SHANNON","SHEILA","ETHEL","ELLEN","ELAINE","MARJORIE","CARRIE","CHARLOTTE","MONICA", | ||
"ESTHER","PAULINE","EMMA","JUANITA","ANITA","RHONDA","HAZEL","AMBER","EVA","DEBBIE", | ||
"APRIL","LESLIE","CLARA","LUCILLE","JAMIE","JOANNE","ELEANOR","VALERIE","DANIELLE","MEGAN", | ||
"ALICIA","SUZANNE","MICHELE","GAIL","BERTHA","DARLENE","VERONICA","JILL","ERIN","GERALDINE", | ||
"LAUREN","CATHY","JOANN","LORRAINE","LYNN","SALLY","REGINA","ERICA","BEATRICE","DOLORES", | ||
"BERNICE","AUDREY","YVONNE","ANNETTE","JUNE","SAMANTHA","MARION","DANA","STACY","ANA", | ||
"RENEE","IDA","VIVIAN","ROBERTA","HOLLY","BRITTANY","MELANIE","LORETTA","YOLANDA","JEANETTE", | ||
"LAURIE","KATIE","KRISTEN","VANESSA","ALMA","SUE","ELSIE","BETH","JEANNE","VICKI", | ||
"CARLA","TARA","ROSEMARY","EILEEN","TERRI","GERTRUDE","LUCY","TONYA","ELLA","STACEY", | ||
"WILMA","GINA","KRISTIN","JESSIE","NATALIE","AGNES","VERA","WILLIE","CHARLENE","BESSIE", | ||
"DELORES","MELINDA","PEARL","ARLENE","MAUREEN","COLLEEN","ALLISON","TAMARA","JOY","GEORGIA", | ||
"CONSTANCE","LILLIE","CLAUDIA","JACKIE","MARCIA","TANYA","NELLIE","MINNIE","MARLENE","HEIDI", | ||
"GLENDA","LYDIA","VIOLA","COURTNEY","MARIAN","STELLA","CAROLINE","DORA","JO","VICKIE", | ||
"MATTIE","TERRY","MAXINE","IRMA","MABEL","MARSHA","MYRTLE","LENA","CHRISTY","DEANNA", | ||
"PATSY","HILDA","GWENDOLYN","JENNIE","NORA","MARGIE","NINA","CASSANDRA","LEAH","PENNY", | ||
"KAY","PRISCILLA","NAOMI","CAROLE","BRANDY","OLGA","BILLIE","DIANNE","TRACEY","LEONA", | ||
"JENNY","FELICIA","SONIA","MIRIAM","VELMA","BECKY","BOBBIE","VIOLET","KRISTINA","TONI", | ||
"MISTY","MAE","SHELLY","DAISY","RAMONA","SHERRI","ERIKA","KATRINA","CLAIRE","LINDSEY", | ||
"LINDSAY","GENEVA","GUADALUPE","BELINDA","MARGARITA","SHERYL","CORA","FAYE","ADA","NATASHA", | ||
"SABRINA","ISABEL","MARGUERITE","HATTIE","HARRIET","MOLLY","CECILIA","KRISTI","BRANDI","BLANCHE", | ||
"SANDY","ROSIE","JOANNA","IRIS","EUNICE","ANGIE","INEZ","LYNDA","MADELINE","AMELIA", | ||
"ALYSSA","KRISTY","CATHLEEN","ANGELINE","FRIEDA","ANTOINETTE","CECIL","JASMINE","NORMA","HANNAH", | ||
"SANDRA","KEISHA","CLAIRE","ELLA","TAMIKA","FANNIE","CELIA","PEGGY","MICHAELA","ALYSON", | ||
"ALTHEA","KENDRA","LORA","CORA","SHIRLEY","MATTIE","EMMA","MONICA","CATHY","ELEANOR", | ||
"REBECCA","TERESA","CLARA","PAMELA","SYLVIA","NANCY","FLORENCE","VICTORIA","ANITA","ELIZABETH", | ||
"JESSIE","LORRAINE","GERTRUDE","KATHERINE","VIVIAN","LOUISE","SUSAN","WANDA","PATRICIA","MARY","OMKARNATH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Names Scores | ||
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. | ||
For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 * 53 = 49714. | ||
What is the total of all the name scores in the file? | ||
*/ | ||
import fs from 'fs' | ||
export const getAlphabeticalValue = (name) => { | ||
return [...name].reduce( | ||
(sum, char) => sum + (char.charCodeAt(0) - 'A'.charCodeAt(0) + 1), | ||
0 | ||
) | ||
} | ||
export const calculateTotalNameScore = (filePath) => { | ||
return new Promise((resolve) => { | ||
fs.readFile(filePath, 'utf8', (_, data) => { | ||
const names = data.replace(/"/g, '').split(',').sort() | ||
const totalScore = names.reduce((total, name, index) => { | ||
const alphabeticalValue = getAlphabeticalValue(name) | ||
const nameScore = alphabeticalValue * (index + 1) | ||
return total + nameScore | ||
}, 0) | ||
resolve(totalScore) | ||
}) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { calculateTotalNameScore, getAlphabeticalValue } from './Problem022' | ||
const path = require('path') | ||
describe('getAlphabeticalValue', () => { | ||
it('should return correct alphabetical value for COLIN', () => { | ||
const name = 'COLIN' | ||
const expectedValue = 3 + 15 + 12 + 9 + 14 | ||
expect(getAlphabeticalValue(name)).toBe(expectedValue) | ||
}) | ||
it('should return correct alphabetical value for A', () => { | ||
const name = 'A' | ||
const expectedValue = 1 | ||
expect(getAlphabeticalValue(name)).toBe(expectedValue) | ||
}) | ||
it('should return correct alphabetical value for Z', () => { | ||
const name = 'Z' | ||
const expectedValue = 26 | ||
expect(getAlphabeticalValue(name)).toBe(expectedValue) | ||
}) | ||
}) | ||
describe('calculateTotalNameScore', () => { | ||
it('should correctly calculate the total name score', async () => { | ||
const namesFilePath = path.join(__dirname, 'Names.txt') | ||
const result = await calculateTotalNameScore(namesFilePath) | ||
const expectedScore = 4654143 | ||
expect(result).toBe(expectedScore) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.