5 Commits ffb7d34a1b ... c5d29954a9

Author SHA1 Message Date
  Frédéric G. MARAND c5d29954a9 14: Difference of squares. 2 weeks ago
  Frédéric G. MARAND 14fabc805b 12: Luhn. 1 month ago
  Frédéric G. MARAND 92d64f192f 11: Sieve. 1 month ago
  Frédéric G. MARAND c3ed69637c 10: Allergies. 1 month ago
  Frédéric G. MARAND ffb7d34a1b 12: Luhn. 1 month ago
40 changed files with 1086 additions and 0 deletions
  1. 13 0
      allergies/.eslintignore
  2. 38 0
      allergies/.eslintrc.cjs
  3. 23 0
      allergies/.exercism/config.json
  4. 1 0
      allergies/.exercism/metadata.json
  5. 3 0
      allergies/.yarn/releases/yarn-3.6.4.cjs
  6. 45 0
      allergies/HELP.md
  7. 47 0
      allergies/README.md
  8. 114 0
      allergies/allergies.test.ts
  9. 43 0
      allergies/allergies.ts
  10. 4 0
      allergies/babel.config.cjs
  11. 19 0
      allergies/jest.config.cjs
  12. 32 0
      allergies/package.json
  13. 28 0
      allergies/tsconfig.json
  14. 13 0
      difference-of-squares/.eslintignore
  15. 38 0
      difference-of-squares/.eslintrc.cjs
  16. 22 0
      difference-of-squares/.exercism/config.json
  17. 1 0
      difference-of-squares/.exercism/metadata.json
  18. 3 0
      difference-of-squares/.yarn/releases/yarn-3.6.4.cjs
  19. 45 0
      difference-of-squares/HELP.md
  20. 31 0
      difference-of-squares/README.md
  21. 4 0
      difference-of-squares/babel.config.cjs
  22. 53 0
      difference-of-squares/difference-of-squares.test.ts
  23. 21 0
      difference-of-squares/difference-of-squares.ts
  24. 19 0
      difference-of-squares/jest.config.cjs
  25. 32 0
      difference-of-squares/package.json
  26. 28 0
      difference-of-squares/tsconfig.json
  27. 13 0
      sieve/.eslintignore
  28. 38 0
      sieve/.eslintrc.cjs
  29. 23 0
      sieve/.exercism/config.json
  30. 1 0
      sieve/.exercism/metadata.json
  31. 3 0
      sieve/.yarn/releases/yarn-3.6.4.cjs
  32. 45 0
      sieve/HELP.md
  33. 56 0
      sieve/README.md
  34. 4 0
      sieve/babel.config.cjs
  35. 19 0
      sieve/jest.config.cjs
  36. 32 0
      sieve/package.json
  37. 36 0
      sieve/sieve.go
  38. 40 0
      sieve/sieve.test.ts
  39. 28 0
      sieve/sieve.ts
  40. 28 0
      sieve/tsconfig.json

+ 13 - 0
allergies/.eslintignore

@@ -0,0 +1,13 @@
+!.meta
+
+# Protected or generated
+.git
+.vscode
+
+# When using npm
+node_modules/*
+
+# Configuration files
+.eslintrc.cjs
+babel.config.cjs
+jest.config.cjs

+ 38 - 0
allergies/.eslintrc.cjs

@@ -0,0 +1,38 @@
+module.exports = {
+  root: true,
+  parserOptions: {
+    tsconfigRootDir: __dirname,
+    project: ['./tsconfig.json'],
+  },
+  overrides: [
+    // Student provided files
+    {
+      files: ['*.ts'],
+      excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
+      extends: '@exercism/eslint-config-typescript',
+    },
+    // Exercism given tests
+    {
+      files: ['*.test.ts'],
+      excludedFiles: ['custom.test.ts'],
+      env: {
+        jest: true,
+      },
+      extends: '@exercism/eslint-config-typescript/maintainers',
+    },
+    // Student provided tests
+    {
+      files: ['custom.test.ts'],
+      env: {
+        jest: true,
+      },
+      extends: '@exercism/eslint-config-typescript',
+    },
+    // Exercism provided files
+    {
+      files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
+      excludedFiles: ['custom.test.ts'],
+      extends: '@exercism/eslint-config-typescript/maintainers',
+    },
+  ],
+}

+ 23 - 0
allergies/.exercism/config.json

@@ -0,0 +1,23 @@
+{
+  "authors": [
+    "CRivasGomez"
+  ],
+  "contributors": [
+    "masters3d",
+    "SleeplessByte"
+  ],
+  "files": {
+    "solution": [
+      "allergies.ts"
+    ],
+    "test": [
+      "allergies.test.ts"
+    ],
+    "example": [
+      ".meta/proof.ci.ts"
+    ]
+  },
+  "blurb": "Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.",
+  "source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
+  "source_url": "https://turing.edu"
+}

+ 1 - 0
allergies/.exercism/metadata.json

@@ -0,0 +1 @@
+{"track":"typescript","exercise":"allergies","id":"3a845fcff99f4fd69cf0d78c3aad5e9f","url":"https://exercism.org/tracks/typescript/exercises/allergies","handle":"Fairgame","is_requester":true,"auto_approve":false}

File diff suppressed because it is too large
+ 3 - 0
allergies/.yarn/releases/yarn-3.6.4.cjs


+ 45 - 0
allergies/HELP.md

@@ -0,0 +1,45 @@
+# Help
+
+## Running the tests
+
+Execute the tests with:
+
+```bash
+$ yarn test
+```
+
+## Skipped tests
+
+In the test suites all tests but the first have been skipped.
+
+Once you get a test passing, you can enable the next one by changing `xit` to
+`it`.
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit allergies.ts` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [TypeScript track's documentation](https://exercism.org/docs/tracks/typescript)
+- The [TypeScript track's programming category on the forum](https://forum.exercism.org/c/programming/typescript)
+- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [TypeScript QuickStart](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html)
+- [ECMAScript 2015 Language Specification](https://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2015.pdf) (pdf)
+- [Mozilla JavaScript Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
+- [/r/typescript](https://www.reddit.com/r/typescript) is the TypeScript subreddit.
+- [StackOverflow](https://stackoverflow.com/questions/tagged/typescript) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

+ 47 - 0
allergies/README.md

@@ -0,0 +1,47 @@
+# Allergies
+
+Welcome to Allergies on Exercism's TypeScript Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
+
+An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for).
+
+The list of items (and their value) that were tested are:
+
+- eggs (1)
+- peanuts (2)
+- shellfish (4)
+- strawberries (8)
+- tomatoes (16)
+- chocolate (32)
+- pollen (64)
+- cats (128)
+
+So if Tom is allergic to peanuts and chocolate, he gets a score of 34.
+
+Now, given just that score of 34, your program should be able to say:
+
+- Whether Tom is allergic to any one of those allergens listed above.
+- All the allergens Tom is allergic to.
+
+Note: a given score may include allergens **not** listed above (i.e. allergens that score 256, 512, 1024, etc.).
+Your program should ignore those components of the score.
+For example, if the allergy score is 257, your program should only report the eggs (1) allergy.
+
+## Source
+
+### Created by
+
+- @CRivasGomez
+
+### Contributed to by
+
+- @masters3d
+- @SleeplessByte
+
+### Based on
+
+Exercise by the JumpstartLab team for students at The Turing School of Software and Design. - https://turing.edu

+ 114 - 0
allergies/allergies.test.ts

@@ -0,0 +1,114 @@
+import { Allergies } from './allergies'
+
+describe('allergicTo', () => {
+  it('no allergies means not allergic', () => {
+    const allergies = new Allergies(0)
+
+    expect(allergies.allergicTo('peanuts')).toBeFalsy()
+    expect(allergies.allergicTo('cats')).toBeFalsy()
+    expect(allergies.allergicTo('strawberries')).toBeFalsy()
+  })
+
+  xit('is allergic to eggs', () => {
+    const allergies = new Allergies(1)
+
+    expect(allergies.allergicTo('eggs')).toBeTruthy()
+  })
+
+  xit('allergic to eggs in addition to other stuff', () => {
+    const allergies = new Allergies(5)
+
+    expect(allergies.allergicTo('eggs')).toBeTruthy()
+    expect(allergies.allergicTo('shellfish')).toBeTruthy()
+    expect(allergies.allergicTo('strawberries')).toBeFalsy()
+  })
+})
+
+describe('list', () => {
+  xit('no allergies at all', () => {
+    const allergies = new Allergies(0)
+    const expected: string[] = []
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('allergic to just eggs', () => {
+    const allergies = new Allergies(1)
+    const expected = ['eggs']
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('allergic to just peanuts', () => {
+    const allergies = new Allergies(2)
+    const expected = ['peanuts']
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('allergic to just strawberries', () => {
+    const allergies = new Allergies(8)
+    const expected = ['strawberries']
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('allergic to eggs and peanuts', () => {
+    const allergies = new Allergies(3)
+    const expected = ['eggs', 'peanuts']
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('allergic to more than eggs but not peanuts', () => {
+    const allergies = new Allergies(5)
+    const expected = ['eggs', 'shellfish']
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('allergic to lots of stuff', () => {
+    const allergies = new Allergies(248)
+    const expected = ['strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats']
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('allergic to everything', () => {
+    const allergies = new Allergies(255)
+    const expected = [
+      'eggs',
+      'peanuts',
+      'shellfish',
+      'strawberries',
+      'tomatoes',
+      'chocolate',
+      'pollen',
+      'cats',
+    ]
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('ignore non allergen score parts', () => {
+    const allergies = new Allergies(509)
+    const expected = [
+      'eggs',
+      'shellfish',
+      'strawberries',
+      'tomatoes',
+      'chocolate',
+      'pollen',
+      'cats',
+    ]
+
+    expect(allergies.list()).toEqual(expected)
+  })
+
+  xit('ignore non allergen score parts, without highest valid score', () => {
+    const allergies = new Allergies(257)
+    const expected = ['eggs']
+
+    expect(allergies.list()).toEqual(expected)
+  })
+})

+ 43 - 0
allergies/allergies.ts

@@ -0,0 +1,43 @@
+type allergyMap = { [key: number]: string };
+
+let allergies:allergyMap = {
+    1: 'eggs',
+    2: 'peanuts',
+    4: 'shellfish',
+    8: 'strawberries',
+    16: 'tomatoes',
+    32: 'chocolate',
+    64: 'pollen',
+    128: 'cats',
+};
+
+export class Allergies {
+    private ids = 0;
+
+    constructor(allergenIndex: number) {
+        allergenIndex &= 255;
+        let i = 1;
+        while (i <= 128) {
+            if ((i & allergenIndex) !== 0) {
+                this.ids |= i;
+            }
+            i <<= 1;
+        }
+    }
+
+    public list(): string[] {
+        let i = 1;
+        let res: string[] = [];
+        while (i <= 128) {
+            if ((i & this.ids) !== 0) {
+                res.push(allergies[i])
+            }
+            i <<= 1;
+        }
+        return res;
+    }
+
+    public allergicTo(allergen: string): boolean {
+        return this.list().indexOf(allergen) >= 0;
+    }
+}

+ 4 - 0
allergies/babel.config.cjs

@@ -0,0 +1,4 @@
+module.exports = {
+  presets: ['@exercism/babel-preset-typescript'],
+  plugins: [],
+}

+ 19 - 0
allergies/jest.config.cjs

@@ -0,0 +1,19 @@
+module.exports = {
+  verbose: true,
+  projects: ['<rootDir>'],
+  testMatch: [
+    '**/__tests__/**/*.[jt]s?(x)',
+    '**/test/**/*.[jt]s?(x)',
+    '**/?(*.)+(spec|test).[jt]s?(x)',
+  ],
+  testPathIgnorePatterns: [
+    '/(?:production_)?node_modules/',
+    '.d.ts$',
+    '<rootDir>/test/fixtures',
+    '<rootDir>/test/helpers',
+    '__mocks__',
+  ],
+  transform: {
+    '^.+\\.[jt]sx?$': 'babel-jest',
+  },
+}

+ 32 - 0
allergies/package.json

@@ -0,0 +1,32 @@
+{
+  "name": "@exercism/typescript-allergies",
+  "version": "1.0.0",
+  "description": "Exercism exercises in Typescript.",
+  "private": true,
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/exercism/typescript"
+  },
+  "type": "module",
+  "engines": {
+    "node": "^18.16.0 || >=20.0.0"
+  },
+  "devDependencies": {
+    "@exercism/babel-preset-typescript": "^0.4.0",
+    "@exercism/eslint-config-typescript": "^0.5.0",
+    "@types/jest": "^29.5.2",
+    "@types/node": "~18.16.16",
+    "babel-jest": "^29.5.0",
+    "core-js": "~3.30.2",
+    "eslint": "^8.42.0",
+    "jest": "^29.5.0",
+    "typescript": "~5.0.4"
+  },
+  "scripts": {
+    "test": "yarn lint:types && jest --no-cache",
+    "lint": "yarn lint:types && yarn lint:ci",
+    "lint:types": "yarn tsc --noEmit -p .",
+    "lint:ci": "eslint . --ext .tsx,.ts"
+  },
+  "packageManager": "yarn@3.6.4"
+}

+ 28 - 0
allergies/tsconfig.json

@@ -0,0 +1,28 @@
+{
+  "display": "Configuration for Exercism TypeScript Exercises",
+  "compilerOptions": {
+    // Allows you to use the newest syntax, and have access to console.log
+    // https://www.typescriptlang.org/tsconfig#lib
+    "lib": ["ESNEXT", "dom"],
+    // Make sure typescript is configured to output ESM
+    // https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
+    "module": "ES2020",
+    // Since this project is using babel, TypeScript may target something very
+    // high, and babel will make sure it runs on your local Node version.
+    // https://babeljs.io/docs/en/
+    "target": "ESNext", // ESLint doesn't support this yet: "es2022",
+
+    "strict": true,
+    "esModuleInterop": true,
+    "skipLibCheck": true,
+    "forceConsistentCasingInFileNames": true,
+
+    // Because we'll be using babel: ensure that Babel can safely transpile
+    // files in the TypeScript project.
+    //
+    // https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
+    "isolatedModules": true
+  },
+  "include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
+  "exclude": ["node_modules"]
+}

+ 13 - 0
difference-of-squares/.eslintignore

@@ -0,0 +1,13 @@
+!.meta
+
+# Protected or generated
+.git
+.vscode
+
+# When using npm
+node_modules/*
+
+# Configuration files
+.eslintrc.cjs
+babel.config.cjs
+jest.config.cjs

+ 38 - 0
difference-of-squares/.eslintrc.cjs

@@ -0,0 +1,38 @@
+module.exports = {
+  root: true,
+  parserOptions: {
+    tsconfigRootDir: __dirname,
+    project: ['./tsconfig.json'],
+  },
+  overrides: [
+    // Student provided files
+    {
+      files: ['*.ts'],
+      excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
+      extends: '@exercism/eslint-config-typescript',
+    },
+    // Exercism given tests
+    {
+      files: ['*.test.ts'],
+      excludedFiles: ['custom.test.ts'],
+      env: {
+        jest: true,
+      },
+      extends: '@exercism/eslint-config-typescript/maintainers',
+    },
+    // Student provided tests
+    {
+      files: ['custom.test.ts'],
+      env: {
+        jest: true,
+      },
+      extends: '@exercism/eslint-config-typescript',
+    },
+    // Exercism provided files
+    {
+      files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
+      excludedFiles: ['custom.test.ts'],
+      extends: '@exercism/eslint-config-typescript/maintainers',
+    },
+  ],
+}

+ 22 - 0
difference-of-squares/.exercism/config.json

@@ -0,0 +1,22 @@
+{
+  "authors": [],
+  "contributors": [
+    "masters3d",
+    "Scientifica96",
+    "SleeplessByte"
+  ],
+  "files": {
+    "solution": [
+      "difference-of-squares.ts"
+    ],
+    "test": [
+      "difference-of-squares.test.ts"
+    ],
+    "example": [
+      ".meta/proof.ci.ts"
+    ]
+  },
+  "blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.",
+  "source": "Problem 6 at Project Euler",
+  "source_url": "https://projecteuler.net/problem=6"
+}

+ 1 - 0
difference-of-squares/.exercism/metadata.json

@@ -0,0 +1 @@
+{"track":"typescript","exercise":"difference-of-squares","id":"f8956bff576543d7b33cdc91216601d0","url":"https://exercism.org/tracks/typescript/exercises/difference-of-squares","handle":"Fairgame","is_requester":true,"auto_approve":false}

File diff suppressed because it is too large
+ 3 - 0
difference-of-squares/.yarn/releases/yarn-3.6.4.cjs


+ 45 - 0
difference-of-squares/HELP.md

@@ -0,0 +1,45 @@
+# Help
+
+## Running the tests
+
+Execute the tests with:
+
+```bash
+$ yarn test
+```
+
+## Skipped tests
+
+In the test suites all tests but the first have been skipped.
+
+Once you get a test passing, you can enable the next one by changing `xit` to
+`it`.
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit difference-of-squares.ts` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [TypeScript track's documentation](https://exercism.org/docs/tracks/typescript)
+- The [TypeScript track's programming category on the forum](https://forum.exercism.org/c/programming/typescript)
+- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [TypeScript QuickStart](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html)
+- [ECMAScript 2015 Language Specification](https://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2015.pdf) (pdf)
+- [Mozilla JavaScript Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
+- [/r/typescript](https://www.reddit.com/r/typescript) is the TypeScript subreddit.
+- [StackOverflow](https://stackoverflow.com/questions/tagged/typescript) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

+ 31 - 0
difference-of-squares/README.md

@@ -0,0 +1,31 @@
+# Difference of Squares
+
+Welcome to Difference of Squares on Exercism's TypeScript Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.
+
+The square of the sum of the first ten natural numbers is
+(1 + 2 + ... + 10)² = 55² = 3025.
+
+The sum of the squares of the first ten natural numbers is
+1² + 2² + ... + 10² = 385.
+
+Hence the difference between the square of the sum of the first ten natural numbers and the sum of the squares of the first ten natural numbers is 3025 - 385 = 2640.
+
+You are not expected to discover an efficient solution to this yourself from first principles; research is allowed, indeed, encouraged.
+Finding the best algorithm for the problem is a key skill in software engineering.
+
+## Source
+
+### Contributed to by
+
+- @masters3d
+- @Scientifica96
+- @SleeplessByte
+
+### Based on
+
+Problem 6 at Project Euler - https://projecteuler.net/problem=6

+ 4 - 0
difference-of-squares/babel.config.cjs

@@ -0,0 +1,4 @@
+module.exports = {
+  presets: ['@exercism/babel-preset-typescript'],
+  plugins: [],
+}

+ 53 - 0
difference-of-squares/difference-of-squares.test.ts

@@ -0,0 +1,53 @@
+import { Squares } from './difference-of-squares';
+
+// eslint-disable-next-line no-global-assign
+xit = it
+describe('Squares', () => {
+  describe('up to 5', () => {
+    const squares = new Squares(5)
+
+    it('gets the square of sum', () => {
+      expect(squares.squareOfSum).toBe(225)
+    })
+
+    xit('gets the sum of squares', () => {
+      expect(squares.sumOfSquares).toBe(55)
+    })
+
+    xit('gets the difference', () => {
+      expect(squares.difference).toBe(170)
+    })
+  })
+
+  describe('up to 10', () => {
+    const squares = new Squares(10)
+
+    xit('gets the square of sum', () => {
+      expect(squares.squareOfSum).toBe(3025)
+    })
+
+    xit('gets the sum of squares', () => {
+      expect(squares.sumOfSquares).toBe(385)
+    })
+
+    xit('gets the difference', () => {
+      expect(squares.difference).toBe(2640)
+    })
+  })
+
+  describe('up to 100', () => {
+    const squares = new Squares(100)
+
+    xit('gets the square of sum', () => {
+      expect(squares.squareOfSum).toBe(25502500)
+    })
+
+    xit('gets the sum of squares', () => {
+      expect(squares.sumOfSquares).toBe(338350)
+    })
+
+    xit('gets the difference', () => {
+      expect(squares.difference).toBe(25164150)
+    })
+  })
+})

+ 21 - 0
difference-of-squares/difference-of-squares.ts

@@ -0,0 +1,21 @@
+export class Squares {
+    constructor(private count: number) {
+    }
+
+    get sumOfSquares(): number {
+        let sum = 0;
+        for (let i = 0; i <= this.count; i++) {
+            sum += i * i;
+        }
+        return sum;
+    }
+
+    get squareOfSum(): number {
+        let sum = this.count * (this.count + 1) / 2;
+        return sum * sum;
+    }
+
+    get difference(): number {
+        return this.squareOfSum-this.sumOfSquares;
+    }
+}

+ 19 - 0
difference-of-squares/jest.config.cjs

@@ -0,0 +1,19 @@
+module.exports = {
+  verbose: true,
+  projects: ['<rootDir>'],
+  testMatch: [
+    '**/__tests__/**/*.[jt]s?(x)',
+    '**/test/**/*.[jt]s?(x)',
+    '**/?(*.)+(spec|test).[jt]s?(x)',
+  ],
+  testPathIgnorePatterns: [
+    '/(?:production_)?node_modules/',
+    '.d.ts$',
+    '<rootDir>/test/fixtures',
+    '<rootDir>/test/helpers',
+    '__mocks__',
+  ],
+  transform: {
+    '^.+\\.[jt]sx?$': 'babel-jest',
+  },
+}

+ 32 - 0
difference-of-squares/package.json

@@ -0,0 +1,32 @@
+{
+  "name": "@exercism/typescript-difference-of-squares",
+  "version": "1.0.0",
+  "description": "Exercism exercises in Typescript.",
+  "private": true,
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/exercism/typescript"
+  },
+  "type": "module",
+  "engines": {
+    "node": "^18.16.0 || >=20.0.0"
+  },
+  "devDependencies": {
+    "@exercism/babel-preset-typescript": "^0.4.0",
+    "@exercism/eslint-config-typescript": "^0.5.0",
+    "@types/jest": "^29.5.2",
+    "@types/node": "~18.16.16",
+    "babel-jest": "^29.5.0",
+    "core-js": "~3.30.2",
+    "eslint": "^8.42.0",
+    "jest": "^29.5.0",
+    "typescript": "~5.0.4"
+  },
+  "scripts": {
+    "test": "yarn lint:types && jest --no-cache",
+    "lint": "yarn lint:types && yarn lint:ci",
+    "lint:types": "yarn tsc --noEmit -p .",
+    "lint:ci": "eslint . --ext .tsx,.ts"
+  },
+  "packageManager": "yarn@3.6.4"
+}

+ 28 - 0
difference-of-squares/tsconfig.json

@@ -0,0 +1,28 @@
+{
+  "display": "Configuration for Exercism TypeScript Exercises",
+  "compilerOptions": {
+    // Allows you to use the newest syntax, and have access to console.log
+    // https://www.typescriptlang.org/tsconfig#lib
+    "lib": ["ESNEXT", "dom"],
+    // Make sure typescript is configured to output ESM
+    // https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
+    "module": "ES2020",
+    // Since this project is using babel, TypeScript may target something very
+    // high, and babel will make sure it runs on your local Node version.
+    // https://babeljs.io/docs/en/
+    "target": "ESNext", // ESLint doesn't support this yet: "es2022",
+
+    "strict": true,
+    "esModuleInterop": true,
+    "skipLibCheck": true,
+    "forceConsistentCasingInFileNames": true,
+
+    // Because we'll be using babel: ensure that Babel can safely transpile
+    // files in the TypeScript project.
+    //
+    // https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
+    "isolatedModules": true
+  },
+  "include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
+  "exclude": ["node_modules"]
+}

+ 13 - 0
sieve/.eslintignore

@@ -0,0 +1,13 @@
+!.meta
+
+# Protected or generated
+.git
+.vscode
+
+# When using npm
+node_modules/*
+
+# Configuration files
+.eslintrc.cjs
+babel.config.cjs
+jest.config.cjs

+ 38 - 0
sieve/.eslintrc.cjs

@@ -0,0 +1,38 @@
+module.exports = {
+  root: true,
+  parserOptions: {
+    tsconfigRootDir: __dirname,
+    project: ['./tsconfig.json'],
+  },
+  overrides: [
+    // Student provided files
+    {
+      files: ['*.ts'],
+      excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
+      extends: '@exercism/eslint-config-typescript',
+    },
+    // Exercism given tests
+    {
+      files: ['*.test.ts'],
+      excludedFiles: ['custom.test.ts'],
+      env: {
+        jest: true,
+      },
+      extends: '@exercism/eslint-config-typescript/maintainers',
+    },
+    // Student provided tests
+    {
+      files: ['custom.test.ts'],
+      env: {
+        jest: true,
+      },
+      extends: '@exercism/eslint-config-typescript',
+    },
+    // Exercism provided files
+    {
+      files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
+      excludedFiles: ['custom.test.ts'],
+      extends: '@exercism/eslint-config-typescript/maintainers',
+    },
+  ],
+}

+ 23 - 0
sieve/.exercism/config.json

@@ -0,0 +1,23 @@
+{
+  "authors": [
+    "CRivasGomez"
+  ],
+  "contributors": [
+    "masters3d",
+    "SleeplessByte"
+  ],
+  "files": {
+    "solution": [
+      "sieve.ts"
+    ],
+    "test": [
+      "sieve.test.ts"
+    ],
+    "example": [
+      ".meta/proof.ci.ts"
+    ]
+  },
+  "blurb": "Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.",
+  "source": "Sieve of Eratosthenes at Wikipedia",
+  "source_url": "https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes"
+}

+ 1 - 0
sieve/.exercism/metadata.json

@@ -0,0 +1 @@
+{"track":"typescript","exercise":"sieve","id":"a8587f6bfdd44b698aeb82535c7cd3ce","url":"https://exercism.org/tracks/typescript/exercises/sieve","handle":"Fairgame","is_requester":true,"auto_approve":false}

File diff suppressed because it is too large
+ 3 - 0
sieve/.yarn/releases/yarn-3.6.4.cjs


+ 45 - 0
sieve/HELP.md

@@ -0,0 +1,45 @@
+# Help
+
+## Running the tests
+
+Execute the tests with:
+
+```bash
+$ yarn test
+```
+
+## Skipped tests
+
+In the test suites all tests but the first have been skipped.
+
+Once you get a test passing, you can enable the next one by changing `xit` to
+`it`.
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit sieve.ts` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [TypeScript track's documentation](https://exercism.org/docs/tracks/typescript)
+- The [TypeScript track's programming category on the forum](https://forum.exercism.org/c/programming/typescript)
+- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [TypeScript QuickStart](https://www.typescriptlang.org/docs/handbook/release-notes/overview.html)
+- [ECMAScript 2015 Language Specification](https://www.ecma-international.org/wp-content/uploads/ECMA-262_6th_edition_june_2015.pdf) (pdf)
+- [Mozilla JavaScript Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)
+- [/r/typescript](https://www.reddit.com/r/typescript) is the TypeScript subreddit.
+- [StackOverflow](https://stackoverflow.com/questions/tagged/typescript) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

+ 56 - 0
sieve/README.md

@@ -0,0 +1,56 @@
+# Sieve
+
+Welcome to Sieve on Exercism's TypeScript Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Introduction
+
+You bought a big box of random computer parts at a garage sale.
+You've started putting the parts together to build custom computers.
+
+You want to test the performance of different combinations of parts, and decide to create your own benchmarking program to see how your computers compare.
+You choose the famous "Sieve of Eratosthenes" algorithm, an ancient algorithm, but one that should push your computers to the limits.
+
+## Instructions
+
+Your task is to create a program that implements the Sieve of Eratosthenes algorithm to find prime numbers.
+
+A prime number is a number that is only divisible by 1 and itself.
+For example, 2, 3, 5, 7, 11, and 13 are prime numbers.
+
+The Sieve of Eratosthenes is an ancient algorithm that works by taking a list of numbers and crossing out all the numbers that aren't prime.
+
+A number that is **not** prime is called a "composite number".
+
+To use the Sieve of Eratosthenes, you first create a list of all the numbers between 2 and your given number.
+Then you repeat the following steps:
+
+1. Find the next unmarked number in your list. This is a prime number.
+2. Mark all the multiples of that prime number as composite (not prime).
+
+You keep repeating these steps until you've gone through every number in your list.
+At the end, all the unmarked numbers are prime.
+
+~~~~exercism/note
+[Wikipedia's Sieve of Eratosthenes article][eratosthenes] has a useful graphic that explains the algorithm.
+
+The tests don't check that you've implemented the algorithm, only that you've come up with the correct list of primes.
+A good first test is to check that you do not use division or remainder operations.
+
+[eratosthenes]: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
+~~~~
+
+## Source
+
+### Created by
+
+- @CRivasGomez
+
+### Contributed to by
+
+- @masters3d
+- @SleeplessByte
+
+### Based on
+
+Sieve of Eratosthenes at Wikipedia - https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

+ 4 - 0
sieve/babel.config.cjs

@@ -0,0 +1,4 @@
+module.exports = {
+  presets: ['@exercism/babel-preset-typescript'],
+  plugins: [],
+}

+ 19 - 0
sieve/jest.config.cjs

@@ -0,0 +1,19 @@
+module.exports = {
+  verbose: true,
+  projects: ['<rootDir>'],
+  testMatch: [
+    '**/__tests__/**/*.[jt]s?(x)',
+    '**/test/**/*.[jt]s?(x)',
+    '**/?(*.)+(spec|test).[jt]s?(x)',
+  ],
+  testPathIgnorePatterns: [
+    '/(?:production_)?node_modules/',
+    '.d.ts$',
+    '<rootDir>/test/fixtures',
+    '<rootDir>/test/helpers',
+    '__mocks__',
+  ],
+  transform: {
+    '^.+\\.[jt]sx?$': 'babel-jest',
+  },
+}

+ 32 - 0
sieve/package.json

@@ -0,0 +1,32 @@
+{
+  "name": "@exercism/typescript-sieve",
+  "version": "1.0.0",
+  "description": "Exercism exercises in Typescript.",
+  "private": true,
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/exercism/typescript"
+  },
+  "type": "module",
+  "engines": {
+    "node": "^18.16.0 || >=20.0.0"
+  },
+  "devDependencies": {
+    "@exercism/babel-preset-typescript": "^0.4.0",
+    "@exercism/eslint-config-typescript": "^0.5.0",
+    "@types/jest": "^29.5.2",
+    "@types/node": "~18.16.16",
+    "babel-jest": "^29.5.0",
+    "core-js": "~3.30.2",
+    "eslint": "^8.42.0",
+    "jest": "^29.5.0",
+    "typescript": "~5.0.4"
+  },
+  "scripts": {
+    "test": "yarn lint:types && jest --no-cache",
+    "lint": "yarn lint:types && yarn lint:ci",
+    "lint:types": "yarn tsc --noEmit -p .",
+    "lint:ci": "eslint . --ext .tsx,.ts"
+  },
+  "packageManager": "yarn@3.6.4"
+}

+ 36 - 0
sieve/sieve.go

@@ -0,0 +1,36 @@
+package sieve
+
+import "log"
+
+const (
+	Maybe = iota
+	Prime
+	NotPrime
+)
+
+func Sieve(limit int) []int {
+	all := make([]int, limit+1)
+	all[0] = NotPrime
+	all[1] = NotPrime
+	for i := 2; i <= limit; i++ {
+		all[i] = Maybe
+	}
+
+	for i := 2; i <= limit; i++ {
+		if all[i] == NotPrime {
+			continue
+		}
+		all[i] = Prime
+		for j := 2; j <= limit/i; j++ {
+			all[i*j] = NotPrime
+		}
+		log.Printf("After %3d: %v\n", i, all)
+	}
+	res := make([]int, 0, len(all))
+	for i, v := range all {
+		if v == Prime {
+			res = append(res, i)
+		}
+	}
+	return res
+}

+ 40 - 0
sieve/sieve.test.ts

@@ -0,0 +1,40 @@
+import { primes } from './sieve'
+
+describe('Sieve', () => {
+  it('no primes under two', () => {
+    const expected: number[] = []
+    expect(primes(1)).toEqual(expected)
+  })
+
+  xit('find first prime', () => {
+    const expected = [2]
+    expect(primes(2)).toEqual(expected)
+  })
+
+  xit('find primes up to 10', () => {
+    const expected = [2, 3, 5, 7]
+    expect(primes(10)).toEqual(expected)
+  })
+
+  xit('limit is prime', () => {
+    const expected = [2, 3, 5, 7, 11, 13]
+    expect(primes(13)).toEqual(expected)
+  })
+
+  xit('find primes up to 1000', () => {
+    const expected: number[] = [
+      2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
+      71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
+      151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
+      233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
+      317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
+      419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499,
+      503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
+      607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691,
+      701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
+      811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907,
+      911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,
+    ]
+    expect(primes(1000)).toEqual(expected)
+  })
+})

+ 28 - 0
sieve/sieve.ts

@@ -0,0 +1,28 @@
+enum State {
+    Maybe = 0,
+    Prime,
+    NotPrime,
+}
+
+export function primes(limit: number): number[] {
+    const all: number[] = Array(limit + 1).fill(State.Maybe);
+    all[0] = State.NotPrime;
+    all[1] = State.NotPrime;
+    for (let i = 2; i <= limit; i++) {
+        if (all[i] === State.NotPrime) {
+            continue;
+        }
+        all[i] = State.Prime;
+        for (let j = 2; j <= limit / i; j++) {
+            all[i * j] = State.NotPrime;
+        }
+    }
+    const res: number[] = [];
+    let property: keyof typeof all;
+    for (property in all) {
+        if (all[property] === State.Prime) {
+            res.push(Number(property));
+        }
+    }
+    return res;
+}

+ 28 - 0
sieve/tsconfig.json

@@ -0,0 +1,28 @@
+{
+  "display": "Configuration for Exercism TypeScript Exercises",
+  "compilerOptions": {
+    // Allows you to use the newest syntax, and have access to console.log
+    // https://www.typescriptlang.org/tsconfig#lib
+    "lib": ["ESNEXT", "dom"],
+    // Make sure typescript is configured to output ESM
+    // https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
+    "module": "ES2020",
+    // Since this project is using babel, TypeScript may target something very
+    // high, and babel will make sure it runs on your local Node version.
+    // https://babeljs.io/docs/en/
+    "target": "ESNext", // ESLint doesn't support this yet: "es2022",
+
+    "strict": true,
+    "esModuleInterop": true,
+    "skipLibCheck": true,
+    "forceConsistentCasingInFileNames": true,
+
+    // Because we'll be using babel: ensure that Babel can safely transpile
+    // files in the TypeScript project.
+    //
+    // https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
+    "isolatedModules": true
+  },
+  "include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
+  "exclude": ["node_modules"]
+}

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