Weird Function Using python

0 votes

Weird Function

DescriptionIn data science, quite often you need to implement research papers and write code according to what's present in those papers. Research papers have a lot of maths involved and you need to implement the maths in code. In this exercise, you're required to implement some maths in code. The problem is as follows:

For fixed integers a, b, c, define a weird function F(n) as follows: 
F(n) = n - c for all n > b 
F(n) = F(a + F(a + F(a + F(a + n)))) for all n ≤ b. 

Also, define S(a, b, c) = ∑F(n) where n takes the values 0 till b [in other words, S(a, b, c) = F(0) + F(1) + F(2) + .... F(b-1) + F(b)].

The input will be the value of a, b and c. The output should be S(a, b, c). You can define the functions in your own customized way with no restrictions on the number of parameters. For example, you can define the function S which can take additional parameters than a, b and c. Just make sure the code behaves as per the maths.

For example, if a = 20, b = 100 and c = 15, then F(0) = 195 and F(2000) = 1985. 
Therefore, S(20, 100, 15) = 14245

Input:
3 values separated by a comma
a,b,c

Output:
S(a,b,c)

Sample input:
20, 100, 15

Sample output:
14245

Jun 22, 2020 in Python by rocking
• 160 points
4,406 views

Hi, @Rocking,

 Do you write a full code regarding your query?

1 answer to this question.

0 votes
input_str = input()
input_list = input_str.split(',')

a = int(input_list[0])
b = int(input_list[1])
c = int(input_list[2])

# write code here

sum = 0

def weird_function(a,b,c,n):
    #base case
    if n>b:
        return n-c
    #action and recursive calls
    #here more than one recurssive calls will be needed
    else:
        add=weird_function(a,b,c,a+n)
        add1=weird_function(a,b,c,a+add)
        add2=weird_function(a,b,c,a+add1)
        return weird_function(a,b,c,a+add2)

def large_sum(a, b, c):
    large_sum = 0
    for value in range(b+1):
        large_sum += weird_function(a, b, c, value)
    return large_sum

result = large_sum(a, b, c)

print(result)
answered Jul 28, 2020 by Vin

Related Questions In Python

0 votes
1 answer

Using generator function in Python

A generator is effectively a function that ...READ MORE

answered Oct 29, 2018 in Python by Priyaj
• 58,020 points
567 views
0 votes
4 answers

How to print objects of class using print function in Python?

>>> class Test: ... ...READ MORE

answered Dec 16, 2020 in Python by Roshni
• 10,480 points
78,623 views
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is demo.py and ...READ MORE

answered Jun 26, 2019 in Python by Neel
• 3,020 points
1,077 views
+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points
4,968 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
13,609 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,486 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,150 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP