I made an odd language called "Lojban",
You need to make a program to convert a string Lojban input to a normal number, then output it.
The numbers from zero to nine are:
1 pa 4 vo 7 ze
2 re 5 mu 8 bi 0 no
3 ci 6 xa 9 so
Larger numbers are created by gluing the digits together. For example, 123 is pareci.
I have already done this one, but my implementation may be crap. Please do not post source until after 26th April 17:00 BST to make sure no-one plagiarises.
PM me your source code in any language at all (tell me what it is, and if it is a bloody obscure language *please* give me compiling instructions (Languages like brain

, the weird image one and suchlike)

)
I have a scoring system too, so I will be able to (hopefully) determine a winner.
Post your entrance notice in here.
I'm excited. I'll do it!
But I don't understand.. The user imputs a number, and then the program outputs a word based off what you posted?
The other way, I put in a number in Lojban and you generate the numerical version.
So you would input pa, and the program would output 1?
Yep, input pareci for 123.
Good luck!
This isn't hard I believe , its almost like counting words in a string (same logic) though I cant be assed to work on this atm :dodgy:
(04-25-2009 07:15 AM)Aspras Wrote: [ -> ]This isn't hard I believe , its almost like counting words in a string (same logic) though I cant be assed to work on this atm :dodgy:
Not even for +rep points?
Bluehairman, you scored 83 arbitrary points

I scored 90.
+rep points? The only reason why Id do it is to practice and learn. Richard I sent you my source in a pm. Also I was wondering If I am allowed to post this challenge in a greek forum which was made to help highschool students in my country with a programming subject at school. Its the only one in its kind and the administrator does not seek popularity in any way. Credits for the challenge will go to you Richard if you agree with me translating it and posting it.
Feel free!
You scored 69 -.-
You engineered that, didn't you, Mr 69
One hour left to enter guise!
Umm what did I engineer ?
A score of 69

Times up, seeing as my entry does not count, Bluehairman wins!!
Oh

, so I guess the score gets generated according how fast the decimal value is generated ?
Yay! I'm not sure which one he used, because I didn't have a way to test either of my programs for speed, but here's both:
C++ Programming
#include <string>
#include <map>
#include <iostream>
using namespace std;
string inp;
string loj;
//--------------------------------------------------
//--------------------------------------------------
int main(int argc, char *argv[])
{
while(1){
cout << "enter lojban." << endl;
getline(cin, inp);
for (int i = 0; (i <= inp.length()); i += 2){
loj = inp.substr(i,2);
if(loj == "pa"){ //"pa"
cout << "1"; }
if(loj == "re"){ //"re"
cout << "2"; }
if(loj == "ci"){ //"ci"
cout << "3"; }
if(loj == "vo"){ //"vo"
cout << "4"; }
if(loj == "mu"){ //"mu"
cout << "5"; }
if(loj == "xa"){ //"xa"
cout << "6"; }
if(loj == "ze"){ //"ze"
cout << "7"; }
if(loj == "bi"){ //"bi"
cout << "8"; }
if(loj == "so"){ //"so"
cout << "9"; }
if(loj == "no"){ //"no"
cout << "0"; }
if(loj == "--"){
return 0; }
}//for close
cout << endl;
}//while close
} //main close
C++ Programming
#include <string>
#include <map>
#include <iostream>
enum strnghld { pa,
re,
ci,
vo,
mu,
xa,
ze,
bi,
so,
no,
exitr };
using namespace std;
static map<string, strnghld> lojmap;
static char* inp;
string loj;
string loji;
void setvalue()
{
lojmap["pa"] = pa;
lojmap["re"] = re;
lojmap["ci"] = ci;
lojmap["vo"] = vo;
lojmap["mu"] = mu;
lojmap["xa"] = xa;
lojmap["ze"] = ze;
lojmap["bi"] = bi;
lojmap["so"] = so;
lojmap["no"] = no;
lojmap["--"] = exitr;
}
//--------------------------------------------------
//--------------------------------------------------
int main()
{
setvalue();
while(1){
cout << "enter lojban." << endl;
getline(cin, loji);
for (int i = 0; (i < loji.length()); i += 2){
loj = loji.substr(i,2);
switch(lojmap[loj])
{
case pa:
cout << "1";
break;
case re:
cout << "2";
break;
case ci:
cout << "3";
break;
case vo:
cout << "4";
break;
case mu:
cout << "5";
break;
case xa:
cout << "6";
break;
case ze:
cout << "7";
break;
case bi:
cout << "8";
break;
case so:
cout << "9";
break;
case no:
cout << "0";
break;
case exitr:
return 0;
break;
default:
cout << "-";
} //switch
}//for
cout << endl;
}//while
}//main
And Richard, I'm wondering what you used?
I didn't factor in speed. I took your shortest one. I just crashed my source D:
So I cannot show you the awesome way I did it

. (I didn't use big switche statements/if-else trees).
(04-25-2009 04:04 PM)Richard Wrote: [ -> ]I didn't factor in speed. I took your shortest one. I just crashed my source D:
So I cannot show you the awesome way I did it
. (I didn't use big switche statements/if-else trees).
Well maybe you should explain how you did it ;)
I think that instead of using many if statements he used just one inside a loop where he had a variable incrementing and corresponding to one of the first characters, or something like that I believe.
(04-25-2009 04:41 PM)Aspras Wrote: [ -> ]I think that instead of using many if statements he used just one inside a loop where he had a variable incrementing and corresponding to one of the first characters, or something like that I believe.
Very good idea. I never thought of that.
Aspras, if you don't mind, would you post your code?
Thats the only way I could think of since he says he didnt use many if statements or cases. I dont know if that makes the application faster though since theres only 10 cases. Also
here is my sourcecode.
(04-25-2009 05:33 PM)Aspras Wrote: [ -> ]Thats the only way I could think of since he says he didnt use many if statements or cases. I dont know if that makes the application faster though since theres only 10 cases. Also here is my sourcecode.
Ahh. I see.
He didn't count speed, and since I don't know how he scored I don't know how he came up with the numbers. Organization? How well you put everything together and made it work?
I just thought of a way to count speed, you just thread a timer at the beginning of main and then close it as well as output time before main ends.
(04-25-2009 09:29 PM)Aspras Wrote: [ -> ]I just thought of a way to count speed, you just thread a timer at the beginning of main and then close it as well as output time before main ends.
I always thought of this as a bad idea because it could slow it down. But I don't think a thread could slow it down. Could it?
The way you time your code is...
C++ Programming
#include <windows.h>
int main() {
DWORD initialCount = ::GetTickCount();
yourCodeToBeTimedGoesHere();
DWORD finalCount = ::GetTickCount();
cout << "Your code took " << finalCount - initialCount << " milliseconds to execute!" << endl;
return 0;
}
This is fine for timing algorithms that execute on large data sets, but if you want more precision you need to use other timers, like the ones described in the "Remarks" section
here...
Creating a secondary thread to time your code would be overkill, and Windows would also slow down your program a little bit for thread synchronization stuff...
Thank you for that code

That looks better, I know a thread would certainly slow the application down though it wouldnt matter if the exact same code was implemented in all applications since they would all be slowed down by the same amount of time, im not sure about this its just a logical assumption

Better yet, Seeing as I tested them in Linux, I could use the time command.
I did it by having an array of numbers and an array od lojban numbers. I then did a camparison between a lojban number and the number fgiven, if it was found, the number at the index was added to the result string. I also did an integrity of the number check, by checking that the length moduloed to 2.
Im not sure if I understand what you did, you checked whether the programs had converted lojban to numbers correctly?
O.o?
No.
Argh :@ I'm annoyed I lost it.
Right, I had an array of Lojban, which I iterated through and compared with substrings of the input string. When I found a match, I int-to-str'ed the iterator and concatenated it onto the result string. I basically compacted all the if/else tree into a loop.
Sorry I thought you were explaining how you got the score thats why I found it weird and why you found my reply weird haha.