online python to c converter

from collections import deque

def BFS(a, b, target):
	
	# Map is used to store the states, every
	# state is hashed to binary value to
	# indicate either that state is visited
	# before or not
	m = {}
	isSolvable = False
	path = []
	
	# Queue to maintain states
	q = deque()
	
	# Initialing with initial state
	q.append((0, 0))

	while (len(q) > 0):
		
		# Current state
		u = q.popleft()

		#q.pop() #pop off used state

		# If this state is already visited
		if ((u[0], u[1]) in m):
			continue

		# Doesn't met jug constraints
		if ((u[0] > a or u[1] > b or
			u[0] < 0 or u[1] < 0)):
			continue

		# Filling the vector for constructing
		# the solution path
		path.append([u[0], u[1]])

		# Marking current state as visited
		m[(u[0], u[1])] = 1

		# If we reach solution state, put ans=1
		if (u[0] == target or u[1] == target):
			isSolvable = True
			
			if (u[0] == target):
				if (u[1] != 0):
					
					# Fill final state
					path.append([u[0], 0])
			else:
				if (u[0] != 0):

					# Fill final state
					path.append([0, u[1]])

			# Print the solution path
			sz = len(path)
			for i in range(sz):
				print("(", path[i][0], ",",
						path[i][1], ")")
			break

		# If we have not reached final state
		# then, start developing intermediate
		# states to reach solution state
		q.append([u[0], b]) # Fill Jug2
		q.append([a, u[1]]) # Fill Jug1

		for ap in range(max(a, b) + 1):

			# Pour amount ap from Jug2 to Jug1
			c = u[0] + ap
			d = u[1] - ap

			# Check if this state is possible or not
			if (c == a or (d == 0 and d >= 0)):
				q.append([c, d])

			# Pour amount ap from Jug 1 to Jug2
			c = u[0] - ap
			d = u[1] + ap

			# Check if this state is possible or not
			if ((c == 0 and c >= 0) or d == b):
				q.append([c, d])
		
		# Empty Jug2
		q.append([a, 0])
		
		# Empty Jug1
		q.append([0, b])

	# No, solution exists if ans=0
	if (not isSolvable):
		print ("No solution")

# Driver code
if __name__ == '__main__':
	
	Jug1, Jug2, target = 4, 3, 2
	print("Path from initial state "
		"to solution state ::")
	
	BFS(Jug1, Jug2, target)

# This code is contributed by mohit kumar 29

3.8
5
Momo Johnson 125 points

                                        for i in range(gradient1b.shape[0]):
        for j in range(gradient1b.shape[1]):
            if gradient1b[i, j] &gt; thresholdHi:
                gradient2b[i, j] = 0
            elif ((gradient1b[i, j] &lt;= thresholdHi) and (gradient1b[i, j] &gt; thresholdLo)):
                #gradient2b[i, j] = gradient1b[i, j] #255  #Binary thresholding
                gradient2b[i, j] = 255  #Binary thresholding
            else:
                gradient2b[i, j] = 0

3.8 (5 Votes)
0
4.08
8
Chase07 55 points

                                    # A brute force approach based
# implementation to find if a number
# can be written as sum of two squares.
 
# function to check if there exist two
# numbers sum of whose squares is n.
def sumSquare( n) :
    i = 1
    while i * i &lt;= n :
        j = 1
        while(j * j &lt;= n) :
            if (i * i + j * j == n) :
                print(i, &quot;^2 + &quot;, j , &quot;^2&quot; )
                return True
            j = j + 1
        i = i + 1
         
    return False
  
# driver Program
n = 25
if (sumSquare(n)) :
    print(&quot;Yes&quot;)
else :
    print( &quot;No&quot;)
     

4.08 (26 Votes)
0
0
0
Xmoleslo 115 points

                                    n=int(input())
for i in range (n):
    a,b,k=(map(int,input().split()))
    if a&gt;=b:
        print(k//b)
    else:
        print(k//a)

0
0
0
0
Seb Hall 85 points

                                    if number == 2 : prime_con = True
        if number&gt;2 and number%2==0 : prime_con = False
                stopper = math.floor(math.sqrt(number))
                        for j in range(3,100,2):
                                    if number%j==0: 
                                                    prime_con = False
                                                                    break

0
0
0
0
Zaje 110 points

                                    def djikstra(graph, initial):
    visited_weight_map = {initial: 0}
    nodes = set(graph.nodes)

    # Haven't visited every node
    while nodes:
        next_node = min(
          node for node in nodes if node in visited 
        )

        if next_node is None:
            # If we've gone through them all
            break

        nodes.remove(next_node)
        current_weight = visited_weight_map[next_node]

        for edge in graph.edges[next_node]:
            # Go over every edge connected to the node
            weight = current_weight + graph.distances[(next_node, edge)]
            if edge not in visited_weight_map or weight &lt; visited_weight_map[edge]:
                visited_weight_map[edge] = weight

    return visited

0
0
0
0
UltraBird 90 points

                                    lista[2:10] = [7]

0
0
4.1
10
Eric Thomsen 100 points

                                    a=[]
def knapsack(pro,wt,c,n,ans):
	global a
	if n==0 or c==0:
		a+=ans,
	elif wt[n-1]&gt;c:
		knapsack(pro,wt,c,n-1,ans)
	else:
		knapsack(pro,wt,c-wt[n-1],n-1,ans+pro[n-1])
		knapsack(pro,wt,c,n-1,ans)

n=int(input())
profit=list(map(int,input().split()))
weights=list(map(int,input().split()))
capacity=int(input())

knapsack(profit,weights,capacity,n,0)
a.sort(reverse=True)
print(a[1 if a[0]&lt;=10 and a[0]%3 else 0])

4.1 (10 Votes)
0
3
1
Caitlin 95 points

                                    def djikstra(graph, initial):
    visited_weight_map = {initial: 0}
    nodes = set(graph.nodes)

    # Haven't visited every node
    while nodes:
        next_node = min(
          node for node in nodes if node in visited 
        )

        if next_node is None:
            # If we've gone through them all
            break

        nodes.remove(next_node)
        current_weight = visited_weight_map[next_node]

        for edge in graph.edges[next_node]:
            # Go over every edge connected to the node
            weight = current_weight + graph.distances[(next_node, edge)]
            if edge not in visited_weight_map or weight &lt; visited_weight_map[edge]:
                visited_weight_map[edge] = weight

    return visited

3 (1 Votes)
0
4
7
Tomash 110 points

                                    Yawning Yacare

4 (7 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source