Beginners Task #2

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

Postby scrappy » Tue Feb 01, 2005 12:54 pm

have not been here for a while. here's my solution.
Code: Select all
#include <iostream>
#include <cstdlib>
using namespace std;

int main(void)
{   
int primes[1000];   
int number,count,x,lastprime;

lastprime=2;
count=0;
cout<<"Enter the number";
cin>>number;

while(number>1){
  for(x=lastprime;x<=number;x++){
      if(number%x==0){
          primes[count]=x;
          lastprime=x;
          count++;
          number=number/lastprime;
          break;
      }
  }
}
     
for(x=0;x<count-1;x++){
    cout<<primes[x]<<"x";
}             
cout<<primes[count-1];   
    system("PAUSE");
    return 0;
}
scrappy
 
Posts: 3
Joined: Sat Aug 07, 2004 2:18 pm

Postby schloob » Fri Feb 11, 2005 5:13 pm

heres my solution in schloobscript:

Code: Select all
stdin $num;
int $num;
pos $begin1;
set $i 2;
pos $begin2;
set $m $num;
mod $m $i;
not $m;
if $m 4;
print $i;
print " * ";
div $num $i;
goto $begin1;
set $a $i;
mult $a $a;
lt $a $num $r;
if $r 2;
add $i 1;
goto $begin2;
print $num;


:D :D :D
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby tomcant » Fri Feb 11, 2005 5:28 pm

:D Nice to see my contest is still going!
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby schloob » Fri Feb 11, 2005 6:10 pm

tomcant wrote:Nice to see my contest is still going!
i decided to try some of the contests with schloobscript :D its 4x faster than php! yay!
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Darobat » Fri Feb 11, 2005 6:29 pm

Does it actually create an exe or just run it from the console that "compiled" it?
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby schloob » Fri Feb 11, 2005 6:53 pm

Darobat wrote:Does it actually create an exe or just run it from the console that "compiled" it?
its interpreted :x

as in

ss c:/ss.txt

will run whats in ss.txt :-\
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Corsix » Sat Feb 12, 2005 2:11 am

I know how you could make an exe - the cheating way...
Have an exe interpreter that has the code in an RCData resource.
To make an exe copy this new interpreter exe and use Win32's UpdateResource
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby Corsix » Sun Feb 13, 2005 5:31 pm

and my solution in CorsixScript:
Code: Select all
include "io.cxs" "math.cxs" "logic.cxs"
print "Enter number: "
set $number 0
scan $number
print "Prime factors: "
section $part1
eq $number 1 $num_is_1
isprime $number $num_is_p
ifany $num_is_1 $num_is_p
jump $finish
set $int 1
section $part2
add $int 1
isprime $int $num_is_p
ifnot $num_is_p
jump $part2
set $modres $number
mod $modres $int
if $modres
jump $part2
print $int " * "
div $number $int
jump $part1
section $finish
print $number
end
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby schloob » Sun Feb 13, 2005 5:39 pm

you just cant beat schloobscript though.. its so compact! so awesome! so.. so.. BETTER! :mrgreen:

corsixscript is so cliché, so un-good

its all about the schloob script baby! :o
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Corsix » Sun Feb 13, 2005 5:48 pm

schloob wrote:corsixscript is so cliché, so un-good
Did I say that it was good? But what makes it so cliché? The fact that you didn't make it?
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby schloob » Sun Feb 13, 2005 5:57 pm

Corsix wrote:
schloob wrote:corsixscript is so cliché, so un-good
Did I say that it was good? But what makes it so cliché? The fact that you didn't make it?


The fact that you didn't make it?
exactly! :mrgreen:

why is it cliché?

half of it is mine for one, and your if statements are unoriginal

im only joking here, if you didnt gather that, i still think your is neat :biggun:
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby allan » Sun Feb 13, 2005 5:59 pm

stop with that smilie schloob.
allan
 
Posts: 47
Joined: Tue Jul 20, 2004 12:55 pm

Postby Corsix » Sun Feb 13, 2005 6:01 pm

schloob wrote:im only joking here, if you didnt gather that, i still think your is neat

i know :mrgreen: , i did, as do I

edit: but :biggun: brings so much happiness...
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby schloob » Sun Feb 13, 2005 6:23 pm

whahaahah, that just makes me laugh too much :mrgreen:



wizard, do you think we could like switch :D with :mrgreen:.. the :D face sucks pretty bad -.-
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Beer Hunter » Mon Feb 14, 2005 12:32 am

In accordance with the current theme, here's a solution in my new language, Unsuckscript.
Code: Select all
print "Enter a number: "
x = readint()
print "Prime factors: " + [
   i = 2
   while i <= x:
      if x % i == 0: yield i; x /= i
      else: i += 1
   ].join(" x ")
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

PreviousNext

Return to Contests

Who is online

Users browsing this forum: No registered users and 0 guests