Calculator using variable names

I’ve recently been assigned an assignment to create a word calculator, and given my knowledge in python is still quite lacking, I want to ask if anybody has any better ideas for any possible solutions. The question is here: Jimmy has invented a new kind of calculator that works with words rather than numbers. Input … Read more

Reversing a number

I was working through a programming challenge I found on Reddit and it seemed easy enough: Find all numbers less than \$10^n\$ where the number and its reverse (the reverse of \$123\$ is \$321\$) are both divisible by \$7\$ and then sum them all together. def challenge_229(power): numbers = [] for x in range(0, 10**power, … Read more

HackerRank Implement Queue using two stacks Solution

Challenge Problem Statement – Implement a Queue using two Stacks I implemented dequeue() in O(1) at the cost of enqueue() in O(n) #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <stack> using namespace std; struct Queue{ stack<int> s1,s2; int dequeue(){ int x = s1.top(); s1.pop(); return x; } void peek(){ cout<< s1.top()<<“\n”; … Read more

Finding area and perimeter of rectangles and circles that are instance of interface region

The missing code in task 1 were the methodsarea(), perimeter() and toString(). In task 2 I know that using built in collection such as Arraylist would be efficient and simpler,So any new different idea and implementation are appreciated. Make the classes Circle and Rectangle complete: write the missing code. A static method selectRectangle accepts an … Read more

Parsing n lines to count vowels – HackerEarth

I have written a haskell program for the following ‘Code Monk’ Challenge at HackerEarth. Here is the challenge description. Basically, we are looking for the number of vowels in a string. The first input n is the number of string to parse, followed by n number of random strings. And here is my implementation: import … Read more

Find next bigger number with same combination of digits

Please review my code for a puzzle to find next bigger number with same combination of digits. so if the number is 156432 the next bigger number is 162345 I wrote a program which is as follows, // converts a number // to an number array // i.e. 13452 = [1,3,4,5,2] var convertToNumArray = function(num){ … Read more

KQuery SPOJ problem, using merge sort segment tree

Problem : KQUERY Summary: For each query consisting of \$(i, j, k)\$, return the number of elements greater than \$k\$ in the subsequence \$a_i, a_{i+1}, …, a_j\$. My code has complexity of \$O(n\log^2{n})\$. I am only interested in segment tree based solution of Kquery. Please let me know why am I getting TLE using merge … Read more

Create all combinations of length N from a given alphabet (2)

I implemented this challenge in Java before but performance was not the best so I decided to implement this in C++ to compare the two. The code works and performance is indeed much better than in the Java version. However I am unsure about the quality of this code. I am still not overly familiar … Read more

Project Euler Problem 12 in Python 3 (Find triangle number with 500 divisors)

I am doing Project Euler, and 12 is the one that takes significantly longer then everything else. Here is my code: # The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be # 1 + 2 + 3 + 4 + 5 + 6 + 7 … Read more