Tight programming exercise, using bad programming practices
- Posted by fizzpopsoft Jun 18, 2015
- 2805 views
A friend who is studying, was asked to create pseudo-code for the following problem:
- Your algorithm should:
o Search a string of at least five numbers (for example, 37540)
o Identify all of the substrings that form numbers that are divisible by 3.
o For example, applying the algorithm on the string 37540 should produce the
following substrings (not necessarily in this order): 0; 3; 75; 54; 375; 540.
OK, did that for him, but just for the heck of it, I also provided the following code,
as an example of a few bad programming practices to see how small I could make it,
while still being mostly legible.
Other than making the two value related statements into one, can anyone make it smaller?
procedure tiny() sequence s1,s2,s3="37540" atom a1 integer i1,i2=0 while i2<5 do i2=i2+1 i1=i2-1 while i1<5 do i1=i1+1 s1=s3[i2..i1] s2=value(s1) a1=s2[2] if floor(a1/3)=(a1/3) then puts(1,s1&", ") end if end while end while end procedure tiny()