Archive
Python: Even Fibonacci Numbers
Python: Even Fibonacci Numbers
ProjectEuler Problem No.2
Easy fast task in ProjectEuler, The Task is to find the sum of the even-valued terms in Fibonacci sequence whose values do not exceed four million.
In this code we will add some print-statment to just show how mane even numbers there and the summation of it.
|
The Code:
# Even Fibonacci Numbers
# projectEuler Problem No. 2
def get_fibonacci_sequence():
n1 = 1
n2 = 1
fibo = 1
while fibo < 4000000:
fibo = n1+n2
n1 = n2
n2 = fibo
if fibo% 2 == 0:
even_fibo_num.append(fibo)
tot = 0
even_fibo_num = []
get_fibonacci_sequence()
print(‘\n We fond {} even fibonacci”s number less than 4000000.’.format(len(even_fibo_num)))
for each in even_fibo_num:
tot = tot + each
print(‘ The summation on those even Fibonacci”s is: ‘, tot)
|
Python: Perfect Number
Python: Non-abundant sums
Problem No.23 @ ProjectEuler
In projecteuler Problem No. 23 talking about Non-abundant sums to clear this it state three categories for a numbers.
1. A number N called Perfect Number if the sum of its divisors are equal to the number it self. So 28 is a perfect number because the divisors of 28 are 1,2,4,7,14 they equal to 28. ( 1 + 2 + 4 + 7 + 1 4 = 28)
2. A number N is called Deficient if the sum of its proper divisors is less than the number it self N.
3. And a number N is called Abundant if this sum of its proper divisors is exceeds N (number it self)
Enhancement: So instead of solving problem No.23, we will write a code to determent the group that a number belongs to. As we trying to make a general cods, we will ask the user to enter a number then we will call the function to collect all the divisors of N and get its sum and gives it a name according to the classification we just talk about.
The Code:
# Python: Non-abundant sums
# Problem No.23 @ ProjectEuler
# We solve it in my way
num_divisors=[]
def get_num_group (num):
for x in range(1,num):
if num%x == 0:
num_divisors.append(x)
num =int(input(‘Enter a number: ‘))
div_sum =0
get_num_group(num)
for each in num_divisors:
div_sum = div_sum + each
print(‘\n Divisors of {} are,’.format(num),num_divisors)
print(‘ The sum of the Divisors is ‘,div_sum)
if div_sum == num :
print (‘ The number {} is Perfect Number’.format(num))
elif div_sum < num :
print (‘ The number {} is Deficient ‘.format(num))
else:
print (‘ The number {} is Abundant ‘.format(num))
Python: Square Digit Chain
Python: Square Digit Chain
ProjectEuler Problem No.92
Here we have a mathematical definition called Happy Number..
A Happy Number is defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits in base-ten, and repeat the process until the number either:
equals 1 (where it will stay), or
it loops endlessly in a cycle that does not include 1.
(Wikipedia).
In ProjectEuler the task stated in this problem as ” How many starting numbers below ten million will arrive at 89?”
Enhancement: Here we will do something else, we will try to solve the task and post the answer to the projecteuler portal, BUT we are not talking about this here, we will use the concept of this task to generate chains of looped number and I will use it later in another post (project) and trying to represent this chains in a graphic way.
So to do this we need two functions, First one will read a number, get its digits, squaring each digit and get the summation. To keep our eyes on the numbers we need to store it, so we will use list called the_chain.
To check if we have reach a closed chain then we need to ask if the new number (sum of square digit) exists in the chain list or not. If exists we finish and will return the chain for more manipulating.
I will solve this on my way .. 🙂
In this code we will do the following:
1. We will ask the user to enter a number.
2. We will run the function on that number.
3. Outputs:
If we ends with 1 then we have a Happy Number.
If we have closed chain (current number exists in the chain) then we will have tow cases:
If the current number is the same as the start number, then we will call this “Perfect Chain“. Otherwise we will call it “Tail Chain”
The Code:
# Square digit chain.
# Pprojecteuler problem No 92
num = 1
the_chain=[]
def get_square_digit_chain(n):
tot=0
the_chain.append(n)
while n != 0:
tot=0
for each in str(n):
tot= tot + int(each)**2
n = tot
if n in the_chain:
return n
else:
the_chain.append(n)
#We ask the user to enter a number.
num =int(input(“Enter a number “))
chain_closed = get_square_digit_chain(num)
if chain_closed == 1:
print(“We have a Happy Number”)
print(the_chain,’This is Open Chain’)
else:
if chain_closed == num:
print(“We have a Perfect Chain”)
print(the_chain,’Closed on’,chain_closed)
else:
print(“We have a Tail Chain”)
print(the_chain,’Closed on’,chain_closed)
|
Python : Triangle Number
Python: Triangle Number
Projecteuler problem No.42
With Problem 42, we have to read a file containing nearly two-thousand common English words and find how many are triangle words?
Difinetion: Triangle Words: If we give each alphabetical in English language a value related to its corresponding location such as A=1, B=2, C=3 and so on, then we convert the word to a value based on a sum of its characters values, we can said that a word is a triangular if its value equal to sequence in a Triangular Number formula.
Triangular Number formula:
Tn =(n/2)*(n+1)Example.. If we have a word “SKY”, We will find that:
The Value of S=19
The Value of K= 11
The value of Y= 25The Total is (19+11+25) = 55
(55) is a number in the Triangular Number Sequence n=10
T10=(10/2)*(10+1)
=5*11
=55
Notes In this task, I will not write a code to read the text-file, but i will copy-paste it in a variable called “The_words”.
The words:
The_words=(“A”,”ABILITY”,”ABLE”,”ABOUT”,”ABOVE”,”ABSENCE”,”ABSOLUTELY”,”ACADEMIC”,”ACCEPT”,”ACCESS”, “ACCIDENT”,”ACCOMPANY”,”ACCORDING”,”ACCOUNT”,”ACHIEVE”,”ACHIEVEMENT”,”ACID”,”ACQUIRE”, “ACROSS”,”ACT”,”ACTION”,”ACTIVE”,”ACTIVITY”,”ACTUAL”,”ACTUALLY”,”ADD”,”ADDITION”,”ADDITIONAL”,”ADDRESS”,”ADMINISTRATION”,”ADMIT”,”ADOPT”,”ADULT”,”ADVANCE”,”ADVANTAGE”,”ADVICE”,”ADVISE”,”AFFAIR”, “AFFECT”,”AFFORD”,”AFRAID”,”AFTER”,”AFTERNOON”,”AFTERWARDS”,”AGAIN”,”AGAINST”,”AGE”,”AGENCY”,”AGENT”,”AGO”,”AGREE”,”AGREEMENT”,”AHEAD”,”AID”,”AIM”,”AIR”,”AIRCRAFT”,”ALL”,”ALLOW”,”ALMOST”, “ALONE”,”ALONG”,”ALREADY”,”ALRIGHT”,”ALSO”,”ALTERNATIVE”,”ALTHOUGH”,”ALWAYS”,”AMONG”,”AMONGST”, “AMOUNT”,”AN”,”ANALYSIS”,”ANCIENT”,”AND”,”ANIMAL”,”ANNOUNCE”,”ANNUAL”,”ANOTHER”,”ANSWER”,”ANY”, “ANYBODY”,”ANYONE”,”ANYTHING”,”ANYWAY”,”APART”,”APPARENT”,”APPARENTLY”,”APPEAL”,”APPEAR”,”APPEARANCE”,”APPLICATION”,”APPLY”,”APPOINT”,”APPOINTMENT”,”APPROACH”,”APPROPRIATE”,”APPROVE”,”AREA”,”ARGUE”, “ARGUMENT”,”ARISE”,”ARM”,”ARMY”,”AROUND”,”ARRANGE”,”ARRANGEMENT”,”ARRIVE”,”ART”,”ARTICLE”, “ARTIST”,”AS”,”ASK”,”ASPECT”,”ASSEMBLY”,”ASSESS”,”ASSESSMENT”,”ASSET”,”ASSOCIATE”,”ASSOCIATION”,”ASSUME”,”ASSUMPTION”,”AT”,”ATMOSPHERE”,”ATTACH”,”ATTACK”,”ATTEMPT”,”ATTEND”,”ATTENTION”,”ATTITUDE”, “ATTRACT”,”ATTRACTIVE”,”AUDIENCE”,”AUTHOR”,”AUTHORITY”,”AVAILABLE”,”AVERAGE”,”AVOID”,”AWARD”, “AWARE”,”AWAY”,”AYE”,”BABY”,”BACK”,”BACKGROUND”,”BAD”,”BAG”,”BALANCE”,”BALL”,”BAND”,”BANK”, “BAR”,”BASE”,”BASIC”,”BASIS”,”BATTLE”,”BE”,”BEAR”,”BEAT”,”BEAUTIFUL”,”BECAUSE”,”BECOME”,”BED”,”BEDROOM”,”BEFORE”,”BEGIN”,”BEGINNING”,”BEHAVIOUR”,”BEHIND”,”BELIEF”,”BELIEVE”,”BELONG”,”BELOW”, “BENEATH”,”BENEFIT”,”BESIDE”,”BEST”,”BETTER”,”BETWEEN”,”BEYOND”,”BIG”,”BILL”,”BIND”,”BIRD”, “BIRTH”,”BIT”,”BLACK”,”BLOCK”,”BLOOD”,”BLOODY”,”BLOW”,”BLUE”,”BOARD”,”BOAT”,”BODY”,”BONE”, “BOOK”,”BORDER”,”BOTH”,”BOTTLE”,”BOTTOM”,”BOX”,”BOY”,”BRAIN”,”BRANCH”,”BREAK”,”BREATH”,”BRIDGE”,”BRIEF”,”BRIGHT”,”BRING”,”BROAD”,”BROTHER”,”BUDGET”,”BUILD”,”BUILDING”,”BURN”,”BUS”,”BUSINESS”, “BUSY”,”BUT”,”BUY”,”BY”,”CABINET”,”CALL”,”CAMPAIGN”,”CAN”,”CANDIDATE”,”CAPABLE”,”CAPACITY”,”CAPITAL”,”CAR”,”CARD”,”CARE”,”CAREER”,”CAREFUL”,”CAREFULLY”,”CARRY”,”CASE”,”CASH”,”CAT”,”CATCH”, “CATEGORY”,”CAUSE”,”CELL”,”CENTRAL”,”CENTRE”,”CENTURY”,”CERTAIN”,”CERTAINLY”,”CHAIN”,”CHAIR”,”CHAIRMAN”,”CHALLENGE”,”CHANCE”,”CHANGE”,”CHANNEL”,”CHAPTER”,”CHARACTER”,”CHARACTERISTIC”,”CHARGE”, “CHEAP”,”CHECK”,”CHEMICAL”,”CHIEF”,”CHILD”,”CHOICE”,”CHOOSE”,”CHURCH”,”CIRCLE”,”CIRCUMSTANCE”,”CITIZEN”,”CITY”,”CIVIL”,”CLAIM”,”CLASS”,”CLEAN”,”CLEAR”,”CLEARLY”,”CLIENT”,”CLIMB”,”CLOSE”, “CLOSELY”,”CLOTHES”,”CLUB”,”COAL”,”CODE”,”COFFEE”,”COLD”,”COLLEAGUE”,”COLLECT”,”COLLECTION”,”COLLEGE”,”COLOUR”,”COMBINATION”,”COMBINE”,”COME”,”COMMENT”,”COMMERCIAL”,”COMMISSION”,”COMMIT”, “COMMITMENT”,”COMMITTEE”,”COMMON”,”COMMUNICATION”,”COMMUNITY”,”COMPANY”,”COMPARE”,”COMPARISON”, “COMPETITION”,”COMPLETE”,”COMPLETELY”,”COMPLEX”,”COMPONENT”,”COMPUTER”,”CONCENTRATE”,”CONCENTRATION”,”CONCEPT”,”CONCERN”,”CONCERNED”,”CONCLUDE”,”CONCLUSION”,”CONDITION”,”CONDUCT”,”CONFERENCE”,”CONFIDENCE”,”CONFIRM”,”CONFLICT”,”CONGRESS”,”CONNECT”,”CONNECTION”,”CONSEQUENCE”,”CONSERVATIVE”,”CONSIDER”, “CONSIDERABLE”,”CONSIDERATION”,”CONSIST”,”CONSTANT”,”CONSTRUCTION”,”CONSUMER”,”CONTACT”,”CONTAIN”,”CONTENT”,”CONTEXT”,”CONTINUE”,”CONTRACT”,”CONTRAST”,”CONTRIBUTE”,”CONTRIBUTION”,”CONTROL”, “CONVENTION”,”CONVERSATION”,”COPY”,”CORNER”,”CORPORATE”,”CORRECT”,”COS”,”COST”,”COULD”,”COUNCIL”,”COUNT”,”COUNTRY”,”COUNTY”,”COUPLE”,”COURSE”,”COURT”,”COVER”,”CREATE”,”CREATION”,”CREDIT”, “CRIME”,”CRIMINAL”,”CRISIS”,”CRITERION”,”CRITICAL”,”CRITICISM”,”CROSS”,”CROWD”,”CRY”,”CULTURAL”, “CULTURE”,”CUP”,”CURRENT”,”CURRENTLY”,”CURRICULUM”,”CUSTOMER”,”CUT”,”DAMAGE”,”DANGER”,”DANGEROUS”, “DARK”,”DATA”,”DATE”,”DAUGHTER”,”DAY”,”DEAD”,”DEAL”,”DEATH”,”DEBATE”,”DEBT”,”DECADE”,”DECIDE”, “DECISION”,”DECLARE”,”DEEP”,”DEFENCE”,”DEFENDANT”,”DEFINE”,”DEFINITION”,”DEGREE”,”DELIVER”,”DEMAND”, “DEMOCRATIC”,”DEMONSTRATE”,”DENY”,”DEPARTMENT”,”DEPEND”,”DEPUTY”,”DERIVE”,”DESCRIBE”,”DESCRIPTION”, “DESIGN”,”DESIRE”,”DESK”,”DESPITE”,”DESTROY”,”DETAIL”,”DETAILED”,”DETERMINE”,”DEVELOP”,”DEVELOPMENT”, “DEVICE”,”DIE”,”DIFFERENCE”,”DIFFERENT”,”DIFFICULT”,”DIFFICULTY”,”DINNER”,”DIRECT”,”DIRECTION”, “DIRECTLY”,”DIRECTOR”,”DISAPPEAR”,”DISCIPLINE”,”DISCOVER”,”DISCUSS”,”DISCUSSION”,”DISEASE”, “DISPLAY”,”DISTANCE”,”DISTINCTION”,”DISTRIBUTION”,”DISTRICT”,”DIVIDE”,”DIVISION”,”DO”,”DOCTOR”, “DOCUMENT”,”DOG”,”DOMESTIC”,”DOOR”,”DOUBLE”,”DOUBT”,”DOWN”,”DRAW”,”DRAWING”,”DREAM”,”DRESS”,”DRINK”, “DRIVE”,”DRIVER”,”DROP”,”DRUG”,”DRY”,”DUE”,”DURING”,”DUTY”,”EACH”,”EAR”,”EARLY”,”EARN”,”EARTH”, “EASILY”,”EAST”,”EASY”,”EAT”,”ECONOMIC”,”ECONOMY”,”EDGE”,”EDITOR”,”EDUCATION”,”EDUCATIONAL”,”EFFECT”, “EFFECTIVE”,”EFFECTIVELY”,”EFFORT”,”EGG”,”EITHER”,”ELDERLY”,”ELECTION”,”ELEMENT”,”ELSE”,”ELSEWHERE”, “EMERGE”,”EMPHASIS”,”EMPLOY”,”EMPLOYEE”,”EMPLOYER”,”EMPLOYMENT”,”EMPTY”,”ENABLE”,”ENCOURAGE”,”END”, “ENEMY”,”ENERGY”,”ENGINE”,”ENGINEERING”,”ENJOY”,”ENOUGH”,”ENSURE”,”ENTER”,”ENTERPRISE”,”ENTIRE”, “ENTIRELY”,”ENTITLE”,”ENTRY”,”ENVIRONMENT”,”ENVIRONMENTAL”,”EQUAL”,”EQUALLY”,”EQUIPMENT”,”ERROR”, “ESCAPE”,”ESPECIALLY”,”ESSENTIAL”,”ESTABLISH”,”ESTABLISHMENT”,”ESTATE”,”ESTIMATE”,”EVEN”,”EVENING”, “EVENT”,”EVENTUALLY”,”EVER”,”EVERY”,”EVERYBODY”,”EVERYONE”,”EVERYTHING”,”EVIDENCE”,”EXACTLY”, “EXAMINATION”,”EXAMINE”,”EXAMPLE”,”EXCELLENT”,”EXCEPT”,”EXCHANGE”,”EXECUTIVE”,”EXERCISE”,”EXHIBITION”, “EXIST”,”EXISTENCE”,”EXISTING”,”EXPECT”,”EXPECTATION”,”EXPENDITURE”,”EXPENSE”,”EXPENSIVE”, “EXPERIENCE”,”EXPERIMENT”,”EXPERT”,”EXPLAIN”,”EXPLANATION”,”EXPLORE”,”EXPRESS”,”EXPRESSION”, “EXTEND”,”EXTENT”,”EXTERNAL”,”EXTRA”,”EXTREMELY”,”EYE”,”FACE”,”FACILITY”,”FACT”,”FACTOR”, “FACTORY”,”FAIL”,”FAILURE”,”FAIR”,”FAIRLY”,”FAITH”,”FALL”,”FAMILIAR”,”FAMILY”,”FAMOUS”,”FAR”, “FARM”,”FARMER”,”FASHION”,”FAST”,”FATHER”,”FAVOUR”,”FEAR”,”FEATURE”,”FEE”,”FEEL”,”FEELING”, “FEMALE”,”FEW”,”FIELD”,”FIGHT”,”FIGURE”,”FILE”,”FILL”,”FILM”,”FINAL”,”FINALLY”,”FINANCE”,”FINANCIAL”, “FIND”,”FINDING”,”FINE”,”FINGER”,”FINISH”,”FIRE”,”FIRM”,”FIRST”,”FISH”,”FIT”,”FIX”,”FLAT”, “FLIGHT”,”FLOOR”,”FLOW”,”FLOWER”,”FLY”,”FOCUS”,”FOLLOW”,”FOLLOWING”,”FOOD”,”FOOT”,”FOOTBALL”, “FOR”,”FORCE”,”FOREIGN”,”FOREST”,”FORGET”,”FORM”,”FORMAL”,”FORMER”,”FORWARD”,”FOUNDATION”,”FREE”, “FREEDOM”,”FREQUENTLY”,”FRESH”,”FRIEND”,”FROM”,”FRONT”,”FRUIT”,”FUEL”,”FULL”,”FULLY”,”FUNCTION”,”FUND”,”FUNNY”,”FURTHER”,”FUTURE”,”GAIN”,”GAME”,”GARDEN”,”GAS”,”GATE”,”GATHER”,”GENERAL”,”GENERALLY”,”GENERATE”,”GENERATION”,”GENTLEMAN”,”GET”,”GIRL”,”GIVE”,”GLASS”,”GO”,”GOAL”,”GOD”,”GOLD”,”GOOD”,”GOVERNMENT”,”GRANT”,”GREAT”,”GREEN”,”GREY”,”GROUND”,”GROUP”,”GROW”,”GROWING”,”GROWTH”,”GUEST”,”GUIDE”,”GUN”,”HAIR”,”HALF”,”HALL”,”HAND”,”HANDLE”,”HANG”,”HAPPEN”,”HAPPY”,”HARD”,”HARDLY”,”HATE”,”HAVE”,”HE”,”HEAD”,”HEALTH”,”HEAR”,”HEART”,”HEAT”,”HEAVY”,”HELL”,”HELP”,”HENCE”,”HER”,”HERE”,”HERSELF”,”HIDE”,”HIGH”,”HIGHLY”,”HILL”,”HIM”,”HIMSELF”,”HIS”,”HISTORICAL”,”HISTORY”,”HIT”,”HOLD”,”HOLE”,”HOLIDAY”,”HOME”,”HOPE”,”HORSE”,”HOSPITAL”,”HOT”,”HOTEL”,”HOUR”,”HOUSE”,”HOUSEHOLD”,”HOUSING”,”HOW”,”HOWEVER”,”HUGE”,”HUMAN”,”HURT”,”HUSBAND”,”I”,”IDEA”,”IDENTIFY”,”IF”,”IGNORE”,”ILLUSTRATE”,”IMAGE”,”IMAGINE”,”IMMEDIATE”,”IMMEDIATELY”,”IMPACT”,”IMPLICATION”,”IMPLY”,”IMPORTANCE”,”IMPORTANT”,”IMPOSE”,”IMPOSSIBLE”,”IMPRESSION”,”IMPROVE”,”IMPROVEMENT”,”IN”,”INCIDENT”,”INCLUDE”,”INCLUDING”,”INCOME”,”INCREASE”,”INCREASED”,”INCREASINGLY”,”INDEED”,”INDEPENDENT”,”INDEX”,”INDICATE”,”INDIVIDUAL”,”INDUSTRIAL”,”INDUSTRY”,”INFLUENCE”,”INFORM”,”INFORMATION”,”INITIAL”,”INITIATIVE”,”INJURY”,”INSIDE”,”INSIST”,”INSTANCE”,”INSTEAD”,”INSTITUTE”,”INSTITUTION”,”INSTRUCTION”,”INSTRUMENT”,”INSURANCE”,”INTEND”,”INTENTION”,”INTEREST”,”INTERESTED”,”INTERESTING”,”INTERNAL”,”INTERNATIONAL”,”INTERPRETATION”,”INTERVIEW”,”INTO”,”INTRODUCE”,”INTRODUCTION”,”INVESTIGATE”,”INVESTIGATION”,”INVESTMENT”,”INVITE”,”INVOLVE”,”IRON”,”IS”,”ISLAND”,”ISSUE”,”IT”,”ITEM”,”ITS”,”ITSELF”,”JOB”,”JOIN”,”JOINT”,”JOURNEY”,”JUDGE”,”JUMP”,”JUST”,”JUSTICE”,”KEEP”,”KEY”,”KID”,”KILL”,”KIND”,”KING”,”KITCHEN”,”KNEE”,”KNOW”,”KNOWLEDGE”,”LABOUR”,”LACK”,”LADY”,”LAND”,”LANGUAGE”,”LARGE”,”LARGELY”,”LAST”,”LATE”,”LATER”,”LATTER”,”LAUGH”,”LAUNCH”,”LAW”,”LAWYER”,”LAY”,”LEAD”,”LEADER”,”LEADERSHIP”,”LEADING”,”LEAF”,”LEAGUE”,”LEAN”,”LEARN”,”LEAST”,”LEAVE”,”LEFT”,”LEG”,”LEGAL”,”LEGISLATION”,”LENGTH”,”LESS”,”LET”,”LETTER”,”LEVEL”,”LIABILITY”,”LIBERAL”,”LIBRARY”,”LIE”,”LIFE”,”LIFT”,”LIGHT”,”LIKE”,”LIKELY”,”LIMIT”,”LIMITED”,”LINE”,”LINK”,”LIP”,”LIST”,”LISTEN”,”LITERATURE”,”LITTLE”,”LIVE”,”LIVING”,”LOAN”,”LOCAL”,”LOCATION”,”LONG”,”LOOK”,”LORD”,”LOSE”,”LOSS”,”LOT”,”LOVE”,”LOVELY”,”LOW”,”LUNCH”,”MACHINE”,”MAGAZINE”,”MAIN”,”MAINLY”,”MAINTAIN”,”MAJOR”,”MAJORITY”,”MAKE”,”MALE”,”MAN”,”MANAGE”,”MANAGEMENT”,”MANAGER”,”MANNER”,”MANY”,”MAP”,”MARK”,”MARKET”,”MARRIAGE”,”MARRIED”,”MARRY”,”MASS”,”MASTER”,”MATCH”,”MATERIAL”,”MATTER”,”MAY”,”MAYBE”,”ME”,”MEAL”,”MEAN”,”MEANING”,”MEANS”,”MEANWHILE”,”MEASURE”,”MECHANISM”,”MEDIA”,”MEDICAL”,”MEET”,”MEETING”,”MEMBER”,”MEMBERSHIP”,”MEMORY”,”MENTAL”,”MENTION”,”MERELY”,”MESSAGE”,”METAL”,”METHOD”,”MIDDLE”,”MIGHT”,”MILE”,”MILITARY”,”MILK”,”MIND”,”MINE”,”MINISTER”,”MINISTRY”,”MINUTE”,”MISS”,”MISTAKE”,”MODEL”,”MODERN”,”MODULE”,”MOMENT”,”MONEY”,”MONTH”,”MORE”,”MORNING”,”MOST”,”MOTHER”,”MOTION”,”MOTOR”,”MOUNTAIN”,”MOUTH”,”MOVE”,”MOVEMENT”,”MUCH”,”MURDER”,”MUSEUM”,”MUSIC”,”MUST”,”MY”,”MYSELF”,”NAME”,”NARROW”,”NATION”,”NATIONAL”,”NATURAL”,”NATURE”,”NEAR”,”NEARLY”,”NECESSARILY”,”NECESSARY”,”NECK”,”NEED”,”NEGOTIATION”,”NEIGHBOUR”,”NEITHER”,”NETWORK”,”NEVER”,”NEVERTHELESS”,”NEW”,”NEWS”,”NEWSPAPER”,”NEXT”,”NICE”,”NIGHT”,”NO”,”NOBODY”,”NOD”,”NOISE”,”NONE”,”NOR”,”NORMAL”,”NORMALLY”,”NORTH”,”NORTHERN”,”NOSE”,”NOT”,”NOTE”,”NOTHING”,”NOTICE”,”NOTION”,”NOW”,”NUCLEAR”,”NUMBER”,”NURSE”,”OBJECT”,”OBJECTIVE”,”OBSERVATION”,”OBSERVE”,”OBTAIN”,”OBVIOUS”,”OBVIOUSLY”,”OCCASION”,”OCCUR”,”ODD”,”OF”,”OFF”,”OFFENCE”,”OFFER”,”OFFICE”,”OFFICER”,”OFFICIAL”,”OFTEN”,”OIL”,”OKAY”,”OLD”,”ON”,”ONCE”,”ONE”,”ONLY”,”ONTO”,”OPEN”,”OPERATE”,”OPERATION”,”OPINION”,”OPPORTUNITY”,”OPPOSITION”,”OPTION”,”OR”,”ORDER”,”ORDINARY”,”ORGANISATION”,”ORGANISE”,”ORGANIZATION”,”ORIGIN”,”ORIGINAL”,”OTHER”,”OTHERWISE”,”OUGHT”,”OUR”,”OURSELVES”,”OUT”,”OUTCOME”,”OUTPUT”,”OUTSIDE”,”OVER”,”OVERALL”,”OWN”,”OWNER”,”PACKAGE”,”PAGE”,”PAIN”,”PAINT”,”PAINTING”,”PAIR”,”PANEL”,”PAPER”,”PARENT”,”PARK”,”PARLIAMENT”,”PART”,”PARTICULAR”,”PARTICULARLY”,”PARTLY”,”PARTNER”,”PARTY”,”PASS”,”PASSAGE”,”PAST”,”PATH”,”PATIENT”,”PATTERN”,”PAY”,”PAYMENT”,”PEACE”,”PENSION”,”PEOPLE”,”PER”,”PERCENT”,”PERFECT”,”PERFORM”,”PERFORMANCE”,”PERHAPS”,”PERIOD”,”PERMANENT”,”PERSON”,”PERSONAL”,”PERSUADE”,”PHASE”,”PHONE”,”PHOTOGRAPH”,”PHYSICAL”,”PICK”,”PICTURE”,”PIECE”,”PLACE”,”PLAN”,”PLANNING”,”PLANT”,”PLASTIC”,”PLATE”,”PLAY”,”PLAYER”,”PLEASE”,”PLEASURE”,”PLENTY”,”PLUS”,”POCKET”,”POINT”,”POLICE”,”POLICY”,”POLITICAL”,”POLITICS”,”POOL”,”POOR”,”POPULAR”,”POPULATION”,”POSITION”,”POSITIVE”,”POSSIBILITY”,”POSSIBLE”,”POSSIBLY”,”POST”,”POTENTIAL”,”POUND”,”POWER”,”POWERFUL”,”PRACTICAL”,”PRACTICE”,”PREFER”,”PREPARE”,”PRESENCE”,”PRESENT”,”PRESIDENT”,”PRESS”,”PRESSURE”,”PRETTY”,”PREVENT”,”PREVIOUS”,”PREVIOUSLY”,”PRICE”,”PRIMARY”,”PRIME”,”PRINCIPLE”,”PRIORITY”,”PRISON”,”PRISONER”,”PRIVATE”,”PROBABLY”,”PROBLEM”,”PROCEDURE”,”PROCESS”,”PRODUCE”,”PRODUCT”,”PRODUCTION”,”PROFESSIONAL”,”PROFIT”,”PROGRAM”,”PROGRAMME”,”PROGRESS”,”PROJECT”,”PROMISE”,”PROMOTE”,”PROPER”,”PROPERLY”,”PROPERTY”,”PROPORTION”,”PROPOSE”,”PROPOSAL”,”PROSPECT”,”PROTECT”,”PROTECTION”,”PROVE”,”PROVIDE”,”PROVIDED”,”PROVISION”,”PUB”,”PUBLIC”,”PUBLICATION”,”PUBLISH”,”PULL”,”PUPIL”,”PURPOSE”,”PUSH”,”PUT”,”QUALITY”,”QUARTER”,”QUESTION”,”QUICK”,”QUICKLY”,”QUIET”,”QUITE”,”RACE”,”RADIO”,”RAILWAY”,”RAIN”,”RAISE”,”RANGE”,”RAPIDLY”,”RARE”,”RATE”,”RATHER”,”REACH”,”REACTION”,”READ”,”READER”,”READING”,”READY”,”REAL”,”REALISE”,”REALITY”,”REALIZE”,”REALLY”,”REASON”,”REASONABLE”,”RECALL”,”RECEIVE”,”RECENT”,”RECENTLY”,”RECOGNISE”,”RECOGNITION”,”RECOGNIZE”,”RECOMMEND”,”RECORD”,”RECOVER”,”RED”,”REDUCE”,”REDUCTION”,”REFER”,”REFERENCE”,”REFLECT”,”REFORM”,”REFUSE”,”REGARD”,”REGION”,”REGIONAL”,”REGULAR”,”REGULATION”,”REJECT”,”RELATE”,”RELATION”,”RELATIONSHIP”,”RELATIVE”,”RELATIVELY”,”RELEASE”,”RELEVANT”,”RELIEF”,”RELIGION”,”RELIGIOUS”,”RELY”,”REMAIN”,”REMEMBER”,”REMIND”,”REMOVE”,”REPEAT”,”REPLACE”,”REPLY”,”REPORT”,”REPRESENT”,”REPRESENTATION”,”REPRESENTATIVE”,”REQUEST”,”REQUIRE”,”REQUIREMENT”,”RESEARCH”,”RESOURCE”,”RESPECT”,”RESPOND”,”RESPONSE”,”RESPONSIBILITY”,”RESPONSIBLE”,”REST”,”RESTAURANT”,”RESULT”,”RETAIN”,”RETURN”,”REVEAL”,”REVENUE”,”REVIEW”,”REVOLUTION”,”RICH”,”RIDE”,”RIGHT”,”RING”,”RISE”,”RISK”,”RIVER”,”ROAD”,”ROCK”,”ROLE”,”ROLL”,”ROOF”,”ROOM”,”ROUND”,”ROUTE”,”ROW”,”ROYAL”,”RULE”,”RUN”,”RURAL”,”SAFE”,”SAFETY”,”SALE”,”SAME”,”SAMPLE”,”SATISFY”,”SAVE”,”SAY”,”SCALE”,”SCENE”,”SCHEME”,”SCHOOL”,”SCIENCE”,”SCIENTIFIC”,”SCIENTIST”,”SCORE”,”SCREEN”,”SEA”,”SEARCH”,”SEASON”,”SEAT”,”SECOND”,”SECONDARY”,”SECRETARY”,”SECTION”,”SECTOR”,”SECURE”,”SECURITY”,”SEE”,”SEEK”,”SEEM”,”SELECT”,”SELECTION”,”SELL”,”SEND”,”SENIOR”,”SENSE”,”SENTENCE”,”SEPARATE”,”SEQUENCE”,”SERIES”,”SERIOUS”,”SERIOUSLY”,”SERVANT”,”SERVE”,”SERVICE”,”SESSION”,”SET”,”SETTLE”,”SETTLEMENT”,”SEVERAL”,”SEVERE”,”SEX”,”SEXUAL”,”SHAKE”,”SHALL”,”SHAPE”,”SHARE”,”SHE”,”SHEET”,”SHIP”,”SHOE”,”SHOOT”,”SHOP”,”SHORT”,”SHOT”,”SHOULD”,”SHOULDER”,”SHOUT”,”SHOW”,”SHUT”,”SIDE”,”SIGHT”,”SIGN”,”SIGNAL”,”SIGNIFICANCE”,”SIGNIFICANT”,”SILENCE”,”SIMILAR”,”SIMPLE”,”SIMPLY”,”SINCE”,”SING”,”SINGLE”,”SIR”,”SISTER”,”SIT”,”SITE”,”SITUATION”,”SIZE”,”SKILL”,”SKIN”,”SKY”,”SLEEP”,”SLIGHTLY”,”SLIP”,”SLOW”,”SLOWLY”,”SMALL”,”SMILE”,”SO”,”SOCIAL”,”SOCIETY”,”SOFT”,”SOFTWARE”,”SOIL”,”SOLDIER”,”SOLICITOR”,”SOLUTION”,”SOME”,”SOMEBODY”,”SOMEONE”,”SOMETHING”,”SOMETIMES”,”SOMEWHAT”,”SOMEWHERE”,”SON”,”SONG”,”SOON”,”SORRY”,”SORT”,”SOUND”,”SOURCE”,”SOUTH”,”SOUTHERN”,”SPACE”,”SPEAK”,”SPEAKER”,”SPECIAL”,”SPECIES”,”SPECIFIC”,”SPEECH”,”SPEED”,”SPEND”,”SPIRIT”,”SPORT”,”SPOT”,”SPREAD”,”SPRING”,”STAFF”,”STAGE”,”STAND”,”STANDARD”,”STAR”,”START”,”STATE”,”STATEMENT”,”STATION”,”STATUS”,”STAY”,”STEAL”,”STEP”,”STICK”,”STILL”,”STOCK”,”STONE”,”STOP”,”STORE”,”STORY”,”STRAIGHT”,”STRANGE”,”STRATEGY”,”STREET”,”STRENGTH”,”STRIKE”,”STRONG”,”STRONGLY”,”STRUCTURE”,”STUDENT”,”STUDIO”,”STUDY”,”STUFF”,”STYLE”,”SUBJECT”,”SUBSTANTIAL”,”SUCCEED”,”SUCCESS”,”SUCCESSFUL”,”SUCH”,”SUDDENLY”,”SUFFER”,”SUFFICIENT”,”SUGGEST”,”SUGGESTION”,”SUITABLE”,”SUM”,”SUMMER”,”SUN”,”SUPPLY”,”SUPPORT”,”SUPPOSE”,”SURE”,”SURELY”,”SURFACE”,”SURPRISE”,”SURROUND”,”SURVEY”,”SURVIVE”,”SWITCH”,”SYSTEM”,”TABLE”,”TAKE”,”TALK”,”TALL”,”TAPE”,”TARGET”,”TASK”,”TAX”,”TEA”,”TEACH”,”TEACHER”,”TEACHING”,”TEAM”,”TEAR”,”TECHNICAL”,”TECHNIQUE”,”TECHNOLOGY”,”TELEPHONE”,”TELEVISION”,”TELL”,”TEMPERATURE”,”TEND”,”TERM”,”TERMS”,”TERRIBLE”,”TEST”,”TEXT”,”THAN”,”THANK”,”THANKS”,”THAT”,”THE”,”THEATRE”,”THEIR”,”THEM”,”THEME”,”THEMSELVES”,”THEN”,”THEORY”,”THERE”,”THEREFORE”,”THESE”,”THEY”,”THIN”,”THING”,”THINK”,”THIS”,”THOSE”,”THOUGH”,”THOUGHT”,”THREAT”,”THREATEN”,”THROUGH”,”THROUGHOUT”,”THROW”,”THUS”,”TICKET”,”TIME”,”TINY”,”TITLE”,”TO”,”TODAY”,”TOGETHER”,”TOMORROW”,”TONE”,”TONIGHT”,”TOO”,”TOOL”,”TOOTH”,”TOP”,”TOTAL”,”TOTALLY”,”TOUCH”,”TOUR”,”TOWARDS”,”TOWN”,”TRACK”,”TRADE”,”TRADITION”,”TRADITIONAL”,”TRAFFIC”,”TRAIN”,”TRAINING”,”TRANSFER”,”TRANSPORT”,”TRAVEL”,”TREAT”,”TREATMENT”,”TREATY”,”TREE”,”TREND”,”TRIAL”,”TRIP”,”TROOP”,”TROUBLE”,”TRUE”,”TRUST”,”TRUTH”,”TRY”,”TURN”,”TWICE”,”TYPE”,”TYPICAL”,”UNABLE”,”UNDER”,”UNDERSTAND”,”UNDERSTANDING”,”UNDERTAKE”,”UNEMPLOYMENT”,”UNFORTUNATELY”,”UNION”,”UNIT”,”UNITED”,”UNIVERSITY”,”UNLESS”,”UNLIKELY”,”UNTIL”,”UP”,”UPON”,”UPPER”,”URBAN”,”US”,”USE”,”USED”,”USEFUL”,”USER”,”USUAL”,”USUALLY”,”VALUE”,”VARIATION”,”VARIETY”,”VARIOUS”,”VARY”,”VAST”,”VEHICLE”,”VERSION”,”VERY”,”VIA”,”VICTIM”,”VICTORY”,”VIDEO”,”VIEW”,”VILLAGE”,”VIOLENCE”,”VISION”,”VISIT”,”VISITOR”,”VITAL”,”VOICE”,”VOLUME”,”VOTE”,”WAGE”,”WAIT”,”WALK”,”WALL”,”WANT”,”WAR”,”WARM”,”WARN”,”WASH”,”WATCH”,”WATER”,”WAVE”,”WAY”,”WE”,”WEAK”,”WEAPON”,”WEAR”,”WEATHER”,”WEEK”,”WEEKEND”,”WEIGHT”,”WELCOME”,”WELFARE”,”WELL”,”WEST”,”WESTERN”,”WHAT”,”WHATEVER”,”WHEN”,”WHERE”,”WHEREAS”,”WHETHER”,”WHICH”,”WHILE”,”WHILST”,”WHITE”,”WHO”,”WHOLE”,”WHOM”,”WHOSE”,”WHY”,”WIDE”,”WIDELY”,”WIFE”,”WILD”,”WILL”,”WIN”,”WIND”,”WINDOW”,”WINE”,”WING”,”WINNER”,”WINTER”,”WISH”,”WITH”,”WITHDRAW”,”WITHIN”,”WITHOUT”,”WOMAN”,”WONDER”,”WONDERFUL”,”WOOD”,”WORD”,”WORK”,”WORKER”,”WORKING”,”WORKS”,”WORLD”,”WORRY”,”WORTH”,”WOULD”,”WRITE”,”WRITER”,”WRITING”,”WRONG”,”YARD”,”YEAH”,”YEAR”,”YES”,”YESTERDAY”,”YET”,”YOU”,”YOUNG”,”YOUR”,”YOURSELF”,”YOUTH”)
alpha_value={“A”:1,”B”:2,”C”:3,”D”:4,”E”:5,”F”:6,”G”:7,”H”:8,”I”:9,”J”:10,”K”:11,”L”:12,
“M”:13,”N”:14,”O”:15,”P”:16,”Q”:17,”R”:18,”S”:19,”T”:20,”U”:21,”V”:22,”W”:23,”X”:24,”Y”:25,”Z”:26}
|
The Code:
# Function to get the word value
def get_word_value (the_word):
tot=0
for each in the_word:
tot = tot + alpha_value [each]
return tot
def triangle_numbers (the_value):
count_n = 1
while count_n <= the_value :
if ((count_n / 2) * (count_n + 1)) == the_value :
return True
break
else:
count_n = count_n + 1
return False
# Here we call each function and get the total_count of Triangle words
total_count=0
for each in The_words:
check_word =(each)
word_value = get_name_value (check_word)
if triangle_numbers (word_value) :
print (each,word_value,’True’)
total_count = total_count +1
print(‘Total Triangle Words=’,total_count)
|
Python: Digit fifth Powers
Python: Digit Fifth Powers
Projecteuler Problem No.30
This was an easy task and I solve it on my mobile during a brain resting session 😜. I will just copy the problem statement as it is in ProjectEuler ..
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44As 1 = 14 is not a sum it is not included.
The sum of these numbers is 1634 + 8208 + 9474 = 19316.Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
Read it on Projecteuler
My Problem When I start solving the task i was wondering how far i should check the numbers? We can’t just go for ever, we must stop in some range. I search the web for such cases an i fond a post that clearing this with a formula. I will explain this in my way.
Finding the Upper Limits:
1. We are talking about Power (P=5)
2. We are using the (Base ten) numbers, so the highest digit is 9. Then:
3. 9 power 5 (9p5 = 59049)
4. The digits in (59049) are D=5.
5. Finally, The Formula is (D * 9p5), 5 * 59049 = 295245
6. So, The Upper Limits = 295245
|
According to the “Finding the Upper Limits” section, if we want to use the power (4) then the upper limit will be:
9p4 = 6561
6561 is a 4 digits
upper limit = 4 * 6561 = 26244
The Code: [The code is for power 4]
# Digit Fifth Powers
# Projecteuler Problem 30
num = 2
pdig = []
wefound = []
thesum = 0
while num < 26244 :
for each in str(num):
pdig.append(int(each) ** 4)
for x in pdig:
thesum = thesum + int(x)
if thesum == num:
wefound.append(num)
print(‘\n Number =’, num)
print(‘ Digits Power 4 =’, pdig)
print(‘ The Sum ‘, thesum)
num = num + 1
pdig = []
thesum = 0
thesum = 0
for x in wefound:
thesum = thesum + x
print(“\n The Numbers that the 4th power of its each digit = itself are: “,wefound)
print(” The Sum of the numbers is: “,thesum)
|
Follow me on Twitter.. |
Python: Self Power
Python: Self Powers
Problem No.48 on ProjectEuler
Another easy task in Problem No.48. We have to find the power of each number to itsefl in the range of 1 to 1000 and get the sum of all numbers, then to find the last ten digits of the series.
In this Task we will save the powers in a set name powers then we run a for loop
to get the sum of all elements in the lest, later will reade the last ten digits.
Enhancment In this problem I will not do any more than solving the problem, but if we want to enhance the project, we can ask the user to enter a range and we perform the function on that range of numbers.
|
|
The Code:
powers=[]
def get_power(num):
powers.append(num**num)
for x in range(1,1001):
get_power(x)
sum=0
for each in powers:
sum=sum+each
print(powers)
print (‘the sum is ‘,sum)
Python : Curious Number
Python: Curious Number
Problem No.34 in ProjectEuler
Definition: A number is Curious Number if the factorial of their digits equal to the number itself.
Example: 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Our Task: We will write two functions, first one will get (return) all digits in the number, then another function to get the factorial of each digits in that number then with If statement we will examine the result.Enhancement: We will ask the user to enter a number and we will check if it is a Curious Number.
We will reuse some of our functions that we wrote in previous posts.
The Code:
digs=[]
print(‘\nEnter a number to see if it is a Curious Number or not.’)
num=input (‘\nEnter a number: ‘)
num=input (‘Enter a number: ‘)
tot=0
# To get the digits In a number
def digits_in_num (num):
for each in str(num):
digs.append(each)
# To get the Factorial of a number
def Factorial_digit_sum(num):
if (num == 0) :
return 1
else:
return num * Factorial_digit_sum(num-1)
for each in digs:
print(‘factorial :’,each,’ is ‘,Factorial_digit_sum(int(each)))
tot = tot + Factorial_digit_sum(int(each))
print(‘\nTotal sum of the Factorial of each digits is: ‘,tot)
if int(num) == tot:
print(num ,’Is a Curious Number.’)
else:
print(num ,’Is NOT Curious Number.’)
Python: Multiples of Numbers
Python: Multiples of 3 and 5
Problem No.1 in ProjectEuler
This is very easy, very short task to work on, the task as is in ProjectEuler like this “Find the sum of all the multiples of 3 or 5 below 1000.”
My way, as i like to do open code works for any numbers, we will ask the user to enter three numbers, num1 and num2 will be as (3 and 5) in the task, my_range will be as the 1000. So the code can get the sum Multiples of any two numbers in a ranges from 1 to my_range.
The Code:
# Multiples of 3 and 5
# ProjectEuler: Problem 1
def Multiples_of_N (num1,num2,my_range):
tot=0
for t in range (1,my_range):
if t %num1==0 or t%num2 ==0 :
tot = tot + t
return tot
print ‘\nDescription: This function will take three variables, two numbers represint the what we want to get there Multiples, then we ask for a range so we will start from 1 to your range.\n’
num1=int(input(‘Enter the first number:’))
num2=int(input(‘Enter the second number:’))
my_range =int(input(‘Enter the range (1, ??):’))
total=Multiples_of_N (num1,num2,my_range)
print ‘\nYou entered ‘,num1,’,’, num2,’ So the sum of all multiples of those number in range (1-‘,my_range,’) = ‘,total
Python: Largest product in series
Python: Largest product in a series
Problem 8 @ projectEuler
In Problem 8, ProjectEuler wants to find the thirteen adjacent digits in the 1000-digit number that have the greatest product.
In this task i use a for loop to check each 13-dig set, each time creating a set of 13 digits starting from (0,13) then (1,14)..(2,15)….. and so-on. for each set i get the product of its digits and store it in an a array of [set,total] each time if total of the new set is larger than what we have in the array[total] then we write the new values to the array, we call the array largest.
The Code:
# Largest product in a series
# ProjectEuler: Problem 8
num=’7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
‘
v1=0
v2=13
set1=num[v1:v2]
largest =[0,0]
tot=1
for x in range((1000)):
set1=num[v1:v2]
for each in set1:
tot=tot * int(each)
if tot > largest [1]:
largest[0] = set1
largest[1] = tot
tot=1
tot =1
v1=v1+1
v2=v2+1
print’The thirteen adjacent digits are’,largest[1],’there product is ‘,largest[0]
Python: Factorial Digit Sum
Python: Factorial Digit Sum
Problem 20 @ projectEuler
The Task: The task in projectEuler P20 is to get the sum of the digits in the number Factorial of 100!
Factorial NdefinitionThe factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 10! = 10 × 9 × … × 3 × 2 × 1 = 3628800.
Problem 20 is another easy problem in projectEuler, and we will write two functions to solve it. First one is a Factorial_digit_sum this one will return the factorial of a number. The second function will calculate the sum of all digits in a number N and we will call it sum_of_digits.
Clarification As long as i just start solving or posting my answers to projectEuler portal, i am selecting problems and not going through them in sequence, that’s way my posts are jumps between problems, so if i am posting the code to solve problem 144 (for example) that does’t meaning that i solve all problems before it.
print of solved screen:

The Code:
#Python: Factorial Digit Sum
#Problem No.20 on projectEuler
def Factorial_digit_sum(num):
if (num == 0) :
return 1
else:
return num * Factorial_digit_sum(num-1)
num=100
fact =Factorial_digit_sum(100)
print fact,’is the Factorial of {}.’.format(num)
def sum_of_digits(dig):
t = 0
for each in dig:
t = t + int(each)
print ‘\nThe sum of your number is’,t
sum_of_digits(str(tot1))


Follow me on Twitter..














