-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
685 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
% 2004 J1: Squares | ||
% | ||
% this is a simple case of getting the square root as an integer | ||
% | ||
|
||
var tiles: int | ||
|
||
put "Number of Tiles?" | ||
get tiles | ||
put "The largest Square has side length ", floor (sqrt (tiles)), "." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
% 2004 J2: Terms of Office | ||
% | ||
% this is a simple case of using the mod operator to cycle through | ||
% some "cycles". | ||
% | ||
|
||
var cy, fy,m,t,c,d: int | ||
|
||
put "Enter the current year:" | ||
get cy | ||
put "Enter a future year:" | ||
get fy | ||
m:=0 | ||
t:=0 | ||
c:=0 | ||
d:=0 | ||
for y: cy .. fy | ||
if m = 0 and t = 0 and c = 0 and d = 0 then | ||
put "All positions change in year ", y | ||
end if | ||
m := (m+1) mod 4 | ||
t := (t+1) mod 2 | ||
c := (c+1) mod 3 | ||
d := (d+1) mod 5 | ||
end for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
% 2004 J3: Similes | ||
% | ||
% nested loops print all combinations of two arrays | ||
% | ||
|
||
var m, n : int | ||
var adj : array 1 .. 5 of string | ||
var noun : array 1 .. 5 of string | ||
|
||
get n | ||
get m | ||
for i : 1 .. n | ||
get adj (i) | ||
end for | ||
for i : 1 .. m | ||
get noun (i) | ||
end for | ||
for i : 1 .. n | ||
for j : 1 .. m | ||
put adj (i), " as ", noun (j) | ||
end for | ||
end for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
% 2004 J4: Encryption | ||
% | ||
% String processing and encryption using a keyword to shift. | ||
% - need to cycle through the keyword letters | ||
% ('A' shifts 0, 'B' shifts 1, etc.) | ||
% - if the resulting letter (after the shift) is beyond 'Z' | ||
% need to bring it back | ||
% (eg if it is 4 beyond Z, it should be a 'D' (ie. 'A' + 3) | ||
% | ||
|
||
var key, plain : string | ||
var i, l : int | ||
|
||
get key | ||
get plain : * | ||
i := 1 | ||
for j : 1 .. length (plain) | ||
if plain (j) >= "A" and plain (j) <= "Z" then | ||
l := ord (plain (j)) + (ord (key (i)) - ord ('A')) | ||
if l > ord ('Z') then | ||
l := ord ('A') + (l - ord ('Z') - 1) | ||
end if | ||
put chr (l) .. | ||
i := i + 1 | ||
if i > length (key) then | ||
i := 1 | ||
end if | ||
end if | ||
end for | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
% 2004 J5: Fractals | ||
% | ||
% Long ugly array and geometry calculations | ||
% using 1D array storage | ||
% | ||
% ox,oy are arrays of the old endpoints of the lines making up the fractal | ||
% using these lines, the nx,ny arrays of end points are created. | ||
% (brute force: all 4 directions are considered.) | ||
% then the old arrays are replaced by the new ones | ||
% repeat for all the levels | ||
% | ||
% finally all the points (xcoor,y) where y = 1,2,3,... are checked to see if | ||
% they are on any of the lines. If they are, the | ||
|
||
var ox : array 1 .. 7000 of int | ||
var oy : array 1 .. 7000 of int | ||
var nx : array 1 .. 7000 of int | ||
var ny : array 1 .. 7000 of int | ||
var ans : array 1 .. 100 of int | ||
var level, xcoor, width, w, size, k, n : int | ||
var done : boolean | ||
|
||
get level, width, xcoor | ||
ox (1) := 0 | ||
oy (1) := 1 | ||
ox (2) := width | ||
oy (2) := 1 | ||
size := 2 | ||
for i : 1 .. level | ||
k := 0 | ||
for j : 1 .. size - 1 % for each line | ||
k := k + 1 | ||
nx (k) := ox (j) | ||
ny (k) := oy (j) | ||
if oy (j) = oy (j + 1) and ox (j + 1) > ox (j) then % right | ||
w := (ox (j + 1) - ox (j)) div 3 | ||
k := k + 1 | ||
nx (k) := ox (j) + w | ||
ny (k) := oy (j) + 0 | ||
k := k + 1 | ||
nx (k) := ox (j) + w | ||
ny (k) := oy (j) + w | ||
k := k + 1 | ||
nx (k) := ox (j) + 2 * w | ||
ny (k) := oy (j) + w | ||
k := k + 1 | ||
nx (k) := ox (j) + 2 * w | ||
ny (k) := oy (j) + 0 | ||
k := k + 1 | ||
nx (k) := ox (j + 1) | ||
ny (k) := oy (j + 1) | ||
elsif oy (j) = oy (j + 1) and ox (j + 1) < ox (j) then % left | ||
w := (ox (j) - ox (j + 1)) div 3 | ||
k := k + 1 | ||
nx (k) := ox (j) - w | ||
ny (k) := oy (j) + 0 | ||
k := k + 1 | ||
nx (k) := ox (j) - w | ||
ny (k) := oy (j) - w | ||
k := k + 1 | ||
nx (k) := ox (j) - 2 * w | ||
ny (k) := oy (j) - w | ||
k := k + 1 | ||
nx (k) := ox (j) - 2 * w | ||
ny (k) := oy (j) + 0 | ||
k := k + 1 | ||
nx (k) := ox (j + 1) | ||
ny (k) := oy (j + 1) | ||
elsif ox (j) = ox (j + 1) and oy (j + 1) < oy (j) then % down | ||
w := (oy (j) - oy (j + 1)) div 3 | ||
k := k + 1 | ||
nx (k) := ox (j) + 0 | ||
ny (k) := oy (j) - w | ||
k := k + 1 | ||
nx (k) := ox (j) + w | ||
ny (k) := oy (j) - w | ||
k := k + 1 | ||
nx (k) := ox (j) + w | ||
ny (k) := oy (j) - 2 * w | ||
k := k + 1 | ||
nx (k) := ox (j) + 0 | ||
ny (k) := oy (j) - 2 * w | ||
k := k + 1 | ||
nx (k) := ox (j + 1) | ||
ny (k) := oy (j + 1) | ||
elsif ox (j) = ox (j + 1) and oy (j + 1) > oy (j) then % up | ||
w := (oy (j + 1) - oy (j)) div 3 | ||
k := k + 1 | ||
nx (k) := ox (j) + 0 | ||
ny (k) := oy (j) + w | ||
k := k + 1 | ||
nx (k) := ox (j) - w | ||
ny (k) := oy (j) + w | ||
k := k + 1 | ||
nx (k) := ox (j) - w | ||
ny (k) := oy (j) + 2 * w | ||
k := k + 1 | ||
nx (k) := ox (j) + 0 | ||
ny (k) := oy (j) + 2 * w | ||
k := k + 1 | ||
nx (k) := ox (j + 1) | ||
ny (k) := oy (j + 1) | ||
end if | ||
end for | ||
size := k | ||
for m : 1 .. size | ||
ox (m) := nx (m) | ||
oy (m) := ny (m) | ||
end for | ||
end for | ||
|
||
% graph, just for fun :-) | ||
for m : 1 .. size - 1 | ||
drawline (ox (m) * 5, oy (m) * 5, ox (m + 1) * 5, oy (m + 1) * 5, | ||
black) | ||
end for | ||
|
||
|
||
% check if the points (xcoor,1), (xcoor,2), ... are on any lines. | ||
for i : 1 .. 81 | ||
k := 1 | ||
done := false | ||
loop | ||
exit when k = size or done | ||
if ox (k) = ox (k + 1) and oy (k) < oy (k + 1) | ||
and xcoor = ox (k) and (i >= oy (k) and i <= oy (k + 1)) then | ||
put i, " " .. | ||
done := true | ||
elsif ox (k) = ox (k + 1) and oy (k) > oy (k + 1) | ||
and xcoor = ox (k) and (i <= oy (k) and i >= oy (k + 1)) then | ||
put i, " " .. | ||
done := true | ||
elsif oy (k) = oy (k + 1) and ox (k) < ox (k + 1) | ||
and xcoor >= ox (k) and xcoor <= ox (k + 1) and i = oy (k) | ||
then | ||
put i, " " .. | ||
done := true | ||
elsif oy (k) = oy (k + 1) and ox (k) > ox (k + 1) | ||
and xcoor <= ox (k) and xcoor >= ox (k + 1) and i = oy (k) | ||
then | ||
put i, " " .. | ||
done := true | ||
end if | ||
k := k + 1 | ||
end loop | ||
end for | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// CCC 2004 | ||
// Problem S1 Fix | ||
// | ||
// given a series of 3 words, determine if any are prefixes or suffixes | ||
// of each other. | ||
// | ||
// simple ifs of all combos and built-in string functions do the trick. | ||
|
||
import java.awt.*; | ||
import hsa.*; | ||
|
||
public class S1Fix | ||
{ | ||
static Console c; | ||
|
||
|
||
public static void main (String[] args) | ||
{ | ||
c = new Console (); | ||
String file; | ||
int n; | ||
String[] word = new String [3]; | ||
|
||
c.print ("file name: "); | ||
file = c.readString (); | ||
TextInputFile fi = new TextInputFile (file); | ||
|
||
n = fi.readInt (); | ||
for (int i = 0 ; i < n ; i++) | ||
{ | ||
for (int j = 0 ; j < 3 ; j++) | ||
word [j] = fi.readLine (); | ||
if (word [0].startsWith (word [1]) || | ||
word [0].startsWith (word [2]) || | ||
word [1].startsWith (word [2]) || | ||
word [1].startsWith (word [0]) || | ||
word [2].startsWith (word [0]) || | ||
word [2].startsWith (word [1]) || | ||
word [0].endsWith (word [1]) || | ||
word [0].endsWith (word [2]) || | ||
word [1].endsWith (word [2]) || | ||
word [1].endsWith (word [0]) || | ||
word [2].endsWith (word [0]) || | ||
word [2].endsWith (word [1])) | ||
c.println ("NO"); | ||
else | ||
c.println ("YES"); | ||
|
||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// CCC 2004 | ||
// Problem S2 TopYodeller | ||
// | ||
// given multiple series of integers, maintain cummulative totals, | ||
// rankings and worse ranking. | ||
// | ||
// simple 1D integer arrays handle this | ||
|
||
import java.awt.*; | ||
import hsa.*; | ||
|
||
public class S2TopYodeller | ||
{ | ||
static Console c; | ||
|
||
public static void main (String[] args) | ||
{ | ||
c = new Console (); | ||
String file; | ||
int n, k; | ||
int[] y = new int [100]; | ||
int[] r = new int [100]; | ||
int[] w = new int [100]; | ||
|
||
c.print ("file name: "); | ||
file = c.readString (); | ||
TextInputFile fi = new TextInputFile (file); | ||
|
||
n = fi.readInt (); | ||
k = fi.readInt (); | ||
|
||
for (int i = 0 ; i < n ; i++) | ||
{ | ||
y [i] = 0; | ||
w [i] = 1; | ||
} | ||
|
||
for (int i = 0 ; i < k ; i++) | ||
{ | ||
for (int j = 0 ; j < n ; j++) | ||
y [j] = y [j] + fi.readInt (); | ||
for (int j = 0 ; j < n ; j++) | ||
{ | ||
int t = 1; | ||
for (int p = 0 ; p < n ; p++) | ||
if (p != j && y [p] > y [j]) | ||
t++; | ||
if (t > w [j]) | ||
w [j] = t; | ||
r [j] = t; | ||
} | ||
} | ||
for (int j = 0 ; j < n ; j++) | ||
if (r [j] == 1) | ||
c.println ("Yodeller " + (j + 1) + " is the TopYodeller: score " + y [j] + ", worse rank " + w [j]); | ||
} | ||
} | ||
|
Oops, something went wrong.