Historical SampleCode, Revision 3

Sieve Of Erathosthenes

include get.e
procedure eratosthenes(integer target)

  sequence sieve
  integer next_prime
  integer limit
  sieve = repeat(0, target)
  limit = floor(power(target, 0.5))
  sieve[1] = 1
  next_prime = 2
  while next_prime <= target and next_prime != 0 do
    if next_prime <= limit then
      for i = next_prime + next_prime to target by next_prime do
        sieve[i] = 1
      end for
    end if
    printf(1, "%d ", next_prime)
    next_prime = find_from(0, sieve, next_prime+1)
  end while
end procedure

procedure main(sequence argv)
  integer n

  n = 50
  if length(argv) >= 3 then
    argv = value(argv[3])
    n = argv[2]
  end if
end procedure

main( command_line() )

99 Bottles of Beer

include wildcard.e

function cap(sequence x)
	x[1] = upper(x[1])
	return x
end function

function count_bottles(integer n)
    sequence text
    switch n do
	  case 0:
		text = "no more bottles"
	  case 1:
		text = "1 bottle"
	  case else
		text = sprintf("%d bottles", n)
	end switch
	return text
end function

procedure main()
  sequence bottlecount
  bottlecount = count_bottles(99)

  for i = 99 to 0 by -1 do
    -- Line one of the stanza
    printf(1, "%s of beer on the wall, %s of beer.\n", 
            {cap(bottlecount), bottlecount})
    -- Line 2 of the stanza
    if i > 0 then
      puts(1, "Take one down and pass it around, ")
      puts(1, "Go to the store and buy some more, ")
    end if
   if i > 0 then
  	 bottlecount = count_bottles(i-1)
  	 bottlecount = count_bottles(99)
   end if
   printf(1, "%s of beer on the wall.\n\n", 
  end for
end procedure
Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu