LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 679 users online 221676 members 992 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
WhoreosandMilk
Cool Things: skating, partying, metal
Mood: Scheming
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
6 online / 26 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

OCaml help
Eratosthenes' prime sieve
Replies: 1Last Post Dec. 31, 2008 5:24pm by Whit3 Gangst3r
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( Dangeresque )


Lawn Care Specialist
Reply
Hey, I am new to this site.  I need some help debugging some OCaml code.  This is a simple Eratosthenes' prime sieve algorithm.  I can do this easily in C, C++, C#, Java, MATLAB, Ruby, and Python, but as I am learning OCaml as my first functional programming language I can't get this to compile.  I would really appreciate your help with this as a friend of mine recommended this site for teen programmers.  Thanks again.  Keep in mind that I am trying to keep this recursive.

let max = 1000 in
let primes = Array.create 1000 true in
let num = 2 in
let outer_func num =
 if num == sqrt.max then num  
 else if primes.(num) == true then
    let pos = num * num in
    let inner_func pos =
       if pos > max then pos
       else (
          primes.(pos)<-false;);
       inner_func (pos + num);
  outer_func (num + 1);
for counter = 2 to max do
  if primes.(counter) == true then
     print_line counter;
done;;


5:05 am on Sep. 10, 2006 | Joined: Sep. 2006 | Days Active: 8
Join to learn more about Dangeresque United States | Posts: 11 | Points: 91
LiveWire Humor
Whit3 Gangst3r

Novice
Reply
Dayummm, and no one replied... HAH!

5:24 pm on Dec. 31, 2008 | Joined: Dec. 2008 | Days Active: 3
Join to learn more about Whit3 Gangst3r United Kingdom | Posts: 103 | Points: -869
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic