started at ; stage 2 at ; ended at
hey, hey! your challenge this round is to simulate bingo. submissions may be written in raku, zig, go, d or haskell.
the rules of (american) bingo are simple. a series of numbers from 1-75 are called out. after each number is called, all players mark that number, if present, on their bingo cards. the first person to mark 5 cells in a vertical, horizontal or diagonal line on their card wins the round.
your program, given a list of bingo cards as 5x5 grids, and a series of numbers, shall return the index of the card which wins the round by being the first to form a line.
for example, consider the following 2 cards, represented here as ASCII art:
67 64 11 28 16
63 26 20 15 10
68 44 00 53 70
22 56 38 51 09
47 33 17 39 59
51 24 53 70 62
54 44 57 72 35
32 05 00 20 38
36 04 73 29 69
63 42 07 08 58
with the sequence [0, 72, 3, 8, 59, 66, 61, 58, 23, 14, 16, 42, 10, 17, 2, 48, 44, 26, 70, 21, 31, 19, 9]
,
the first of the two cards will win, as the final 9
forms a line on the rightmost column. your program should return 0
given this input.
additional input invariants:
0
, as will be the centre space of all of the cards. this emulates the "free space" from the real game.and now the APIs:
pub fn entry(cards: [][5][5]u7, calls: []u7) usize
func Entry(cards [][5][5]uint8, calls []uint8) uint
public size_t entry(ubyte[5][5][] cards, ubyte[] calls)
entry :: [[[Int]]] -> [Int] -> Int
you can download all the entries
written by vintium
5 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | const std = @import("std"); const stdout = std.io.getStdOut().writer(); const assert = std.debug.assert; // positions start in the top left corner of the card, // counting from zero. x increases rightwards, y increases leftwards. // x and y must be in the range [0, 4]. const Pos = struct { x: u3, y: u3, }; const Card = struct { c: [5][5]u7, fn find(self: Card, needle: u7) ?Pos { for (self.c) |row, y| { for (row) |number, x| { if (number == needle) { return Pos{ .x = @intCast(u3, x), .y = @intCast(u3, y) }; } } } return null; } test "find a number in a card" { // zig fmt: off const c = Card{ .c = [5][5]u7{ [_]u7{ 67, 64, 11, 28, 16 }, [_]u7{ 63, 26, 20, 15, 10 }, [_]u7{ 68, 44, 00, 53, 70 }, // <- 70 is here at (4, 2) [_]u7{ 22, 56, 38, 51, 09 }, [_]u7{ 47, 33, 17, 39, 59 } }, }; // zig fmt: on try std.testing.expectEqual(c.find(70), Pos{ .x = 4, .y = 2 }); } test "don't find a number in a card" { // zig fmt: off const c = Card{ .c = [5][5]u7{ [_]u7{ 67, 64, 11, 28, 16 }, [_]u7{ 63, 26, 20, 15, 10 }, [_]u7{ 68, 44, 00, 53, 70 }, // 69 is not in this card [_]u7{ 22, 56, 38, 51, 09 }, [_]u7{ 47, 33, 17, 39, 59 } }, }; // zig fmt: on try std.testing.expectEqual(c.find(69), null); } }; const Marks = struct { msk: u25, // bit mask storing marked positions. the lowest bit is 0, 0, the highest bit is at 4, 4. // mapping diagram: // 0b_00000_00000_00000_00000_00000 // y: 44444 33333 22222 11111 00000 // x: 43210 43210 43210 43210 43210 // set the bit at the mapped position to 1 fn mark(self: *Marks, x: u3, y: u3) void { assert(x <= 4 and y <= 4); self.msk |= (@as(u25, 1) << (@as(u5, x) + @as(u5, y) * @as(u5, 5))); } // wrapper to use the `Pos` struct. tests depend on passing in x, y as args, so the original // function wasn't changed. fn markPos(self: *Marks, p: Pos) void { self.mark(p.x, p.y); } fn row(self: Marks) bool { // zig fmt: off const rows = [5]u25{ 0b00000_00000_00000_00000_11111, 0b00000_00000_00000_11111_00000, 0b00000_00000_11111_00000_00000, 0b00000_11111_00000_00000_00000, 0b11111_00000_00000_00000_00000 }; // zig fmt: on var match = false; for (rows) |r| { match = ((r & self.msk) == r) or match; } return match; } test "detect five-in-a-row" { var m = Marks{ .msk = 0 }; // O O O O O // O O O O O // O O O O O // X X X X X // O O O O O m.mark(0, 3); m.mark(1, 3); m.mark(2, 3); m.mark(3, 3); m.mark(4, 3); try std.testing.expectEqual(m.row(), true); try std.testing.expectEqual(m.wins(), true); } test "noisy row" { var m = Marks{ .msk = 0 }; // X X O O O // O O O O O // O O O O O // X X X X X // O X O O O m.mark(0, 3); m.mark(1, 0); m.mark(1, 3); m.mark(2, 3); m.mark(3, 3); m.mark(4, 3); m.mark(0, 0); m.mark(1, 0); m.mark(1, 4); try std.testing.expectEqual(m.row(), true); try std.testing.expectEqual(m.wins(), true); } fn col(self: Marks) bool { // zig fmt: off const cols = [5]u25{ 0b00001_00001_00001_00001_00001, 0b00010_00010_00010_00010_00010, 0b00100_00100_00100_00100_00100, 0b01000_01000_01000_01000_01000, 0b10000_10000_10000_10000_10000 }; // zig fmt: on var match = false; for (cols) |c| { match = ((c & self.msk) == c) or match; } return match; } test "detect five-in-a-col" { var m = Marks{ .msk = 0 }; // O O X O O // O O X O O // O O X O O // O O X O O // O O X O O m.mark(2, 0); m.mark(2, 1); m.mark(2, 2); m.mark(2, 3); m.mark(2, 4); try std.testing.expectEqual(m.col(), true); try std.testing.expectEqual(m.wins(), true); } test "noisy col" { var m = Marks{ .msk = 0 }; // X O X O O // O O X O O // O O X O X // O O X O O // O O X O O m.mark(2, 0); m.mark(2, 1); m.mark(2, 2); m.mark(2, 3); m.mark(2, 4); m.mark(4, 2); m.mark(0, 0); try std.testing.expectEqual(m.col(), true); try std.testing.expectEqual(m.wins(), true); } fn diag(self: Marks) bool { // zig fmt: off const diags = [2]u25{ 0b00001_00010_00100_01000_10000, 0b10000_01000_00100_00010_00001, }; // zig fmt: on var match = false; for (diags) |d| { match = ((d & self.msk) == d) or match; } return match; } test "detect diagonal" { var m = Marks{ .msk = 0 }; // X O O O O // O X O O O // O O X O O // O O O X O // O O O O X m.mark(0, 0); m.mark(1, 1); m.mark(2, 2); m.mark(3, 3); m.mark(4, 4); try std.testing.expectEqual(m.diag(), true); try std.testing.expectEqual(m.wins(), true); } test "noisy diag" { var m = Marks{ .msk = 0 }; // X O O O X // O X O O O // O O X O O // O O X X O // O O X O X m.mark(0, 0); m.mark(1, 1); m.mark(2, 2); m.mark(2, 3); m.mark(3, 3); m.mark(4, 4); m.mark(2, 4); m.mark(4, 0); try std.testing.expectEqual(m.diag(), true); try std.testing.expectEqual(m.wins(), true); } fn wins(self: Marks) bool { return self.row() or self.col() or self.diag(); } test "loses 1" { var m = Marks{ .msk = 0 }; // X O O X O // O O O X O // O O X O O // O O X O O // O O X O X m.mark(0, 0); m.mark(3, 1); m.mark(2, 2); m.mark(2, 3); m.mark(3, 0); m.mark(4, 4); m.mark(2, 4); try std.testing.expectEqual(m.wins(), false); } test "loses 2" { var m = Marks{ .msk = 0 }; // X O O X O // O X O X O // X O X O X // O X O O O // O O X O X m.mark(0, 0); m.mark(3, 0); m.mark(1, 1); m.mark(3, 1); m.mark(0, 2); m.mark(2, 2); m.mark(4, 2); m.mark(1, 3); m.mark(4, 4); m.mark(2, 4); try std.testing.expectEqual(m.wins(), false); } }; const Player = struct { id: usize, card: Card, marked: Marks, fn play(self: *Player, call: u7) ?usize { if (self.card.find(call)) |p| { self.marked.markPos(p); } if (self.marked.wins()) { return self.id; } else { return null; } } }; test "a test game" { var me = Player{ .id = 0, // zig fmt: off .card = Card{ .c = [5][5]u7{ [_]u7{ 67, 64, 11, 28, 16 }, [_]u7{ 63, 26, 20, 15, 10 }, [_]u7{ 68, 44, 00, 53, 70 }, [_]u7{ 22, 56, 38, 51, 09 }, [_]u7{ 47, 33, 17, 39, 59 }, }, }, // zig fmt: on .marked = Marks{ .msk = 0 }, }; try std.testing.expectEqual(me.play(0), null); try std.testing.expectEqual(me.play(11), null); try std.testing.expectEqual(me.play(38), null); try std.testing.expectEqual(me.play(50), null); try std.testing.expectEqual(me.play(10), null); try std.testing.expectEqual(me.play(17), null); try std.testing.expectEqual(me.play(20), 0); } pub fn entry(cards: []const [5][5]u7, calls: []const u7) usize { for (cards) |crd, i| { var player = Player{ .id = i, .card = Card{ .c = crd }, .marked = Marks{ .msk = 0 }, }; for (calls) |call| { const winnermaybe = player.play(call); if (winnermaybe) |winner| { return winner; } } } unreachable; } test "example in prompt" { var started = try std.time.Instant.now(); var i: usize = 0; while (i < 1000) { // zig fmt: off var calls = &[_]u7{0, 72, 3, 8, 59, 66, 61, 58, 23, 14, 16, 42, 10, 17, 2, 48, 44, 26, 70, 21, 31, 19, 9}; var cards = &[_][5][5]u7{ [5][5]u7{ [5]u7{67, 64, 11, 28, 16}, [5]u7{63, 26, 20, 15, 10}, [5]u7{68, 44, 00, 53, 70}, [5]u7{22, 56, 38, 51, 09}, [5]u7{47, 33, 17, 39, 59}, }, [5][5]u7{ [5]u7{51, 24, 53, 70, 62}, [5]u7{54, 44, 57, 72, 35}, [5]u7{32, 05, 00, 20, 38}, [5]u7{36, 04, 73, 29, 69}, [5]u7{63, 42, 07, 08, 58}, } }; i += 1; try std.testing.expectEqual(entry(cards, calls), 0); } // zig fmt: on var ended = try std.time.Instant.now(); std.debug.print("took: {} ", .{ended.since(started)}); } pub fn main() anyerror!void { std.debug.print("It was as if an occult hand brought you to run this program as an application. It is a library, yet lack of zig expertise gently drew me towards creating a application project.", .{}); } |
written by LyricLy
8 likes
1 | Like a von Neumann ordinal, we could not exist without the help of all those who came before. |
1 | And now, we do it all over again. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import Data.List import Data.Maybe import Glue convertSingle :: Bool -> [[Bool]] convertSingle True = [ [False, True , False] , [True , False, True ] , [False, True , False] ] convertSingle False = [ [False, False, False] , [False, False, False] , [False, False, False] ] diagToOrth :: [[Bool]] -> [[Bool]] diagToOrth = concatMap (map concat . transpose) . map (map convertSingle) canSolve :: [[Bool]] -> Bool canSolve g = isJust res where orth = diagToOrth g res :: Maybe [Int] res = glueCall "r2.go" $ "entry([]bool{" ++ intercalate "," (map (\x -> case x of True -> "true"; False -> "false") . concat $ orth) ++ "}," ++ show (length orth) ++ ")" |
1 2 3 4 5 6 7 8 9 | module Glue (glueCall) where import System.Process import System.IO.Unsafe import J glueCall :: JRead a => String -> String -> a glueCall f e = jReadFull . unsafePerformIO $ readProcess "raku" ["gluebus.raku", f, e] "" {-# NOINLINE glueCall #-} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | {-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-} module J where import Data.List import Data.Maybe import Parsing class JShow a where jShow :: a -> String instance JShow Int where jShow = show instance {-# OVERLAPS #-} JShow String where jShow s = "\"" ++ concatMap (\c -> if c == '"' then "\"" else pure c) s ++ "\"" instance JShow Bool where jShow True = "true" jShow False = "false" instance JShow a => JShow [a] where jShow xs = "[" ++ intercalate "," (map jShow xs) ++ "]" instance JShow a => JShow (Maybe a) where jShow (Just x) = jShow x jShow Nothing = "null" class JRead a where jRead :: Parser a instance JRead Int where jRead = read <$> some digit <* ws instance {-# OVERLAPS #-} JRead String where jRead = char '"' *> many (noneOf ['"', '\\'] <|> '\"' <$ string "\\\"" <|> '\\' <$ string "\\\\" <|> '\n' <$ string "\\\n") <* char '"' <* ws instance JRead Bool where jRead = (True <$ string "true" <|> False <$ string "false") <* ws instance JRead a => JRead [a] where jRead = char '[' *> ws *> (((:) <$> jRead <*> many (char ',' >> ws >> jRead)) <|> return []) <* char ']' <* ws instance JRead a => JRead (Maybe a) where jRead = Nothing <$ string "null" <* ws <|> Just <$> jRead jReadFull :: JRead a => String -> a jReadFull = snd . fromJust . runParser (ws *> jRead <* eof) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | Copyright (c) 2022 pithlessly, LyricLy, IFcoltransG, RocketRace, OliveIsAWord, Παλαιολόγος, Raghu Ranganathan, Oliver Marks, David Rutter, Benjamin Philippe Applegate, Kaylynn, loovjo, dylan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | {-# LANGUAGE TupleSections, LambdaCase #-} module Parsing (Parser, eof, ws, char, string, noneOf, digit, chainl1, (<|>), many, some, optional, runParser) where import Control.Applicative import Control.Monad import Data.Char import Data.Maybe newtype Parser a = Parser { runParser :: String -> Maybe (String, a) } instance Functor Parser where fmap f (Parser g) = Parser (fmap (fmap f) . g) instance Applicative Parser where pure x = Parser (Just . (,x)) (Parser f) <*> (Parser x) = Parser $ \s -> do (s', g) <- f s (s'', y) <- x s' return (s'', g y) instance Alternative Parser where empty = Parser (const Nothing) (Parser x) <|> (Parser y) = Parser $ (<|>) <$> x <*> y instance Monad Parser where (Parser m) >>= f = Parser $ (>>= uncurry (flip (runParser . f))) . m satisfy :: (Char -> Bool) -> Parser Char satisfy f = Parser $ \case (x:xs) | f x -> Just (xs, x) _ -> Nothing eof :: Parser () eof = Parser $ \s -> if null s then Just (s, ()) else Nothing ws :: Parser () ws = void $ many (satisfy isSpace) char :: Char -> Parser Char char = satisfy . (==) string :: String -> Parser String string = foldr (liftA2 (:)) (pure []) . map char noneOf :: [Char] -> Parser Char noneOf = satisfy . (not .) . flip elem digit :: Parser Char digit = satisfy isDigit chainl1 :: Parser a -> Parser (a -> a -> a) -> Parser a chainl1 p op = p >>= go where go x = (do f <- op y <- p go (f x y) ) <|> return x |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | const std = @import("std"); const glue = @import("glue.zig"); const byte = u7; pub fn entry(flat_cards: []const u7, calls: []const u7) usize { const cards: []const [5][5]u7 = @ptrCast([*]const [5][5]u7, flat_cards.ptr)[0..flat_cards.len/25]; var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); const allocator = arena.allocator(); for (cards) |card, i| { blk: { const file = std.fs.cwd().createFile("progress", .{.truncate = false}) catch break :blk; defer file.close(); file.writer().print("{:0>2}/{:0>2}\n", .{i, cards.len}) catch {}; } // not doing this formatting shit again var out = std.fmt.allocPrint(allocator, "hasWon({any}, {any})", .{card, calls}) catch unreachable; for (out) |x, j| { out[j] = switch (x) { '{' => '[', '}' => ']', else => x, }; } if (glue.glueCall(bool, "haswon.d", out, allocator)) { return i; } } unreachable; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import std.string; import std.process; import std.conv; import std.json; import std.range; import std.algorithm; import std.typecons; import std.traits; string passSliceToZig(T)(T[] a, string type) { return format("%s{%s}", type, to!(char[])(a)[1..$-1]); } // the `get` method on JSONValue doesn't support nested array types or nullables T getJSON(T)(JSONValue v) { static if (is(typeof(v.get!T()))) { return v.get!T(); } else static if (is(typeof(getJSON!(ElementType!(T))(v)))) { return array(v.get!(JSONValue[])().map!(x => getJSON!(ElementType!(T))(x))); } else static if (__traits(isSame, TemplateOf!T, Nullable) && is(typeof(getJSON!(TemplateArgsOf!T[0])(v)))) { T x; if (v.isNull) x.nullify(); else x = T(getJSON!(TemplateArgsOf!T[0])(v)); return x; } } T glueCall(T)(string file, string expr) { auto r = execute(["raku", "gluebus.raku", file, expr]); try { return getJSON!T(parseJSON(r.output)); } catch (JSONException e) { import std.stdio; writeln(r.output); return getJSON!T(parseJSON(r.output)); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | package main import ( "os/exec" "encoding/json" ) func GlueCall[T any](file string, expr string) T { out, _ := exec.Command("raku", "gluebus.raku", file, expr).Output() var r T json.Unmarshal(out, &r) return r } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | const std = @import("std"); pub fn glueCall(comptime T: type, file: []const u8, expr: []const u8, allocator: std.mem.Allocator) T { const result = std.ChildProcess.exec(.{ .allocator = allocator, .argv = &.{"raku", "gluebus.raku", file, expr}, }) catch unreachable; defer { allocator.free(result.stdout); allocator.free(result.stderr); } return std.json.parse(T, &std.json.TokenStream.init(result.stdout), .{ .allocator = allocator }) catch unreachable; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | sub shell_out($filename, $expr) { my $contents = slurp $filename; my $target = "tmp_" ~ $filename; my $output; my $cmd; given $filename { when /go$/ { $output = qq:to/END/; import ( _fmt "fmt" _json "encoding/json" ) $contents func main() \{ s, _ := _json.Marshal($expr) _fmt.Print(string(s)) } END unless $output ~~ /package\s+main/ { $output = "package main\n$output" } $cmd = "go run $target glue.go r5.go"; } when /hs$/ { $output = qq:to/END/; import J $contents main = putStr (jShow ($expr)) END $cmd = "runghc $target"; } when /zig$/ { $output = qq:to/END/; $contents pub fn main() !void \{ const stdout = std.io.getStdOut().writer(); try std.json.stringify(($expr), .\{}, stdout); } END $cmd = "zig run $target --library z --library c"; } when /(\w+).d$/ { $output = qq:to/END/; import std.json; import std.stdio; $contents void main() \{ write(JSONValue($expr).toString); } END $cmd = "dmd $target glue.d && ./tmp_$0; rm -f tmp_$0*"; } when /.c$/ { # omg hi are you kamila szewczyk # im a huge fan can i have your autograph $output = $contents ~ q:to/END/.subst(/102362929/, $expr); /* \/\/\/\/\/ - Code for judges - \/\/\/\/\/ */ int main() { int dest; long * vec = _$$$$$(102362929, &dest); // small modification for JSON if(dest == 0) { printf("[]"); return 0; } printf("[%ld", vec[0]); for(int _$$ = 1; _$$ < dest; _$$++) printf(",%ld", vec[_$$]); printf("]"); } END # it's Zig not C ;) $cmd = "zig cc $target && ./a.out; rm -f a.out"; # zig cc doesn't actually compile the program properly. $cmd ~~ s:s/zig cc/gcc/; } } spurt $target, $output; my $proc = shell $cmd, :out; LEAVE unlink $target; $proc.out.slurp } sub aggressive_assert($cond) { $cond or shell "shutdown 0" } sub MAIN($filename, $expr) { my $output = shell_out($filename, $expr); my $valid_json = shell_out("r7.d", "entry(`$output`)"); aggressive_assert($valid_json eq "true"); say $output } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import std.process; import std.file; import std.conv; import std.format; import std.typecons; import glue; bool hasWon(ubyte[5][5] grid, ubyte[] called) { if (!"pad".exists) { executeShell("zig build-exe r13.zig --library c --library z && ./r13 -c pad.b pad"); } // :) std.file.write(".input", to!string(grid)); auto output = executeShell("cat .input | ./r13 -r pad").output; bool[25] bools; foreach (n; called) { auto index = glueCall!(Nullable!size_t)("r8.hs", format(`entry "%02d" "%s"`, n, output)); if (!index.isNull) { bools[index.get()/3] = true; } } return glueCall!bool("is_line.zig", format("isLine(%s)", passSliceToZig(bools, "."))); } |
1 2 3 4 5 | package hello func hello() string { return "Hello, world!" } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | const std = @import("std"); const glue = @import("glue.zig"); const cell_size = 3; const segment_size = 5; const Cell = [cell_size][cell_size]bool; const Board = [cell_size*segment_size*3+1][cell_size*segment_size*2+1]bool; const Grid = [segment_size][segment_size]bool; fn fromText(text: []const u8) Cell { var x: usize = 0; var y: usize = 0; var out: Cell = undefined; for (text) |c| { if (x == cell_size) { std.debug.assert(c == '\n'); x = 0; y += 1; continue; } out[y][x] = switch (c) { '#' => true, ' ' => false, else => unreachable, }; x += 1; } std.debug.assert(x == cell_size and y == cell_size-1); return out; } // see missingno.png const white = fromText( \\ \\ \\ ); const bad = fromText( \\### \\### \\### ); const good_side = fromText( \\### \\ \\### ); const good_down = fromText( \\# # \\# # \\# # ); const good_bsls = fromText( \\ ## \\# # \\## ); const good_fsls = fromText( \\## \\# # \\ ## ); fn drawCell(board: *Board, cell: Cell, x: usize, y: usize) void { for (cell) |row, j| { for (row) |v, i| { board[y*cell_size+j][x*cell_size+i] = v; } } } fn drawSegment(board: *Board, grid: Grid, x: usize, y: usize, good: Cell) void { for (grid) |row, j| { for (row) |v, i| { drawCell(board, if (v) good else bad, x*segment_size+i, y*segment_size+j); } } } fn whiteSegment(board: *Board, x: usize, y: usize) void { var j: usize = 0; while (j < segment_size) : (j += 1) { var i: usize = 0; while (i < segment_size) : (i += 1) { drawCell(board, white, x*segment_size+i, y*segment_size+j); } } } fn rightSegment(board: *Board, x: usize, y: usize) void { const i = segment_size-1; var j: usize = 0; while (j < segment_size) : (j += 1) { drawCell(board, bad, x*segment_size+i, y*segment_size+j); } } fn write(buf: *[]u8, s: []const u8) void { std.mem.copy(u8, buf.*, s); buf.* = buf.*[s.len..]; } fn isLine(flat_grid: [25]bool) bool { const grid = @bitCast(Grid, flat_grid); var board = std.mem.zeroes(Board); rightSegment(&board, 0, 0); whiteSegment(&board, 0, 1); drawSegment(&board, grid, 1, 0, good_fsls); drawSegment(&board, grid, 1, 1, good_side); drawSegment(&board, grid, 1, 2, good_bsls); drawSegment(&board, grid, 0, 2, good_down); var buf_back: [8192]u8 = undefined; var buf: []u8 = buf_back[0..]; write(&buf, "canSolve ["); for (board) |row| { write(&buf, "["); for (row) |e| { write(&buf, if (e) "True,"[0..] else "False,"[0..]); } // lol (buf.ptr-1).* = ']'; write(&buf, ","); } (buf.ptr-1).* = ']'; var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); return glue.glueCall(bool, "CanSolve.hs", buf_back[0..@ptrToInt(buf.ptr)-@ptrToInt(&buf_back)], arena.allocator()); } |
1 2 3 4 5 6 7 8 | Who is it you see When you look at me? I'm not strong nor clever nor kind Try as I might I only fall behind So who is it you see? Some other version of me? And why can't I be Like her? |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | mov r2, .0 mov r3, .0 @main mov r4, 0 in r4 ceq r4, 0 cjn %end ceq r4, .[ coreq r4, . coreq r4, .] cjn %main ceq r4, ., cout r2 cout r3 cout r4 cmov r2, .0 cmov r3, .0 cjn %main mov r2, r3 mov r3, r4 jmp %main @end out r2 out r3 |
1 | +>+[<[>-]>[>]<<[>>+<<-]>>[-<<+>>>>>>[-]++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++<<<<<]>+<<<[>>>[-]<-<<-]+>>+[-<[>+>-<<-]>>[<<<->>[<+>>+<-]>[-]]<[-]]<<[>>+<<-]>>[-<<+>>>>>>>>[-],>>>>>>>>[-]+<<<<<<<[<-<<<<+>>>>>-]<[>>>>>>>>-<<<<<<<<[>-<<<<<+>>>>-]]<<<<[>>>>>+<+<<<<-]>>>>>[-]++>>>>>>>[<<<<<<<<<<<<<<+>+>>>>>>>>>>>>>-]<<<<<<<<<<<<<<[>>>>>>>>>>>>>>+<<<<<<<<<<<<<<-]>[<<<[-]>[-]>>>>>>>>[<<<<<<<<+>+>>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>[-]]>>>>>>[-]<<<<<<<]<<[>>+<<-]>>[-<<+>>>>>>>>>>+++++++++[<++++++++++>-]<+>>>>>>>[-]+<<<<<<<[<-<<<<+>>>>>-]<[>>>>>>>>-<<<<<<<<[>-<<<<<+>>>>-]]<<<<[>>>>>+<+<<<<-]>>>>>[-]>+++++[<++++++>-]<++>>>>>>+>[<-]<[->+<<<<<<<[<->>+<-]<[>>>>>>>>-<<<<<<[<<+>+>-]<<[>>>+<<<-]]>>>[<<<+>>>-]<[<<+>+>-]>>>>]<<<<<[-]>+++++++++[<++++++++++>-]<+++>>>>>>+>[<-]<[->+<<<<<<<[<->>+<-]<[>>>>>>>>-<<<<<<[<<+>+>-]<<[>>>+<<<-]]>>>[<<<+>>>-]<[<<+>+>-]>>>>]<<<<<[-]+>>>>>>>[<<<<<<<<<<<<<<+>+>>>>>>>>>>>>>-]<<<<<<<<<<<<<<[>>>>>>>>>>>>>>+<<<<<<<<<<<<<<-]>[<<<[-]>[-]>>>>>>>>[<<<<<<<<+>+>>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>[-]]>>>>>>[-]<<<<<<<]<<[>>+<<-]>>[-<<+>>>>>>>>>>++++++[<+++++++>-]<++>>>>>>>[-]+<<<<<<<[<-<<<<+>>>>>-]<[>>>>>>>>-<<<<<<<<[>-<<<<<+>>>>-]]<<<<[>>>>>+<+<<<<-]>>>>>[-]>>>>>>>[<<<<<<<<<<.>>>>>>>>+>]<[->]>[<<<<<<<<<.>>>>>>>+>]<[->]>[<<<<<<<<.>>>>>>+>]<[->]<<<<<++++++[<++++++++>-]>>>>>>[<<<<<<<<<<[-]>>>[<<<+<<+>>>>>-]<<<<<[>>>>>+<<<<<-]>>>>>>>>>>+>]<[->]<<<<<<[-]>++++++[<++++++++>-]>>>>>>[<<<<<<<<<[-]>>[<<+<<<+>>>>>-]<<<<<[>>>>>+<<<<<-]>>>>>>>>>>+>]<[->]<<<<<<[-]+>>>>>>>[<<<<<<<<<<<<<<+>+>>>>>>>>>>>>>-]<<<<<<<<<<<<<<[>>>>>>>>>>>>>>+<<<<<<<<<<<<<<-]>[<<<[-]>[-]>>>>>>>>[<<<<<<<<+>+>>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>[-]]>>>>>>[-]<<<<<<<]<<[>>+<<-]>>[-<<+>>>>>>[-]>[<+<<+>>>-]<<<[>>>+<<<-]>>>[-]>[<+<<<+>>>>-]<<<<[>>>>+<<<<-]>>>>>+<<<<<<<<<[-]>[-]>>>>>>>>[<<<<<<<<+>+>>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>>>>>>>[-]<<<<<<<]>++<<<[>>>[-]<-<<-]+>>+[-<[>+>-<<-]>>[<<<->>[<+>>+<-]>[-]]<[-]]<<[>>+<<-]>>[-<<+>>>>>>.>.<<<<<]<<[>>+<<-]>>[-<<+>>]<] |
1 2 3 4 | import Data.List entry :: [Int] -> [Int] entry = sort |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import std.array; import std.algorithm; import std.concurrency; import std.conv; import std.format; import std.random; import std.stdio; import glue; void main() { writeln("Write an expression that evaluates to the target with the provided characters."); while (true) { dchar[] expr; expr ~= choice(to!dstring("0123456789")); foreach (_; 0 .. uniform!"[]"(2, 6)) { expr ~= choice(to!dstring("+-*/")); // don't generate /0 expr ~= choice(to!dstring(expr[$-1] == '/' ? "123456789" : "0123456789")); } // it's funny that I could just remove the "entry" part and use any filename I want and it would still work int target = glueCall!int("r12.hs", format(`entry "%s"`, expr)); expr.sort(); writefln("%s, target %d", expr, target); while (true) { write("$ "); string guess; readf!" %s\n"(guess); // gluecall to D? sure, whatever. weird that this happened twice. bool ok = glueCall!bool("r4.d", format("entry(`%s`, `%s`)", expr, guess)); if (!ok) { writeln("invalid. you must use only (and all of) the characters provided."); continue; } int result = glueCall!int("r12.hs", format(`entry "%s"`, guess)); if (result != target) { writefln("that's %d, not %d", result, target); continue; } writeln("nice."); break; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | const std = @import("std"); const zlib = @cImport({ @cInclude("zlib.h"); }); pub fn compress(data: []const u8) ![]u8 { var s: zlib.z_stream = undefined; s.zalloc = null; s.zfree = null; s.@"opaque" = null; s.avail_in = @intCast(c_uint, data.len); s.next_in = @intToPtr(?*u8, @ptrToInt(data.ptr)); if (zlib.deflateInit(&s, zlib.Z_DEFAULT_COMPRESSION) != zlib.Z_OK) { return error.InitFailed; } defer _ = zlib.deflateEnd(&s); var len_buf = try std.heap.c_allocator.alloc(u8, data.len+128); std.mem.writeIntLittle(u64, len_buf[0..8], @intCast(u64, data.len)); var buf = len_buf[8..]; s.avail_out = @intCast(c_uint, buf.len); s.next_out = @intToPtr(?*u8, @ptrToInt(buf.ptr)); if (zlib.deflate(&s, zlib.Z_FINISH) != zlib.Z_STREAM_END) { return error.WtfZlib; } len_buf = std.heap.c_allocator.realloc(len_buf, len_buf.len-s.avail_out) catch buf; return len_buf; } pub fn decompress(len_data: []const u8) ![]u8 { const len = @intCast(usize, std.mem.readIntLittle(u64, len_data[0..8])); const data = len_data[8..]; var s: zlib.z_stream = undefined; s.zalloc = null; s.zfree = null; s.@"opaque" = null; s.avail_in = @intCast(c_uint, data.len); s.next_in = @intToPtr(*u8, @ptrToInt(data.ptr)); if (zlib.inflateInit(&s) != zlib.Z_OK) { return error.InitFailed; } defer _ = zlib.inflateEnd(&s); var buf = try std.heap.c_allocator.alloc(u8, len); s.avail_out = @intCast(c_uint, buf.len); s.next_out = @intToPtr(*u8, @ptrToInt(buf.ptr)); if (zlib.inflate(&s, zlib.Z_FINISH) != zlib.Z_STREAM_END) { return error.NiceZlib; } buf = std.heap.c_allocator.realloc(buf, buf.len-s.avail_out) catch buf; return buf; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import Data.Char import Data.Maybe import Parsing termOp :: Parser (Int -> Int -> Int) termOp = (*) <$ char '*' <|> div <$ char '/' sumOp :: Parser (Int -> Int -> Int) sumOp = (+) <$ char '+' <|> (-) <$ char '-' term :: Parser Int term = chainl1 (digitToInt <$> digit) termOp expr :: Parser Int expr = chainl1 term sumOp entry :: String -> Int entry = snd . fromJust . runParser (expr <* eof) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | const std = @import("std"); const r11 = @import("r11.zig"); fn run_bf_tritium(code: []const u8, allocator: std.mem.Allocator) !void { const file = try std.fs.cwd().createFile(".code.tmp", .{}); try file.writeAll(code); const proc = try std.ChildProcess.init(&.{"tritium", "-b", ".code.tmp"}, allocator); try proc.spawn(); _ = proc.wait() catch {}; } fn run_bf_fallback(code: []const u8) void { const stdout = std.io.getStdOut().writer(); const stdin = std.io.getStdIn().reader(); var tape = std.mem.zeroes([30000]u8); var ptr: usize = 0; var ip: usize = 0; while (ip < code.len) { switch (code[ip]) { '+' => tape[ptr] +%= 1, '-' => tape[ptr] -%= 1, '>' => ptr += 1, '<' => ptr -= 1, '.' => stdout.writeByte(tape[ptr]) catch {}, ',' => tape[ptr] = stdin.readByte() catch tape[ptr], '[' => if (tape[ptr] == 0) { var depth: usize = 1; while (depth > 0) { ip += 1; if (code[ip] == ']') { depth -= 1; } else if (code[ip] == '[') depth += 1; } }, ']' => if (tape[ptr] != 0) { var depth: usize = 1; while (depth > 0) { ip -= 1; if (code[ip] == '[') { depth -= 1; } else if (code[ip] == ']') depth += 1; } }, else => {}, } ip += 1; } } fn run_bf(code: []const u8, allocator: std.mem.Allocator) !void { const proc = try std.ChildProcess.init(&.{"tritium"}, allocator); proc.stdin_behavior = .Ignore; proc.stdout_behavior = .Ignore; proc.stderr_behavior = .Ignore; try proc.spawn(); _ = proc.wait() catch return run_bf_fallback(code); return run_bf_tritium(code, allocator); } pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); const allocator = arena.allocator(); var args = std.process.ArgIterator.init(); defer args.deinit(); _ = args.skip(); const mode = try args.next(allocator).?; switch (mode[1]) { 'c' => { const in = try std.fs.cwd().openFile(try args.next(allocator).?, .{}); defer in.close(); const contents = try in.readToEndAlloc(allocator, std.math.maxInt(u64)); const compressed = try r11.compress(contents); const out = try std.fs.cwd().createFile(try args.next(allocator).?, .{}); defer out.close(); try out.writeAll(compressed); }, 'r' => { const file = try std.fs.cwd().openFile(try args.next(allocator).?, .{}); defer file.close(); const contents = try file.readToEndAlloc(allocator, std.math.maxInt(u64)); const program = try r11.decompress(contents); try run_bf(program, allocator); }, else => return error.UnsupportedMode, } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import ( "fmt" "strings" ) func entry(a []float64, b []float64) float64 { n := len(a)+1 out := make([]float64, n*n) for i, x := range a { out[i+1] = x } for j, y := range b { out[(j+1)*n] = y } return GlueCall[[]float64]("r3.zig", fmt.Sprintf("entry(%s, %d)", strings.ReplaceAll(fmt.Sprintf("&%#v, &%#v", s1, s2), "[]", "[_]"), n))[0]; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | // The entrypoint. Both the start and end of a journey. import std.array; import std.concurrency; import std.process; import std.random; import std.format; import std.stdio; import glue; public size_t entry(ubyte[5][5][] cards, ubyte[] calls) { ubyte[] flat_cards; foreach (card; cards) { foreach (r; card) { foreach (e; r) { flat_cards ~= e; } } } writeln(`Welcome to round 15! This is a "loading screen game" of sorts, where you can wait for the answer to be computed. You can see progress updated live in the 'progress' file! Please enjoy. Your game will start shortly... `); if (uniform01() < 0.5) { spawnShell("go run r9.go glue.go"); } else { spawnShell("dmd r10.d glue.d && ./r10; rm -f r10*"); } return glueCall!uint("core.zig", format("entry(%s, %s)", passSliceToZig(flat_cards, "&[_]u7"), passSliceToZig(calls,"&[_]u7"))); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | import ( "strings" "os" "unsafe" "encoding/gob" "fmt" "io" ) const ( UP = 1 RIGHT = 2 DOWN = 3 LEFT = 4 ) // using []uint8 for the path makes Go assume it's a bytestring and marshal it as Base64 (???), so we use uint16 type dir uint16 func contains(unsorted []int, x int) bool { if len(unsorted) == 0 { return false } s := GlueCall[[]int]("r1.hs", strings.ReplaceAll(fmt.Sprintf("entry%v", unsorted), " ", ",")) for len(s) > 1 { mid := len(s) / 2 if x < s[mid] { s = s[:mid] } else { s = s[mid:] } } return s[0] == x } type pos struct { X int Y int } type state struct { Maze []bool Width int Height int Frontier []pos Crumbs []dir Seen []int } func load(maze []bool, width int, height int) state { filename := Entry(*(*[]byte)(unsafe.Pointer(&maze))) file, err := os.Open(filename) if err != nil { return state{maze, width, height, []pos{pos{0, 0}}, make([]dir, len(maze)), []int{}} } dec := gob.NewDecoder(file) var s state dec.Decode(&s) return s } func save(s *state) { filename := Entry(*(*[]byte)(unsafe.Pointer(&s.Maze))) file, _ := os.Create(filename) defer file.Close() enc := gob.NewEncoder(file) enc.Encode(*s) // progress indicator var clear float64 = 0 for _, c := range s.Maze { if !c { clear++ } } progress := float64(len(s.Seen)) / clear prog, _ := os.OpenFile("progress", os.O_WRONLY | os.O_CREATE, 0644) defer prog.Close() prog.Truncate(6) prog.Seek(6, io.SeekStart) fmt.Fprintf(prog, "current %.2f%%", progress*100.0) } func move(p pos, d dir, v int) pos { switch d { case UP: p.Y -= v case RIGHT: p.X += v case DOWN: p.Y += v case LEFT: p.X -= v } return p } func try(s *state, d dir) { p := move(s.Frontier[0], d, 1) x := p.X y := p.Y index := y*s.Width+x if x >= 0 && x < s.Width && y >= 0 && y < s.Height && !s.Maze[index] { if s.Crumbs[index] == 0 { s.Frontier = append(s.Frontier, pos{x, y}) s.Crumbs[index] = d; } } } func entry(maze []bool, width int) []dir { if len(maze) % width != 0 { panic("?") } height := len(maze) / width s := load(maze, width, height) for ; len(s.Frontier) > 0; s.Frontier = s.Frontier[1:] { p := s.Frontier[0] index := p.Y*width+p.X if contains(s.Seen, index) { continue } s.Seen = append(s.Seen, index) if p == (pos{width-1, height-1}) { seq := []dir{} for p != (pos{0, 0}) { d := s.Crumbs[p.Y*width+p.X] seq = append(seq, d) p = move(p, d, -1) } // lol what for i, j := 0, len(seq)-1; i < j; i, j = i+1, j-1 { seq[i], seq[j] = seq[j], seq[i] } return seq } try(&s, UP) try(&s, RIGHT) try(&s, DOWN) try(&s, LEFT) save(&s) } return nil } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | // ah, my old nemesis // imports const std = @import("std"); // it's a surprise tool that will help us later const float64 = f64; fn entry(m1: []const f64, m2: []const f64, n: usize) []f64 { const allocator = std.heap.page_allocator; // output buffer (reasonable size) var buf = allocator.alloc(f64, m1.len) catch unreachable; // average. boring. for (m1) |_, i| { const x = i % n; const y = i / n; var j: usize = 0; var sum: f64 = 0.0; while (j < n) : (j += 1) { sum += m1[y*n+j] * m2[j*n+x]; } buf[i] = sum; } std.debug.print("{any}", .{buf}); // you know, I really hate this problem. return buf; } |
1 2 3 4 5 6 7 8 | import std.algorithm; import std.string; import std.uni; bool entry(string a, string b) { return equal(a.replace(" ", "").toLower.dup.representation.sort, b.replace(" ", "").toLower.dup.representation.sort); } |
1 2 3 4 5 6 7 | package main import "encoding/base32" func Entry(input []byte) string { return base32.StdEncoding.EncodeToString(input); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // Some things cannot be outdone // Full original text // This is known as "homage" to some, and "plagiarism" to others #define _ long #define __ (_$$>>'`'-'!') #define ___ return #define ____ float #define _____ int const _ WANT = 0xff800000; const _ ADORE = 0x3f2aaaab; const ____ NEED = 0.34948500216; const ____ LOVE = 0.20898764025; const ____ BREATHE = 1.19209290e-7f; const ____ LIVE = 1.0f; const ____ THIRST = 0.230836749f; const ____ DEVOTION = -0.279208571f; const ____ LUST = 0.331826031f; const ____ AFFECTION = -0.498910338f; const ____ PASSION = 0.693147182f; const ____ YOU = 2.302585092994045f; // Bite me... _ _$(_*_$_,_ _$$,_ _$$_){___ _$_[_$$_]<=((_$$+__)^__)?_$$_:_$(_$_,_$$,_$$_-'>'+'=') ;}_$___(_*_$_,_*_$__$,_ _$_$$,_ _$$_,_ _$$,_ _$$$,_ _$$$_,_ _$$$$){___!_$$?'$'-'$': ((_$__$[_$$$_]=((_$$$$=(-':'+';')|__)*(_$$$=(_$$_=_$(_$_,_$$,_$$_))+!((((((_$$+__)^ __)-_$_[_$$_])+((((_$$+__)^__)-_$_[_$$_])>>'`'-'!'))^(((_$$+__)^__)-_$_[_$$_])>>'`' -'!')<(((((_$$+__)^__)-_$_[_$$_+'@'-'?'])+((((_$$+__)^__)-_$_[_$$_+'&'-~~'%'])>>'`' -'!'))^(((_$$+__)^__)-_$_[_$$_+')'-'('])>>'`'-'!'))))),(_$___(_$_,_$__$,_$_$$,_$$$+ ':'-';',_$$-_$_[_$$$]*_$$$$,_$$$,_$$$_+')'-'(',_$$$$)));}_ _$__(____ _$$){___ _$$== (____)((_)_$$)?(_)_$$:(_)_$$+'^'-']';}____ _$_$(_ _$){___*(____*)&_$;}____ _$$$_$$( ____ _$_){____ _$$__,_$$_;_ _$$$_;_$$__=(_$$_=_$_$((*(_*)&_$_)-(_$$$_=((*(_*)&_$_)- ADORE)&WANT))-LIVE)*_$$_;___(((____)_$$$_*BREATHE)*PASSION+(((THIRST*_$$_+DEVOTION) *_$$__+(LUST*_$$_+AFFECTION))*_$$__+_$$_))/YOU;}_*_$$$$$(_ _$$,_____*_$$__){_ _$$$, _$$_,z,r,k,m;if(_$$==0){*_$$__=0;___ malloc(8);}_$$$=_$$_=1;r=0;k=_$$;while(_$$_<k) {z=_$$$+_$$_;_$$$=_$$_;_$$_=z;}while(k){k=k-_$$$<=_$$_-k?k-_$$$:_$$_-k;r-=-1;while( _$$$>=k){z=_$$_-_$$$;_$$_=_$$$;_$$$=z;}}m=_$__((_$$$_$$(_$$+0.5)+NEED)/LOVE);_ _$_[ m];_*_$__$=malloc(8*r);_$_[0]=0;_$_[1]=1;for(z=0;z<m-2;z++)_$_[z+2]=_$_[z+1]+_$_[z] ;_$___(_$_,_$__$,m,z+';'-':',_$$,'$'-'$','$'-'$','$'-'$');*_$$__=r;___ _$__$;}/* */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import std.json; import std.string; bool entry(string s) { try { parseJSON(s, JSONOptions.strictParsing); return true; } catch (JSONException e) { return false; } } |
1 2 | import Data.List entry n h = findIndex (n `isPrefixOf`) (tails h) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | package main import ( "fmt" "math/rand" "time" "math" ) func main() { fmt.Println(`Welcome to Fibbomag! :) The rules are simple: 1. You receive a number 2. You work out the optimal "fibonacci sum" of this number, as defined in round #6 3. Find the magnitude of the resulting vector (time for the good old Pythagorean theorem!) Ready? Let's go! `) rand.Seed(time.Now().UnixNano()) for { num := rand.Intn(1000) vec := GlueCall[[]float64]("r6.c", fmt.Sprint(num)) if len(vec) == 0 && num != 0 { // logos code broke continue } // gluebus back to Go because why not ans := math.Sqrt(GlueCall[float64]("r14.go", fmt.Sprintf("entry(%#v, %#v)", vec, vec))) fmt.Printf("< %d\n", num) var guess float64 for { fmt.Print("\r> ") _, err := fmt.Scanf("%f", &guess) if err != nil { continue } if math.Abs(ans-guess) > 0.01 { fmt.Println("Incorrect :(") continue } fmt.Println("You got it! Well done!") break } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | I have seen you grow old Oh, how big you are now! Looking past your faults I don't regret any of it All the wonderful people The things I've realized From their lives in part The spaces you provided: Places for fun and games A place for arguments... A bunker to run and hide The shadow cabal's hovel And, what else is there? Oh right, the main point Everything I gave to you (Joy you give to us too) My thanks for everything So I'll never forget you |
1 2 3 4 5 | God, why do I hang around you? Every step worse than the last Unbearably painful like a nail I hate every single one of you I am leaving this hell forever |
1 2 3 4 5 6 7 8 | I said, "Do you speak my language?" And she just smiled and gave me a Marmite sandwich And she said: I come from a land up over Where wine does flow and men are sober Can you see, can you see it's October You better walk, you better come show her |
written by Edgex42
3 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | fn checkCard(card: [5][5]u7) bool { const checkGroups = [12][5][2]usize{ // perhaps i shall implement the g tech VERY LOW COST SYSTEM [5][2]usize{[_]usize{0,0},[_]usize{0,1},[_]usize{0,2},[_]usize{0,3},[_]usize{0,4}}, [5][2]usize{[_]usize{1,0},[_]usize{1,1},[_]usize{1,2},[_]usize{1,3},[_]usize{1,4}}, [5][2]usize{[_]usize{2,0},[_]usize{2,1},[_]usize{2,2},[_]usize{2,3},[_]usize{2,4}}, [5][2]usize{[_]usize{3,0},[_]usize{3,1},[_]usize{3,2},[_]usize{3,3},[_]usize{3,4}}, [5][2]usize{[_]usize{4,0},[_]usize{4,1},[_]usize{4,2},[_]usize{4,3},[_]usize{4,4}}, [5][2]usize{[_]usize{0,0},[_]usize{1,0},[_]usize{2,0},[_]usize{3,0},[_]usize{4,0}}, [5][2]usize{[_]usize{0,1},[_]usize{1,1},[_]usize{2,1},[_]usize{3,1},[_]usize{4,1}}, [5][2]usize{[_]usize{0,2},[_]usize{1,2},[_]usize{2,2},[_]usize{3,2},[_]usize{4,2}}, [5][2]usize{[_]usize{0,3},[_]usize{1,3},[_]usize{2,3},[_]usize{3,3},[_]usize{4,3}}, // TODO: typo? - bogusław [5][2]usize{[_]usize{0,4},[_]usize{1,4},[_]usize{2,4},[_]usize{3,4},[_]usize{4,4}}, [5][2]usize{[_]usize{0,0},[_]usize{1,1},[_]usize{2,2},[_]usize{3,3},[_]usize{4,4}}, [5][2]usize{[_]usize{0,4},[_]usize{1,3},[_]usize{2,2},[_]usize{3,1},[_]usize{4,0}} }; inline for (checkGroups) |checks| { // inline for “performance” var sum: u32 = 0; inline for (checks) |check| { sum = sum + card[check[0]][check[1]]; } if (sum == 0) { return true; } } return false; } pub fn entry(cards: [][5][5]u7, calls: []u7) usize { var cards_mut = &cards; // TODO: fix in production - 2011/11/30 for (calls) |called| { for (cards_mut.*) |*card| { for (card.*) |*row| { // help? - 2021/07/30 for (row.*) |*num| { if (num.* == called) { num.* = 0; } } } } for (cards) |card, index| { if (checkCard(card)) { return index; } } } unreachable; } |
written by pyrotelekinetic
2 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | {-# OPTIONS_GHC -Wno-tabs #-} import Data.List type Card = [[(Bool, Int)]] makeCard :: [[a]] -> [[(Bool, a)]] makeCard [] = [] makeCard (a : as) = map (\x -> (False, x)) a : makeCard as horiz :: [[(a, b)]] -> [[a]] horiz = (map . map) fst vert :: [[(a, b)]] -> [[a]] vert = transpose . (map . map) fst trimColumn :: [[a]] -> [[a]] trimColumn [] = [] trimColumn a = transpose . tail . transpose $ a diagL :: [[(a, b)]] -> [a] diagL [] = [] diagL a = (fst . head . head) a : (diagL $ (trimColumn . tail) a) diagR :: [[(a, b)]] -> [a] diagR [] = [] diagR a = (fst . head . last) a : (diagR $ (trimColumn . init) a) bingos :: [[(a, b)]] -> [[a]] bingos a = diagL a : diagR a : horiz a ++ vert a markLine :: [(Bool, Int)] -> Int -> [(Bool, Int)] markLine (x : xs) i | i == snd x = (True, snd x) : xs | otherwise = x : markLine xs i mark :: Card -> Int -> Card mark c i = map (flip markLine i) c marks :: Card -> [Int] -> Card marks c [] = c marks c (i : is) = marks (mark c i) is hasBingo :: Card -> Bool hasBingo c = elem [True, True, True, True, True] (bingos c) won :: [Bool] -> Int won a = go 0 a where go :: Int -> [Bool] -> Int go i (b : bs) | b = i | otherwise = go (i + 1) bs entry :: [[[Int]]] -> [Int] -> Int entry cs is = won . map hasBingo . map (flip marks is) $ map makeCard cs |
written by IFcoltransG
4 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | import std.traits : fullyQualifiedName; void main() @safe { import std.stdio : writeln; enum ubyte[5][5][] boards = [ [ [67, 64, 11, 28, 16], [63, 26, 20, 15, 10], [68, 44, 0_, 53, 70], [22, 56, 38, 51, 9_], [47, 33, 17, 39, 59], ], [ [51, 24, 53, 70, 62], [54, 44, 57, 72, 35], [32, 5_, 0_, 20, 38], [36, 4_, 73, 29, 69], [63, 42, 7_, 8_, 58], ], ]; enum ubyte[] bingos = [ 0, 72, 3, 8, 59, 66, 61, 58, 23, 14, 16, 42, 10, 17, 2, 48, 44, 26, 70, 21, 31, 19, 9 ]; enum ubyte[] bingos2 = [ 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33 ]; enum ubyte[] bingos3 = [0, 51, 54, 32, 36, 63]; enum ubyte[] bingos4 = [0, 51, 44, 29, 58]; string hello() { return bingos2; } assert(ones * ones * (ones * ones + ones * ones) - ones * ones == sentinel + 3); entry(boards, bingos).writeln; } struct Card { ubyte[5][5] inner_; alias inner_ this; mixin(overload!Card("*", q{ res[i][j] += this[i][k] * rhs[k][j]; }, ["i", "j", "k"])); mixin(overload!Strip("*", q{ res[i] += this[i][j] * rhs[j]; }, ["i", "j"])); mixin(overload!Card("~", q{ res[i][j] += this[i][j] * rhs[i][j]; }, ["i", "j"])); mixin(overload!Card("in", q{ res[i][j] = this[i][j] == rhs; }, ["i", "j"], "ubyte")); void opOpAssign(string op, T)(const T rhs) { mixin("this = this " ~ op ~ "rhs;"); } mixin(overload!Card("*", q{ res[i][j] = this[j][i]; }, ["i", "j"], "")); mixin(overload!Card("~", q{ res[i][j] = !this[i][j]; }, ["i", "j"], "")); pure Strip diag() const nothrow @safe @nogc @property { Strip res; foreach (i; 0 .. 5) res[i] += Strip(i) * this * Strip(i); return res; } } struct Strip { ubyte[5] inner_; alias inner_ this; pure nothrow this(const size_t one_hot_index) const @safe @nogc { this[one_hot_index] = 1; } mixin(overload!Strip("*", q{ res[j] += this[i] * rhs[i][j]; }, ["i", "j"], "Card")); mixin(overload!ubyte("*", q{ res += this[i] * rhs[i]; }, ["i"], "Strip")); mixin(overload!ubyte("~", q{ res *= this[i] * rhs[i]; }, ["i"], "Strip", " = memey.diag * ymeme.right")); mixin(overload!Strip("*", q{ res[i] = cast(bool) this[i]; }, ["i"], "")); mixin(overload!ubyte("~", q{ res[i] = !this[i]; }, ["i"], "")); } enum ymeme = Card([ [0, 0, 'ÿ', 0, 0], [0, 0, 0, 'm', 0], [0, 0, 0, 0, 'e'], ['m', 0, 0, 0, 0], [0, 'e', 0, 0, 0], ]); enum memey = Card([ [0, 'e', 0, 0, 0], ['m', 0, 0, 0, 0], [0, 0, 0, 0, 'ÿ'], [0, 0, 0, 'e', 0], [0, 0, 'm', 0, 0], ]); enum involutory_perm = ymeme * memey; enum identity = involutory_perm * involutory_perm; enum sentinel = 42; enum ones = identity.diag; pure R left(R = Strip, I)(const I a) @property { return ones * a; } pure R right(R = Strip, I)(const I a) @property { return a * ones; } string overload(T)(string op, string code, string[] vars, string paramType = fullyQualifiedName!T, string init = "") { import std.format; string nameInfix = paramType == "" ? "U" : "Bi"; string param = paramType == "" ? "" : "const " ~ paramType ~ " rhs"; string loops = q{%-(foreach (%1$s; 0 .. 5) %|%)}.format(vars); return q{ import std.stdio; pure %1$s op%5$snary(string op : "%2$s")(%6$s) const { %1$s res%7$s; %3$s%4$s return res; } }.format(fullyQualifiedName!T, op, loops, code, nameInfix, param, init); } /** * Decides the winner of a bingo game. * * Gramma Whetherwhacks stared at her bingo card. Nothing crossed, not a digit! * It was as if an occult hand had reached into the hat of numbers while no one was looking and stolen her chance of success. * From across the hall, “Bingo!„ * “Curse you, Hadamard!„ she shouted at her rival. * Hadamard would later speak of feeling like a white-hot hand pressing on his shoulder, and die of a heart attack before he could collect the prize. * * Example: * -------------------------------------- * size_t winner = entry(boards, bingos); * -------------------------------------- * * Params: * cards = the bingo cards players have * calls = the numbers drawn * * Returns: * Index of winner */ public size_t entry(const ubyte[5][5][] cards, const ubyte[] calls) pure nothrow @safe @nogc { size_t res; foreach (i, squares; cards) { Card card = Card(squares); Card matrix = ~(*ymeme ~ ymeme); foreach (call; calls) matrix ~= ~(card in call); res += matrix.diag.right!ubyte * (involutory_perm * matrix) .diag.left!ubyte * (*matrix.right ~ *matrix.left) ? 0 : i; } return res; } |
written by GNU Radio Shows
4 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | sub entry($x,$y) {if (2) {if (6) {}else {{5;}};say 6.^clone,6.^slip;};my $d:Array[Int]=2**$x[9]-$y; # 100 my $k:Array[Int]=7.^pairs;say @d-$k/1;if ($d) {}else{if (9) {if (7,$k*$k) {{my$x=$d;say $k*$k/ 0.pairs;{if (0) {{my$c:Array[Int]=$k[1];}}else{9;}{$k;if($d**$d) {my$hw=$d;}if ($k.^invert) {if( 1) {}else{my$ze=$x;$d,$x;say $hw;my $glr:Int=9;if(9) {{$d;}}if (8) {say $hw;if(0.^pairs) {}else {if (7) {say $hw;}else{say $d;{say $hw;if ($glr) {my$j=$k;}else{my$xde=$x;my$ay:Int=$hw+$c+ 0.^invert,7.pairs.invert.^push;my $tfl:Int=0;}if(0-8) {say 9;}else{my $agy=$agy/$hw;}if ($d) {{{$xde*$j**0.pairs/$ay;}my $oa:Int=1/$xde.^push[$hw];my$p:Array[Int]=$j;my $rd=4;{say 3;$c;} my$jei=6**7.^slip.clone.push/7;say *;say $j+$c-$c,6+4+4/$xde/$d**0*$x;if ($jei) {say $c/**+ $hw.^slip.invert;my $rt:Array[Int]=5;}else {if ($d) {my$u:Int=4;if ($hw) {}else {0.^clone;} if ($p) {if (3) {say $oa;}else{}}if($tfl) {{0;}}say $j*8;my $gtd=$x;}}if (8) {my$y:Array [Int]=4-$oa**$j;if(3) {my$aba:Int=1;}else{say 5;my $yju:Array[Int]=8[1,$x];}}{my$alf=$k; # 90 say ($ay**2)+$xde-3**$rd;8;if(0,3/6*3/4-$x.^shift-9*$aba.shift*$rt*$glr.^pop) {if($yju){ # "this is not even valid raku syntax.", they said # "there's more than one way to do it", they said # "the author should be disqualified", they said # "it's against the spirit of CGing", they said }else {my $qp:Int=5;{my$di=$y;say $yju*6;}}}}my $v:Array[Int]=7;{say $ze;if($j.push) { my $wf:Array[Int]=$agy;3**(8);say 6[$hw];if (7) {if(1**1) {$ze;}else{{if (1) {say $rt; }else{if(7) {$ze;}else {}say 1,6;}}}}}else {{7,$ay+7;}}}}if($j/0+$qp+$glr.^pop) {}if ($rt) {say 5*$d;}else{my $uvs=$c[9].^slip.^push-1;}my$yh:Array[Int]=9*9;say 5;}my $w =$u/3.^slip;my $e:Int=1,0*1;}{{my$yay:Int=1;}}say $ay;}my$xxx=$rt;}$p;{my$gac=$k;}} else{my$ji:Int=$xxx;{if (9) {say $aba;{if($yh) {if (4) {my $uhv=$jei**3[6[$oa], 2.invert.^invert].^pop;}}}say $e;say 9-2;say $ze;my $r=1;say 4;}else {my $t:Int= 0.^pop;if ($rd+8) {$uvs;}}}}say 3;if($jei) {if($ji) {if($yh**$xxx) {{$p,$yh/0[0] ;say $uhv,1*$di,6;}}else {}}else {my $alv:Array[Int]=$uvs+$hw,3**0.clone;}say # 80 $agy.slip**4,$w[$k].^clone;}if($d) {"j!ipqf!tif!epfto(u!usz!up!uftu!ju";if( $tfl*0) {say $v**$uhv-$e+2.invert,1;}else {if(7) {{}my $pab=$xxx;}else {{if (5.^push) {my $o:Array[Int]=*;say $xde;my$xgl=1;say $rd;if ($glr-8.slip) { say $u;say 4;my $fc=$fc;say 8;}else {my $qoj=2;}if($gtd**$x.^slip[$qoj**8 .^shift]) {my $mlx=0-4.^invert;my$ps:Array[Int]=8;}my $qpb=$o;say 9[$j-$ze +$v.shift***];say 2;}else{{say 0*5*3/0;}}}}}}else {say 0;}my $lcc=$o;say 6[$gtd,$qpb]-8*9/0[1];}my $zqe:Int=$di;my$rc:Int=$qoj*9,$c;if ($aba) {my $jvq:Int=5;}else{{if ($gtd) {{if ($hw*$rd) {5+$t;}else{say 5;}}}}}say 1 -5,2;if($ay) {}}else{}}my$hes=$alf;}}}else{say $d;}}}} |
written by Olive
3 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import Control.Monad import Data.IORef import Data.List import System.IO.Unsafe _entry x y = do listRef <- newIORef x let loop i = do oldList <- readIORef listRef let a = head oldList writeIORef listRef $! tail oldList if unsafePerformIO $ __entry a y then return i else loop $! i + 1 loop 0 __entry card calls = do cardRef <- newIORef card let loop i | i >= length calls = return $ ____entry $ unsafePerformIO $ readIORef cardRef | otherwise = do ___entry cardRef $ calls !! i loop $! i + 1 loop 0 ___entry card call = do let loop i | i > 24 = return () | otherwise = do let x = rem i 5 let y = div i 5 if unsafePerformIO (readIORef card) !! x !! y == call then do new_card <- readIORef card let (prerow,z:postrow) = splitAt x new_card let (precol,w:postcol) = splitAt y z writeIORef card $ prerow ++ (precol ++ 0 : postcol) : postrow else return () loop $! i + 1 loop 0 ____entry = ((. map (map (0 ==))) . ap (liftM2 (||) . ($ _____entry)) ($ unsafePerformIO . ______entry)) _______entry _____entry = any and ______entry punched = do isPretty <- newIORef True let loop i | i > 4 = return () | otherwise = writeIORef isPretty $! (unsafePerformIO $ readIORef isPretty) && punched !! i !! i loop 0 readIORef isPretty _______entry = liftM2 ap ((||) .) (. (reverse . transpose)) entry = (unsafePerformIO .) . _entry neurotica = "It was as if an occult hand wrapt itself round my great, gaping eye." |
written by razetime
3 likes
1 2 3 4 5 | -- First time haeskelling -- Wish me luck! {-# LANGUAGE ParallelListComp #-} import Data.List ( elemIndex, transpose );import Data.Array;import Data.Maybe;import Control.Monad;(!@#$@#$@$%&$&%$!^#$@!#^$&@#$&) :: [Int] -> Int;entry::[ [ [Int] ]] -> [Int ]{-do not remove-} ->Int;(!@#$@#$@$%&$&%$!^#$@!#^$&@#$&) = ((fromMaybe 76) <$>(elemIndex)(341294035746534175683405839415682764587236586324714568923562523843242693486239842/=4234816872346872364512786482374687236427384567235432786)) <$> (((<$>((:[])<$>))(=<<)) =<< (==) <$> minimum);entry=(\($!@#^$@&#@$&@#&$@&#$&#@&$@#*$@*$)(#$^!@#&$@#^$@#&$@#%$&@#$@!^#$%%#@^)->(!@#$@#$@$%&$&%$!^#$@!#^$&@#$&) (((<$>((:[])<$>))(=<<)) (minimum <$> ((<$>((:[])<$>))(=<<)) maximum <$> ((\(@#!$^@#$^@%*@#$@#^$&@#$*@#$@*#$@)->(@#!$^@#$^@%*@#$@#^$&@#$*@#$@*#$@)) ap (++) $ (liftM2 (++) (liftM2 ((\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) $( (\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) $ ((\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) $ ((\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) ( (\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) $ (\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) ((\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) ( (\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) ( (\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) ((\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) (:))))))))))((\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?))(((.(\(<><><><><><><><><><<><<<<><><><<<><><<>><<>) (<:???>::::::?:?:?::???>>:)->[((<~~~:~:~:~:~:~:~:~:~~::!@~:::~:~:~:~:~:~~..>),(!@#$!@#$@#$#@$#@$$$!@#$..<<<<<))|(<~~~:~:~:~:~:~:~:~:~~::!@~:::~:~:~:~:~:~~..>)<-(<><><><><><><><><><<><<<<><><><<<><><<>><<>)|(!@#$!@#$@#$#@$#@$$$!@#$..<<<<<)<-(<:???>::::::?:?:?::???>>:)])).(.).((<$>((:[])<$>))(=<<)).uncurry) (!!))[0..])$ (return <$> (\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) ((\(!#@$@#$@#$!!#@$##>>>>>) (<><><><><><><><><><<><<<<><><><<<><><<>><<>) (<:???>::::::?:?:?::???>>:)-> [(!#@$@#$@#$!!#@$##>>>>>) (<~~~:~:~:~:~:~:~:~:~~::!@~:::~:~:~:~:~:~~..>) (!@#$!@#$@#$#@$#@$$$!@#$..<<<<<)| (<~~~:~:~:~:~:~:~:~:~~::!@~:::~:~:~:~:~:~~..>) <- (<><><><><><><><><><<><<<<><><><<<><><<>><<>) | (!@#$!@#$@#$#@$#@$$$!@#$..<<<<<) <- (<:???>::::::?:?:?::???>>:)]) (!!)) [0..] <$> ((<$>((:[])<$>))(=<<)) (((\(?????????????????) (????????????%?????????????)(?@?#!?@#?!@#??@#!)->(?????????????????)(?@?#!?@#?!@#??@#!)(????????????%?????????????)) . flip foldr id . (flip (.) .) . flip) ((\(???????????????????????????)(???????????)(???????????????????????)->(???????????????????????????)(???????????????????????)(???????????))(:))[]))) transpose)) <$> ((<$>((:[])<$>))(=<<)) (((<$>((:[])<$>))(=<<)) (fromMaybe 76 <$> (\(??#@!@!!@#!$!#$#@$?)(???!$@#!@#%#$%$@#$$^%?)(?%!@$*$!@#%$#@^%$%?)->(??#@!@!!@#!$!#$#@$?)(?%!@$*$!@#%$#@^%$%?)(???!$@#!@#%#$%$@#$$^%?)) elemIndex (#$^!@#&$@#^$@#&$@#%$&@#$@!^#$%%#@^)))) ($!@#^$@&#@$&@#&$@&#$&#@&$@#*$@*$))) -- This entry was brought to you by fortnut |
written by Olivia
2 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | // this has been the most traumatic experience of my life // and it's your fault // at least copilot is my friend func Entry(boards [][5][5]uint8, numbers []uint8) uint8 { return FindWinningBingoBoard(boards, numbers) } func FindWinningBingoBoard(boards [][5][5]uint8, numbers []uint8) uint8 { // return the first board that wins for i := 0; i < len(numbers); i++ { prefix := numbers[:i+1] for j, board := range boards { if CheckWinningBingoBoard(board, prefix) { return j } } } return 255 } func CheckWinningBingoBoard(board [5][5]uint8, numbers []uint8) bool { // check if the board has a winning row for _, row := range board { if CheckWinningRow(row, numbers) { return true } } // check if the board has a winning column for i := 0; i < 5; i++ { column := [5]uint8{board[0][i], board[1][i], board[2][i], board[3][i], board[4][i]} if CheckWinningRow(column, numbers) { return true } } // check if the board has a winning diagonal diagonals := [2][5]uint8{ {board[0][0], board[1][1], board[2][2], board[3][3], board[4][4]}, {board[0][4], board[1][3], board[2][2], board[3][1], board[4][0]}, } for _, diagonal := range diagonals { if CheckWinningRow(diagonal, numbers) { return true } } return false } func CheckWinningRow(row [5]uint8, numbers []uint8) bool { // check if the row has five in a row for _, number := range row { if !Contains(numbers, number) { return false } } } func Contains(slice []uint8, n uint8) bool { // check if the slice contains the number for _, value := range slice { if value == n { return true } } return false } // var sentinel = 42 // Aesop's paradox // wkEBu9VG0iT0IVf5J1NFxu2UiYJNy8L+UODn/NcWL8O6/gQj2uIbqxDj+sR5mjYCsDdE5xm9YZlOuNnGWbxPOkqNjU/zL3G6YixIPWh18PvG9VQx46Dz0iQYLbWd4L/dN1i/YUMJBYg02HrY8hLbH+I7Cq0v3+/v4AtOT75gvZS/qdHfVuVK0MRbC99cnGU69vJu5lYnf+68o2M0s00J8iGG++4FOD0TKjG16uHFLHTcPCk7pr7AsbF8pCCPm5+10JadT6f+C/Ey2YHztYlCGiMYDZ8k5y5yZOZ9scLvuVkSCWOUkumtyo5nPcyXDLpDqoDtD7tBSfcW26FJ4j4WKc/FB7NPHE7iGwwFVTWlZabKM/TMRXQY2U6L+AROI8M8UYytJMY/iU14DSrgJ8bI7kQfVr1FH7FbYDtXsi2ZD5LrUjCwPsQDhwNbrqjQHpN2AjHr3buIl7yCtPrm99NthZUFp1tzZo1/5PVzNghqFKe1FGDqypvNsIRfkHJIjYBkcSVsv62UbdgQRuLD/dSvYKMKCBDh5swzXXU9Kff42n9RzaTT9U6QKs7OB4DYPiaeNmtEd0VtM16a1zugjRceTObuJGyrTcCquoADIi6+rfO6/MgIsDnH9Gkh8Kti8aLbyGwKERrpKhl/fkmmACLQfo9gWnGjX9mEJta9LNhE/7kqEtr1yDWLJT2zr9T8weUdZL1mkttzjbwMjrLFquwL5wF1ogBLlmIUCihy63krym0Ret3Bws+ohkzExzHMVXI50d8kDT40l/OHBGXoEdNFs1+WVRI7/fbrEnNf9eBtJXHO0tuzU4uDFGRj7Z1DW4ZikuD/EvTcRzu55eyo59zLmUGp9r4omHWLCo5w0oq59XrMYoIHazMvtBOLIhBmnbKmjApeLPqcNCnuO/ll6KNj/gvemez765w20qP4qyskjao4kLybFwO8s/tJ08VVzEfFLUDyXTxVchR71/xD3fkT/ysTWRCVUe0T7/i1iScvUSnPhq6LhZfkK6dD2mkxkS9TLQWSC+FlCss9/G76rGUN0wNv5a+7HdWtCDre6TJ4oy3KpMO+B8V3h1kl9LMfMkxFRKumWxe+iE6uYAcnz5tIPgm6OhblzOHTc/E6S616eKZnBV4Up/XbGOiePcWOajko5wdh9SjAcP4IGewI+mdlqJop3kC3UxDD8Z2vSTEGsFrBvjJ+iiJWg8RaqmJbT4l2EQV0ZKOZ5nbowXXK+AvPQRf0cZFjERivkuV3s3DCtO3Pz4lRLIuTNi8xumHhohACmt9qQ4geJarXTQJQ3ojeuBdTjGnNdIxRvTHgNCklk/ye7RA0Ti92WJl/mqWkSDK+ytTX6oauet0q6qkCUkbQNJ5baR8cz6LF9uZO9Sh9Tm8+iFIDlZSfvXDzskh/Cd0lYiFH6DkHyarhIrq4B4ogUw== |
written by Palaiologos
3 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import Data.List ( transpose, inits ) import Data.Function ( on ) import Control.Monad ( ap ) answer :: Int answer = 42 count :: (a -> Bool) -> [a] -> Int count = (length .) . filter whereInd :: [Bool] -> [Int] whereInd = map fst . filter snd . zip [0..] processSingle :: [[[Int]]] -> [Int] -> [Int] processSingle = (whereInd .) . ap (ap . (on (zipWith (||)) check .) . match) ((map transpose .) . match) where match = (foldl1 (zipWith (zipWith (zipWith (||)))) .) . map . flip (map . map . map . (==)) check = map (any ((5 ==) . count id)) entry :: [[[Int]]] -> [Int] -> Int entry = (head .) . (. (tail . inits)) . (=<<) . processSingle |
written by SoundOfSpouting
5 likes
1 2 | -- // Code by SoundOfSpouting#6980 (UID: 151149148639330304) import Data.List;entry p n=head$findIndices(\b->any(all(`elem`n))$b++transpose b++map(zipWith(!!)b)[[0..],[4,3..]])p |
post a comment