question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests need to be rewritten/randomized in Project Euler: Problem 69: Totient maximum

See original GitHub issue

Describe your problem and how to reproduce it: I can just pass the challenge by typing

function totientMaximum() {
  // Good luck!
  return 510510;
}

Add a Link to the page with the problem: https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-69-totient-maximum

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
thecodingaviatorcommented, Jun 4, 2020

Thanks for reporting this @thecodingaviator. This is definitely something we want to improve over time.

I do agree that anyone who cheats is just cheating themselves, and a lot of the solutions are freely available online. Still, we want to avoid letting people return a single number and passing a challenge if possible.

One thing we’ve done is adapt the functions to take arguments, adjust the description, and add more tests. This one would be pretty easy to adapt because there’s a table with the answers in the description.

We could change the last sentence of the description to “Find the value of n ≤ limit for which n/φ(n) is a maximum.” Then we could add or adjust the tests so we’re checking for totientMaximum(10) and totientMaximum(1000000), which should return 6 and 510510, respectively.

Also we could add a solution like

function totientMaximum(limit) {
  let result = 1;
  const primes = [];
  let i = 0;

  const isPrime = num => {
    for (let i = 2; i <= Math.sqrt(num); i++) {
      if (num % i === 0) return false;
    }
    return num !== 0 && num !== 1;
  }
  
  for (let i = 2; i < 200; i++) {
    if (isPrime(i)) primes.push(i);
  }

  while(result * primes[i] < limit) {
    result *= primes[i];
    i++;
  }
  
  return result;
}

But that’s almost directly from this blog, so if there’s a more concise original solution, we should go with that.

What do you think @thecodingaviator and @Sky020?

Sounds awesome!

0reactions
moT01commented, Apr 23, 2021

I think we are safe to close this in favor of the issue linked above. Thanks for all the input on this everyone. If anyone thinks I am wrong in closing this, feel free to leave a comment and we can reopen it. Thanks and happy coding 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

My C++ solution for Project Euler 69: Totient maximum
Simple tests showed that all primes from 2 to 57 are sufficient. Modifications by HackerRank. The test best * nextPrime >= limit might...
Read more >
#69 Totient maximum - Project Euler
Problem 69. Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number of numbers less than n which ......
Read more >
Project Euler 69: Value for which n/φ(n) is a maximum.
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number of numbers less than n which are relatively...
Read more >
#69: Totient Maximum - Project Euler - YouTube
Here we'll discuss, analyze, and code a solution for Project Euler # 69 : Totient Maximum.------ Code and ResourcesFull code from the video...
Read more >
Project Euler #69: Totient maximum - HackerRank
This problem is a programming version of Problem 69 from projecteuler.net. Euler's Totient function, [sometimes called the phi function], ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found