Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,757 members, 7,824,172 topics. Date: Saturday, 11 May 2024 at 02:40 AM

Programming Challenge - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Programming Challenge (853 Views)

Programming Challenge For Beginners Competition Two N20000 -SEASON 2- / Programming Challenge For Beginners N20000 / Facebook Programming Challenge Question (2) (3) (4)

(1) (Reply) (Go Down)

Programming Challenge by elvis10ten(m): 2:21pm On Jul 14, 2013
Write a love calculator that will use the FLAMES love calculation to compute the future of two partners. How the FLAMES love calculation works :
* You will be given two different names as the input, one for each of the partners.
The common letters in the name will cancel out or will be removed, that is if you are given Elvis and Lois, l, i and s will cancel out leaving Ev and O.
* The remaining letters in each name would be counted and added together then stored in a variable, the above example only three letters are left.
* Use the stored variable to go across the word FLAMES. That is you will have to go through each letter and increment a counter variable each time you pass each letter and start all over from F again until you get the number stored in your variable(the number of letters remaining). Example: 3 falls under letter A; hint: counter = 0; variable = 3 while() { counter++; if counter != variable { goto next letter on flame } else { print result } }. Based on the last letter the loop stopped at, you output their fate/future, Where F = Friends, L = Lovers, A = Admirers, M = Married, E = Enemies, S = Sister.
* Print out the two names with the corresponding value. Example "Elvis and Lois are ADMIRERS". You can also add a percentage that tells how true the result is.
RULES 1) Run your code on www.ideone.com .
2)Any programming language is allowed.
3)your code should be fast enough to run properly on a poor cpu.
4)The person with the shortest and fastest code wins.
Re: Programming Challenge by Nobody: 6:18pm On Jul 14, 2013
Try to paragraph your post, its kinda difficult undastanding it.
Re: Programming Challenge by elvis10ten(m): 9:23pm On Jul 14, 2013
Modified
Re: Programming Challenge by WhiZTiM(m): 10:01pm On Jul 14, 2013
Be more specific at your problems @OP! ...
Here are 2 optimized solutions . . ...
The close to fastest... C++

http://ideone.com/T2RerE
took 0 seconds to run..

/* (C) WhiZTiM 2013 */
#include <iostream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;
typedef string::size_type szT;
typedef vector<string> VEC_string;

void strip_common_characters(string& A, string& B)
{
//choose the shortest string to save iteration time
string& S1 = A.size() <= B.size() ? A : B; //by reference!
string& S2 = A.size() > B.size() ? A : B; //by reference!
szT i = 0;
while(i < S1.size())
{
bool found = false;
szT lc = S2.find(S1[i]);
if(lc != string::npos) found = true;
else
{
lc = S2.find(tolower(S1[i]));
if(lc != string::npos) found = true;
}
if(found)
{
S1.erase(i, 1);
S2.erase(lc,1);
continue;
}
++i;
}
}

void instantiateMap(VEC_string& mp)
{
mp.push_back("Friends"wink;
mp.push_back("Lovers"wink;
mp.push_back("Admirers"wink;
mp.push_back("Married"wink;
mp.push_back("Enemies"wink;
mp.push_back("Sisters"wink;
}

void run()
{
string s1, s2, s3, s4;
getline(cin, s1);
getline(cin, s2);
s3 = s1; s4 = s2;

VEC_string mp;
instantiateMap(mp);

strip_common_characters(s1, s2);
unsigned k = s1.size() + s2.size();
k = (k - 1) < 0 ? 0 : ((k - 1) % mp.size());

cout << s3 << " and " << s4 << " are " << mp[k] << endl;
}

int main(int argc, char* argv[])
{
run();
return 0;
}
Re: Programming Challenge by bigt2(m): 10:25pm On Jul 14, 2013
What's wrong with these smileys? wink wink everytime. angry


dis one na die o!!
Re: Programming Challenge by WhiZTiM(m): 10:34pm On Jul 14, 2013
Another... much shorter SLoC...

http://ideone.com/HKdiNS

0.01second on my PC... when I piped input to stdin
It works on my Machine... I am on a Mobile now... can't really make it run on IDEone... this is my 3rd attempt to make it work....
#annoyed.. bad phone, MTN frustrating me and my Money...

PYTHON 2.5+ < 3.0

#!/usr/bin/python
#(C) WhiZTiM 2013

def commonLen(s1, s2):
s1 = s1.lower()
s2 = s2.lower()
k = 0
while(k < len(s1)):
if(s2.find(s1[k]) == -1):
k += 1
continue
s2 = s2.replace(s1[k], '', 1)
s1 = s1.replace(s1[k], '', 1)
return ( len(s1) + len(s2) )

def getVerdict(s1, s2):
mp = ["Friends", "Lovers", "Admirers", "Married", "Enemies", "Sisters"]
ln = commonLen(s1, s2)
ln = 0 if( (ln - 1) < 0) else ((ln - 1) % 6)
return mp[ln]

def main():
s1 = raw_input()
s2 = raw_input()
ans = s1 + " and " + s2 + " are " + getVerdict(s1, s2)
print ans

if(__name__ == '__main__'):
main()


#PythonSquad
Re: Programming Challenge by WhiZTiM(m): 11:10pm On Jul 14, 2013
@op. Thanks for the post... I remember something like this way back in Junior School... But there was something I am not sure I understood from your question . .
Re: Programming Challenge by elvis10ten(m): 4:40am On Jul 15, 2013
WhiZTiM: @op. Thanks for the post... I remember something like this way back in Junior School... But there was something I am not sure I understood from your question . .
wats that ?
Re: Programming Challenge by WhiZTiM(m): 9:47am On Jul 15, 2013
elvis10ten: wats that ?
for two names KABA and BAKKE...should the occurence K in KABA cancel out the 2 Ks in BAKKE? or just one K?

A concrete cancellation example.
iNPUT: KABA and BAKKE
OUTPUT: exclusive chars are "" and "E"
or
OUTPUT: exclusive chars are "A" and "KE"
Re: Programming Challenge by WhiZTiM(m): 10:20am On Jul 15, 2013
here is my pseudocode solution in Java...



Sorry, I ment Arabic cheesy

ﺎﻬﻧﺍ ... ﺓﺮﻔﺸﻟﺍ ﻒﻄﺘﻘﻣ ﺲﻴﻟ ﺍﺬﻫ !ﺍﻮﻔﻋ !ﺔﻌﺘﻤﻠﻟ ﺩﺮﺠﻣ
Re: Programming Challenge by Nobody: 11:23am On Jul 15, 2013
^^^ angry *sharpening cutlass*
Re: Programming Challenge by elvis10ten(m): 2:55pm On Jul 15, 2013
WhiZTiM:
for two names KABA and BAKKE...should the occurence K in KABA cancel out the 2 Ks in BAKKE? or just one K?

A concrete cancellation example.
iNPUT: KABA and BAKKE
OUTPUT: exclusive chars are "" and "E"
or
OUTPUT: exclusive chars are "A" and "KE"
only one k. One letter for one letter.
Re: Programming Challenge by elvis10ten(m): 2:58pm On Jul 15, 2013
Lmao, you dey find trouble abi.
WhiZTiM: here is my pseudocode solution in Java...



Sorry, I ment Arabic cheesy

ﺎﻬﻧﺍ ... ﺓﺮﻔﺸﻟﺍ ﻒﻄﺘﻘﻣ ﺲﻴﻟ ﺍﺬﻫ !ﺍﻮﻔﻋ !ﺔﻌﺘﻤﻠﻟ ﺩﺮﺠﻣ
Re: Programming Challenge by elvis10ten(m): 6:48pm On Jul 16, 2013
@whiZTiM, you are the winner of this challenge. Bravo. Your solution is the best so far.

(1) (Reply)

C++/c Compilers Are So Bad. / Internet-enabled Desktop Applications / Please Help.. How Do I Stop This?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.