Last active
May 17, 2022 19:19
-
-
Save psydvl/e4a636d65b291c01d881a2866747f758 to your computer and use it in GitHub Desktop.
Rewriting python code into pascal
This file contains hidden or 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
def f(s,c,m): | |
if 41<=s<=50: return c%2==m%2 | |
if s>50: return c%2!=m%2 | |
if c==m: return 0 | |
h = [f(s+1,c+1,m),f(s+2,c+1,m),f(s*2,c+1,m)] | |
return any(h) if (c+1)%2 == m%2 else all(h) | |
for s in range (1,41): | |
for m in range (1,7): | |
if f(s,0,m)==1: | |
if m==3: print (s,m) | |
break |
This file contains hidden or 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
//use pascalabc.net compiler here | |
program main; | |
//def f(s,c,m): | |
// if 41<=s<=50: return c%2==m%2 | |
// if s>50: return c%2!=m%2 | |
// if c==m: return 0 | |
// h = [f(s+1,c+1,m),f(s+2,c+1,m),f(s*2,c+1,m)] | |
// | |
// return any(h) if (c+1)%2 == m%2 else all(h) | |
function f(s: integer; c: integer; m: integer): boolean; | |
begin | |
if s in 41..50 then result := (c mod 2) = (m mod 2) | |
else if s > 50 then result := (c mod 2) <> (m mod 2) | |
else if c = m then result := false | |
else | |
begin | |
var h := lst( | |
f(s+1,c+1,m), | |
f(s+2,c+1,m), | |
f(s*2,c+1,m) | |
); | |
result := ((c + 1) mod 2 = m mod 2) ? (true in h) : not (false in h); | |
end; | |
end; | |
//for s in range (1,41): | |
// for m in range (1,7): | |
// if f(s,0,m)==1: | |
// if m==3: print (s,m) | |
// break | |
var | |
s, m: integer; | |
begin | |
for s := 1 to 41 do | |
for m := 1 to 7 do | |
if f(s,0,m) then | |
begin | |
if m = 3 then | |
writeln(s, ' ', m); | |
break; | |
end; | |
end. |
This file contains hidden or 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
//Use Free Pascal compiler aka fpc | |
program main; | |
function any(const b_a: array of boolean): boolean; | |
var b: boolean; | |
begin | |
for b in b_a do | |
if b then | |
exit(true); | |
exit(false); | |
end; | |
function all(const b_a: array of boolean): boolean; | |
var b: boolean; | |
begin | |
for b in b_a do | |
if not b then | |
exit(false); | |
exit(true); | |
end; | |
//def f(s,c,m): | |
// if 41<=s<=50: return c%2==m%2 | |
// if s>50: return c%2!=m%2 | |
// if c==m: return 0 | |
// h = [f(s+1,c+1,m),f(s+2,c+1,m),f(s*2,c+1,m)] | |
// | |
// return any(h) if (c+1)%2 == m%2 else all(h) | |
function f(const s: integer; c: integer; m: integer): boolean; | |
type aob = array of boolean; | |
var | |
h: aob; | |
begin | |
if ((41 <= s) and (s <= 50)) then | |
begin | |
exit(((c mod 2) = (m mod 2))); | |
end; | |
if s > 50 then | |
exit((c mod 2) <> (m mod 2)); | |
if (c = m) then | |
exit(false); | |
//setlength(h,3); | |
//h[0] := f(s+1,c+1,m); | |
//h[1] := f(s+2,c+1,m); | |
//h[2] := f(s*2,c+1,m); | |
h := aob.create(f(s+1,c+1,m),f(s+2,c+1,m),f(s*2,c+1,m)); | |
if ((c + 1) mod 2 = m mod 2) then | |
exit(any(h)) | |
else | |
exit(all(h)); | |
end; | |
//for s in range (1,41): | |
// for m in range (1,7): | |
// if f(s,0,m)==1: | |
// if m==3: print (s,m) | |
// break | |
var | |
s, m: integer; | |
begin | |
for s := 1 to 41 do | |
for m := 1 to 7 do | |
if f(s,0,m) then | |
begin | |
if m = 3 then | |
writeln(s, ' ', m); | |
break; | |
end; | |
end. |
This file contains hidden or 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
//use pascalabc.net compiler here | |
program main; | |
//def f(s,c,m): | |
// if 41<=s<=50: return c%2==m%2 | |
// if s>50: return c%2!=m%2 | |
// if c==m: return 0 | |
// h = [f(s+1,c+1,m),f(s+2,c+1,m),f(s*2,c+1,m)] | |
// | |
// return any(h) if (c+1)%2 == m%2 else all(h) | |
function f(const s: integer; c: integer; m: integer): boolean; | |
begin | |
if ((41 <= s) and (s <= 50)) then | |
begin | |
result := (c mod 2) = (m mod 2); | |
exit; | |
end; | |
if s > 50 then | |
begin | |
result := (c mod 2) <> (m mod 2); | |
exit; | |
end; | |
if (c = m) then | |
begin | |
result := false; | |
exit; | |
end; | |
// using array | |
// var h: array of boolean; | |
// setlength(h,3); | |
// h[0] := f(s+1,c+1,m); | |
// h[1] := f(s+2,c+1,m); | |
// h[2] := f(s*2,c+1,m); | |
// using array | |
// var h := new boolean[3] ( | |
// f(s+1,c+1,m), | |
// f(s+2,c+1,m), | |
// f(s*2,c+1,m) | |
// ); | |
// using set | |
// var h := [ | |
// f(s+1,c+1,m), | |
// f(s+2,c+1,m), | |
// f(s*2,c+1,m) | |
// ]; | |
// using set | |
// var h: set of boolean; | |
// include(h,f(s+1,c+1,m)); | |
// include(h,f(s+2,c+1,m)); | |
// include(h,f(s*2,c+1,m)); | |
// using set | |
// var h: set of boolean; | |
// h += [f(s+1,c+1,m)]; | |
// h += [f(s+2,c+1,m)]; | |
// h += [f(s*2,c+1,m)]; | |
// using set | |
// var h := [ | |
// f(s+1,c+1,m), | |
// f(s+2,c+1,m), | |
// f(s*2,c+1,m) | |
// ]; | |
// using list | |
// var h := new list<boolean>; | |
// h.add(f(s+1,c+1,m)); | |
// h.add(f(s+2,c+1,m)); | |
// h.add(f(s*2,c+1,m)); | |
// using list | |
// var h: list<boolean>; | |
// h := lst( | |
// f(s+1,c+1,m), | |
// f(s+2,c+1,m), | |
// f(s*2,c+1,m) | |
// ); | |
using list | |
var h := lst( | |
f(s+1,c+1,m), | |
f(s+2,c+1,m), | |
f(s*2,c+1,m) | |
); | |
if ((c + 1) mod 2 = m mod 2) then | |
result := h.any(x -> x) // not works for sets | |
// result := (true in h) | |
else | |
result := h.all(x -> x); // not works for sets | |
// result := not (false in h); | |
end; | |
//for s in range (1,41): | |
// for m in range (1,7): | |
// if f(s,0,m)==1: | |
// if m==3: print (s,m) | |
// break | |
var | |
s, m: integer; | |
begin | |
for s := 1 to 41 do | |
for m := 1 to 7 do | |
if f(s,0,m) then | |
begin | |
if m = 3 then | |
writeln(s, ' ', m); | |
break; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment