omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / qualification / security673 / game / solve.om
| 1 | note SC1-G-v3 synchronous greatest fixed point over monitored raw transitions. |
| 2 | global moves uint 2593 |
| 3 | global cert uint 2593 |
| 4 | global chosen uint 2593 |
| 5 | global edges uint 420066 |
| 6 | global keep uchar 2593 |
| 7 | global next uchar 2593 |
| 8 | global mut uint 1 |
| 9 | global totals ulong 4 |
| 10 | fn phase s uint c uint to uint |
| 11 | if eq c 0 |
| 12 | ret rem s 18 |
| 13 | end |
| 14 | ret rem div s 18 18 |
| 15 | end |
| 16 | fn replace s uint c uint p uint to uint |
| 17 | old = phase s c |
| 18 | if eq c 0 |
| 19 | ret add sub s old p |
| 20 | end |
| 21 | ret add sub s mul old 18 mul p 18 |
| 22 | end |
| 23 | fn epoch s uint to uint |
| 24 | ret rem div s 324 2 |
| 25 | end |
| 26 | fn object s uint to uint |
| 27 | ret rem div s 648 2 |
| 28 | end |
| 29 | fn charge p uint to uint |
| 30 | if lt p 2 |
| 31 | ret 0 |
| 32 | end |
| 33 | if and ge p 12 le p 14 |
| 34 | ret 1 |
| 35 | end |
| 36 | ret 2 |
| 37 | end |
| 38 | fn invariant s uint to bool |
| 39 | if ge s 2592 |
| 40 | ret false |
| 41 | end |
| 42 | a = phase s 0 |
| 43 | b = phase s 1 |
| 44 | if or eq a 17 eq b 17 |
| 45 | ret false |
| 46 | end |
| 47 | if gt add charge a charge b 3 |
| 48 | ret false |
| 49 | end |
| 50 | if or or eq a 15 eq a 16 or eq b 15 eq b 16 |
| 51 | ret eq rem div s 324 4 0 |
| 52 | end |
| 53 | ret true |
| 54 | end |
| 55 | fn enabled s uint u uint to bool |
| 56 | if not invariant s |
| 57 | ret false |
| 58 | end |
| 59 | if ge s 1296 |
| 60 | ret eq u 1 |
| 61 | end |
| 62 | if eq u 1 |
| 63 | ret false |
| 64 | end |
| 65 | if eq u 0 |
| 66 | ret and or eq phase s 0 0 eq phase s 0 14 or eq phase s 1 0 eq phase s 1 14 |
| 67 | end |
| 68 | c = div sub u 2 8 |
| 69 | k = rem sub u 2 8 |
| 70 | p = phase s c |
| 71 | if eq k 0 |
| 72 | ret and eq p 1 le add charge phase s 0 charge phase s 1 1 |
| 73 | end |
| 74 | if eq k 1 |
| 75 | ret and ge p 1 le p 10 |
| 76 | end |
| 77 | if eq k 2 |
| 78 | ret eq p 2 |
| 79 | end |
| 80 | if or eq k 3 eq k 7 |
| 81 | if and ge p 3 le p 6 |
| 82 | if eq k 7 |
| 83 | ret eq rem div s 324 4 0 |
| 84 | end |
| 85 | ret true |
| 86 | end |
| 87 | ret and eq k 7 eq p 16 |
| 88 | end |
| 89 | if eq k 4 |
| 90 | ret or and ge p 7 le p 10 eq p 15 |
| 91 | end |
| 92 | if eq k 5 |
| 93 | ret or eq p 11 eq p 15 |
| 94 | end |
| 95 | ret or eq p 12 eq p 13 |
| 96 | end |
| 97 | fn environment s uint d uint to uint |
| 98 | if eq d 1 |
| 99 | if eq phase s 0 0 |
| 100 | ret add s 1 |
| 101 | end |
| 102 | end |
| 103 | if eq d 2 |
| 104 | if eq phase s 1 0 |
| 105 | ret add s 18 |
| 106 | end |
| 107 | end |
| 108 | if eq d 3 |
| 109 | ret add s mul sub uint 1 epoch s 324 |
| 110 | end |
| 111 | if eq d 4 |
| 112 | ret add s mul sub uint 1 object s 648 |
| 113 | end |
| 114 | ret s |
| 115 | end |
| 116 | fn clean p uint to uint |
| 117 | if and ge p 2 le p 10 |
| 118 | ret 0 |
| 119 | end |
| 120 | if eq p 11 |
| 121 | ret 12 |
| 122 | end |
| 123 | ret p |
| 124 | end |
| 125 | fn recover s uint to uint |
| 126 | if or ge phase s 0 15 ge phase s 1 15 |
| 127 | ret 2592 |
| 128 | end |
| 129 | s = replace s 0 clean phase s 0 |
| 130 | s = replace s 1 clean phase s 1 |
| 131 | ret rem s 1296 |
| 132 | end |
| 133 | fn split s uint c uint k uint d uint to uint |
| 134 | p = phase s c |
| 135 | if eq d 7 |
| 136 | ret s |
| 137 | end |
| 138 | if eq d 5 |
| 139 | ret add replace s c 0 1296 |
| 140 | end |
| 141 | if eq p 15 |
| 142 | if or and eq k 4 eq d 4 and eq k 5 eq d 3 |
| 143 | ret 2592 |
| 144 | end |
| 145 | if or eq d 3 eq d 4 |
| 146 | ret environment replace s c 0 d |
| 147 | end |
| 148 | if eq d 6 |
| 149 | ret s |
| 150 | end |
| 151 | ret environment replace s c 14 d |
| 152 | end |
| 153 | if or eq d 3 eq d 4 |
| 154 | ret environment replace s c 0 d |
| 155 | end |
| 156 | ret environment replace s c 15 d |
| 157 | end |
| 158 | fn client s uint c uint k uint d uint to uint |
| 159 | p = phase s c |
| 160 | if eq k 0 |
| 161 | ret replace s c 2 |
| 162 | end |
| 163 | if eq k 1 |
| 164 | ret replace s c 0 |
| 165 | end |
| 166 | if eq k 2 |
| 167 | p = add uint 3 add epoch s mul object s 2 |
| 168 | ret replace s c p |
| 169 | end |
| 170 | if eq k 3 |
| 171 | if eq d 6 |
| 172 | ret s |
| 173 | end |
| 174 | ret replace s c add p 4 |
| 175 | end |
| 176 | if eq k 4 |
| 177 | tag = sub p 7 |
| 178 | if ne get mut 0 3 |
| 179 | if ne tag rem div s 324 4 |
| 180 | ret s |
| 181 | end |
| 182 | end |
| 183 | ret replace s c 11 |
| 184 | end |
| 185 | if eq k 5 |
| 186 | if eq d 6 |
| 187 | if eq get mut 0 4 |
| 188 | ret replace s c 17 |
| 189 | end |
| 190 | ret s |
| 191 | end |
| 192 | if eq d 8 |
| 193 | ret replace s c 13 |
| 194 | end |
| 195 | ret replace s c 12 |
| 196 | end |
| 197 | if eq k 6 |
| 198 | if eq d 8 |
| 199 | ret replace s c 13 |
| 200 | end |
| 201 | ret replace s c 14 |
| 202 | end |
| 203 | if ne rem div s 324 4 0 |
| 204 | ret s |
| 205 | end |
| 206 | ret replace s c 16 |
| 207 | end |
| 208 | fn step s uint u uint d uint to uint |
| 209 | if not enabled s u |
| 210 | ret 2592 |
| 211 | end |
| 212 | if ge u 2 |
| 213 | c = div sub u 2 8 |
| 214 | p = phase s c |
| 215 | if or eq p 15 eq p 16 |
| 216 | if lt s 1296 |
| 217 | ret split s c rem sub u 2 8 d |
| 218 | end |
| 219 | end |
| 220 | end |
| 221 | if eq d 5 |
| 222 | ret add rem s 1296 1296 |
| 223 | end |
| 224 | if eq d 7 |
| 225 | ret s |
| 226 | end |
| 227 | s = environment s d |
| 228 | if eq u 0 |
| 229 | ret s |
| 230 | end |
| 231 | if eq u 1 |
| 232 | ret recover s |
| 233 | end |
| 234 | ret client s div sub u 2 8 rem sub u 2 8 d |
| 235 | end |
| 236 | fn index s uint u uint d uint to uint |
| 237 | ret add mul add mul s 18 u 9 d |
| 238 | end |
| 239 | fn monitored s uint u uint d uint raw uint to uint |
| 240 | if or lt u 2 ge raw 2592 |
| 241 | ret raw |
| 242 | end |
| 243 | c = div sub u 2 8 |
| 244 | p = phase s c |
| 245 | q = phase raw c |
| 246 | if and eq p 11 eq q 17 |
| 247 | ret 2592 |
| 248 | end |
| 249 | if and eq rem sub u 2 8 4 eq q 11 |
| 250 | if and ge p 7 le p 10 |
| 251 | now = environment s d |
| 252 | if ne sub p 7 rem div now 324 4 |
| 253 | ret 2592 |
| 254 | end |
| 255 | end |
| 256 | end |
| 257 | ret raw |
| 258 | end |
| 259 | fn destination s uint u uint d uint to uint |
| 260 | ret monitored s u d get edges index s u d |
| 261 | end |
| 262 | fn construct to void |
| 263 | for i uint 4 |
| 264 | put totals i 0 |
| 265 | end |
| 266 | for s uint 2593 |
| 267 | put keep s 0 |
| 268 | if invariant s |
| 269 | put keep s 1 |
| 270 | end |
| 271 | m = uint 0 |
| 272 | for u uint 18 |
| 273 | if enabled s u |
| 274 | m = or m shl uint 1 u |
| 275 | for d uint 9 |
| 276 | put edges index s u d step s u d |
| 277 | put totals 0 add get totals 0 1 |
| 278 | end |
| 279 | end |
| 280 | end |
| 281 | put moves s m |
| 282 | end |
| 283 | end |
| 284 | fn safe s uint u uint to bool |
| 285 | if eq and get moves s shl uint 1 u 0 |
| 286 | ret false |
| 287 | end |
| 288 | for d uint 9 |
| 289 | if not and eq get mut 0 2 eq d 4 |
| 290 | if eq get keep destination s u d 0 |
| 291 | ret false |
| 292 | end |
| 293 | end |
| 294 | end |
| 295 | ret true |
| 296 | end |
| 297 | fn existsaction s uint to bool |
| 298 | for u uint 18 |
| 299 | if safe s u |
| 300 | ret true |
| 301 | end |
| 302 | end |
| 303 | ret false |
| 304 | end |
| 305 | fn swapped s uint to bool |
| 306 | for d uint 9 |
| 307 | found = false |
| 308 | for u uint 18 |
| 309 | if ne and get moves s shl uint 1 u 0 |
| 310 | if ne get keep destination s u d 0 |
| 311 | found = true |
| 312 | end |
| 313 | end |
| 314 | end |
| 315 | if not found |
| 316 | ret false |
| 317 | end |
| 318 | end |
| 319 | ret true |
| 320 | end |
| 321 | fn solve to void |
| 322 | changed = true |
| 323 | while changed bound 2594 |
| 324 | changed = false |
| 325 | put totals 1 add get totals 1 1 |
| 326 | for s uint 2593 |
| 327 | v = false |
| 328 | if ne get keep s 0 |
| 329 | if eq get mut 0 1 |
| 330 | v = swapped s |
| 331 | else |
| 332 | v = existsaction s |
| 333 | end |
| 334 | end |
| 335 | put next s 0 |
| 336 | if v |
| 337 | put next s 1 |
| 338 | end |
| 339 | if ne get next s get keep s |
| 340 | changed = true |
| 341 | end |
| 342 | end |
| 343 | for s uint 2593 |
| 344 | put keep s get next s |
| 345 | end |
| 346 | if eq get mut 0 6 |
| 347 | ret |
| 348 | end |
| 349 | end |
| 350 | end |
| 351 | fn certificate to void |
| 352 | for s uint 2593 |
| 353 | m = uint 0 |
| 354 | if ne get keep s 0 |
| 355 | put totals 2 add get totals 2 1 |
| 356 | for u uint 18 |
| 357 | if safe s u |
| 358 | m = or m shl uint 1 u |
| 359 | end |
| 360 | end |
| 361 | if or eq get mut 0 1 eq get mut 0 6 |
| 362 | if eq m 0 |
| 363 | m = get moves s |
| 364 | end |
| 365 | end |
| 366 | end |
| 367 | put cert s m |
| 368 | end |
| 369 | end |
| 370 | fn select s uint identity uint to uint |
| 371 | if ne identity 1 |
| 372 | ret 18 |
| 373 | end |
| 374 | m = get cert s |
| 375 | if eq m 0 |
| 376 | ret 18 |
| 377 | end |
| 378 | if eq get mut 0 5 |
| 379 | m = get moves s |
| 380 | end |
| 381 | best = uint 18 |
| 382 | price = uint 99 |
| 383 | for u uint 18 |
| 384 | if ne and m shl uint 1 u 0 |
| 385 | p = uint 2 |
| 386 | if lt u 2 |
| 387 | p = 1 |
| 388 | else |
| 389 | k = rem sub u 2 8 |
| 390 | if eq k 7 |
| 391 | p = 0 |
| 392 | end |
| 393 | if eq k 1 |
| 394 | p = 4 |
| 395 | end |
| 396 | end |
| 397 | if lt p price |
| 398 | price = p |
| 399 | best = u |
| 400 | end |
| 401 | end |
| 402 | end |
| 403 | ret best |
| 404 | end |
| 405 | fn selections to void |
| 406 | for s uint 2593 |
| 407 | put chosen s select s 1 |
| 408 | end |
| 409 | end |
| 410 | fn output to void |
| 411 | sendword 1396912455 |
| 412 | sendword 3 |
| 413 | sendword 2593 |
| 414 | sendword get mut 0 |
| 415 | for s uint 2593 |
| 416 | sendword get moves s |
| 417 | sendword get cert s |
| 418 | sendword get chosen s |
| 419 | for u uint 18 |
| 420 | if ne and get moves s shl uint 1 u 0 |
| 421 | for d uint 9 |
| 422 | sendword get edges index s u d |
| 423 | end |
| 424 | end |
| 425 | end |
| 426 | end |
| 427 | flush |
| 428 | end |
| 429 | fn benchmark to void |
| 430 | if ne get mut 0 0 |
| 431 | exit 90 |
| 432 | end |
| 433 | for i ulong 101 |
| 434 | start = monons |
| 435 | construct |
| 436 | solve |
| 437 | certificate |
| 438 | selections |
| 439 | put samples i ulong sub monons start |
| 440 | end |
| 441 | percentiles |
| 442 | end |
| 443 | fn main to int |
| 444 | put mut 0 fault |
| 445 | m = mode |
| 446 | if eq m 7 |
| 447 | benchmark |
| 448 | output |
| 449 | ret 0 |
| 450 | end |
| 451 | if or ne m 0 gt get mut 0 6 |
| 452 | ret 90 |
| 453 | end |
| 454 | start = monons |
| 455 | construct |
| 456 | label 0 |
| 457 | number ulong sub monons start |
| 458 | start = monons |
| 459 | solve |
| 460 | certificate |
| 461 | selections |
| 462 | label 1 |
| 463 | number ulong sub monons start |
| 464 | label 3 |
| 465 | number 2593 |
| 466 | label 4 |
| 467 | number get totals 0 |
| 468 | label 5 |
| 469 | number get totals 2 |
| 470 | label 6 |
| 471 | number get totals 1 |
| 472 | label 7 |
| 473 | number 1721554 |
| 474 | output |
| 475 | ret 0 |
| 476 | end |