Programming Megathread

Author Topic: Programming Megathread  (Read 105689 times)

oh sure
i'll go ahead and pm one to you if you want
you might as well just post it here. there's no reason for the challenge alone to be private, and that way you can have other people help, and some people could even try to solve it themselves

sure then

i'm having a bit of a problem with this kata:

Code: [Select]
In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!

Examples:

1,9 -> 1,2,3,4,6,7,8,9 -> Result 8
4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12
The result may contain fives. ;-)
The start number will always be smaller than the end number. Both numbers can be also negative!

i was thinking about something like making a list such as this:

Code: [Select]
def dont_give_me_five(start,end):
    n = []
    if n == 5:
        n.remove()
    return n   # amount of numbers

i'm guessing it's not entirely correct but that's what i did try\

you could say i got some idea, but the execution is bad lol
« Last Edit: October 29, 2016, 11:36:46 AM by Timestamp »

It says remove all numbers with a five in it, not just five
So 15, 25, 52, etc

You'll want a for loop for each number n between start and end,
if n does not contain 5, increment a counter

It says remove all numbers with a five in it, not just five
So 15, 25, 52, etc

You'll want a for loop for each number n between start and end,
if n does not contain 5, increment a counter

ahh, thanks

ATM at the ACM event at university of Utah
Warnock (UofU) is in the lead finishing 6, failing on 1

i'm having a bit of a problem with this kata:

Code: [Select]
In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!
Examples:
1,9 -> 1,2,3,4,6,7,8,9 -> Result 8
4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12
The result may contain fives. ;-)
The start number will always be smaller than the end number. Both numbers can be also negative!

you could say i got some idea, but the execution is bad lol

Ah, this one is a pretty good practice problem. Let's not worry about the 5 rule for now and just devise a solution for finding the count. If we're given two numbers, we can turn them into a list with the range() command. Then we can iterate and count that.

Our prototype function will look like:
Code: [Select]
def counter(start, end):
    nums = range(start, end+1)     #range() is exclusive; range(x,y) will yield a list of [x, x+1.....y-1]. we add 1 to the end to offset this
    count = 0
    for item in nums:
        count += 1
    return count

This works pretty well for just counting, but what about the 5 rule? Well, there are a number of ways to implement it. The method that immediately jumps out to me is by using the 'in' keyword, which can check if a certain element is in a certain other element. For example, saying:
Code: [Select]
if 'hello' in '7777helloaaaa':
    return True

will return true. The catch? It can't check if an integer is in another integer. Is all hope lost? Not at all. Using the str(x) function, we can cast an integer to a string. An example of this:

Code: [Select]
def check_if_in(number, check):
    if str(check) in str(number):
        return True
    return False
The above function, given two numbers, will check if one's in the other and return true if so.

The sample functions above should hopefully help you to find a solution. By combining them and reworking the logic a bit, you can get your desired output. There are different (and probably more efficient) ways to solve this kata: don't feel like you absolutely need to implement it this way if you don't want to!

I've put my solution below in transparent text, so you can check out how I did it if you want:

def dont_count_fives(start, end):
    nums = range(start, end+1)
    iter = 0
    for element in nums:
        if not '5' in str(element):
            iter += 1
    return iter


I just remembered that I made this thead about 366 Days ago
Happy Anniversary, thread!

am i the only person that abuses token's in python just to jar my way through any string/integer problems
topkek

huge bump i want this topic to be alive because it's part of my soul


question, what do you guys think about lua? i'm thinking about learning lua a lot more probably as much as python

huge bump i want this topic to be alive because it's part of my soul


question, what do you guys think about lua? i'm thinking about learning lua a lot more probably as much as python

It's interpreted faster than Python but it also has a smaller community so you might not get as much help from Google as you would with Python.
EDIT: If you like Gmod making addons for it is really easy. Having never used it I was able to make some after a quick crashcourse on its syntax.
« Last Edit: November 05, 2016, 09:56:43 PM by Steve5451² »

It's interpreted faster than Python
that's implementation-specific
CPython, python's reference implementation, is probably slower than the lua reference implementation, but Cython is probably faster than that. and on the double flipside, LuaJIT is probably faster than all three of those

compared to python, when it comes to lua, you will have to get used to a much smaller standard library. Python's standard library is just crazy. along with what steve said, that lua is much less popular
you will also have to get used to the lack of language-level classes, because lua has no such thing. you can emulate them with its tables though. also, indices start at 1, instead of 0, which is very unusual

Do you guys know any good / great tutorials for coding with C# for Unity? I'd also like the tutorial to be a video-based one because working solely off just a book will get boring for me quickly and I learn easier by watching

Do you guys know any good / great tutorials for coding with C# for Unity? I'd also like the tutorial to be a video-based one because working solely off just a book will get boring for me quickly and I learn easier by watching

If you don't know C# already then learn C# by itself first. If you go in only knowing how it works with Unity you're gonna write really sloppy code.

If you don't know C# already then learn C# by itself first. If you go in only knowing how it works with Unity you're gonna write really sloppy code.
Alright

Are there any good tutorials or guides on scripting it, along with video ones as well?

Alright

Are there any good tutorials or guides on scripting it, along with video ones as well?

This seems okay. I skimmed through it and he was explaining the data types and how they work rather than telling you what to write without an explanation of what's happening like many seem to do.

He's also use MonoDevelop, the IDE Unity uses.