Giter VIP home page Giter VIP logo

Comments (4)

tommy-muehle avatar tommy-muehle commented on July 27, 2024 1

@benoitmasson That's totally right. Thanks for putting me on the right path! It's so easy sometimes 🙈

from go-mnd.

tommy-muehle avatar tommy-muehle commented on July 27, 2024

@benoitmasson
Thanks for the report. I'll check this asap.

from go-mnd.

tommy-muehle avatar tommy-muehle commented on July 27, 2024

Hi @benoitmasson,

I have made two attempts to implement this so far. Because I got your point. But the documentation isn't really helpful here and I also couldn't find a package which does a conversion of the numbers. Because for numbers like 1000 it seems easy on the first glance. But for example you can write 1234567890 like 1234_567_890 or 1_234_567_890 but also like this 1_234_567_89_0. So I need to generate this combinations in a general way to find every time all occurrences when you give me for example the number 1234567890 to ignore.

But unfortunately I couldn't find one so far. So that I'm stuck here and didn't have the time to go further here.

from go-mnd.

benoitmasson avatar benoitmasson commented on July 27, 2024

Generating all combinations can be done, as follows using recursion for example:

func generateNumberVariants(num int) []string {
	sign := ""
	if num < 0 {
		sign = "-"
		num = -num
	}

	return generateNumberVariantsAux(strconv.Itoa(num), sign)
}

func generateNumberVariantsAux(num, prefix string) []string {
	if len(num) <= 1 {
		return []string{prefix + num}
	}

	variantsWithoutUnderscore := generateNumberVariantsAux(num[1:], prefix+num[0:1])
	variantsWithUnderscore := generateNumberVariantsAux(num[1:], prefix+num[0:1]+"_")
	return append(
		variantsWithoutUnderscore,
		variantsWithUnderscore...,
	)
}

but it is computationally heavy, and generates a lot of elements if the input number is large (2^log(n) variants for n).

Wouldn't it be easier to do the opposite, i.e., for every magic number found in the code, normalize it by removing _'s and check whether this normalized form should be ignored?

from go-mnd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.