name | correct guesses | games together | ratio |
---|---|---|---|
seshoumara | 5 | 5 | 1.000 |
MattiDragon | 3 | 4 | 0.750 |
HelloBoi | 3 | 5 | 0.600 |
Kit | 2 | 4 | 0.500 |
ultlang | 2 | 4 | 0.500 |
Olivia | 15 | 31 | 0.484 |
olus2000 | 7 | 15 | 0.467 |
SoundOfSpouting | 4 | 9 | 0.444 |
kimapr | 3 | 7 | 0.429 |
Olive | 3 | 9 | 0.333 |
vspf | 1 | 4 | 0.250 |
kotnen | 1 | 4 | 0.250 |
deadbraincoral | 1 | 4 | 0.250 |
Palaiologos | 5 | 22 | 0.227 |
luatic | 2 | 9 | 0.222 |
BeatButton | 1 | 5 | 0.200 |
Camto | 1 | 5 | 0.200 |
gollark | 2 | 10 | 0.200 |
quintopia | 2 | 10 | 0.200 |
LyricLy | 6 | 35 | 0.171 |
IFcoltransG | 3 | 22 | 0.136 |
moshikoi | 1 | 11 | 0.091 |
sonata «pathétique» | 0 | 4 | 0.000 |
GNU Radio Shows | 0 | 12 | 0.000 |
soup girl | 0 | 10 | 0.000 |
JJRubes | 0 | 6 | 0.000 |
olive | 0 | 5 | 0.000 |
taswelll | 0 | 6 | 0.000 |
Edgex42 | 0 | 6 | 0.000 |
citrons | 0 | 4 | 0.000 |
name | correct guesses | games together | ratio |
---|---|---|---|
Kit | 2 | 4 | 0.500 |
seshoumara | 2 | 5 | 0.400 |
Camto | 2 | 5 | 0.400 |
GNU Radio Shows | 4 | 12 | 0.333 |
taswelll | 2 | 7 | 0.286 |
deadbraincoral | 1 | 4 | 0.250 |
SoundOfSpouting | 2 | 9 | 0.222 |
LyricLy | 8 | 37 | 0.216 |
Olivia | 6 | 30 | 0.200 |
quintopia | 2 | 10 | 0.200 |
Palaiologos | 3 | 20 | 0.150 |
soup girl | 1 | 8 | 0.125 |
Olive | 1 | 8 | 0.125 |
gollark | 1 | 9 | 0.111 |
moshikoi | 1 | 10 | 0.100 |
luatic | 1 | 10 | 0.100 |
IFcoltransG | 2 | 21 | 0.095 |
vspf | 0 | 4 | 0.000 |
kotnen | 0 | 4 | 0.000 |
BeatButton | 0 | 4 | 0.000 |
kimapr | 0 | 7 | 0.000 |
JJRubes | 0 | 6 | 0.000 |
olive | 0 | 5 | 0.000 |
ultlang | 0 | 4 | 0.000 |
olus2000 | 0 | 15 | 0.000 |
HelloBoi | 0 | 4 | 0.000 |
Edgex42 | 0 | 6 | 0.000 |
1 2 | #!/usr/bin/env bash wc -m $@ | cut -f 1 -d " " |
1 2 3 4 5 6 7 8 | import re def entry(haystack: str, needle: str) -> tuple[int, int] | None: final_matches = [] for i in range(len(haystack)): matches = re.finditer(("."*i).join(needle),haystack) for j in matches: final_matches.append((j.span()[0],i)) return final_matches or None |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | let f1=function(F1:number[]):number[]{let f2:number[][]=[]; let F2: number[]=[];for(let f3:number=0;f3<F1.length;f3++){ ;const F3: number = F1[f3]; let f4 : number [] =[];for(let f6=0;f6<f3;f6++){let F4=f2[f6]; var f5=F1[f6];if(f5<F3&&F4.length>f4.length ){;;f4= F4 ;}};;f2 [ +f3]=f4 .concat ();;;f2 [(f3)]. push(( F3));if (f2[f3] .length >((F2)) .length ){F2=(f2) [((f3))];}} return (F2);}; |
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 | /* ********* * JUDGE * ********* * Order, order in the room please. * Good Morning, ladies and gentlemen. Calling the case of the People of the * State of Esolangs versus Database Admin. Are both sides ready? */ /* ********************* * DISTRICT ATTORNEY * ********************* * Ready for the People, Your Honour. */ /* ******************* * PUBLIC DEFENDER * ******************* * Ready for the defense, Your Honour. */ /* ********* * JUDGE * ********* * Will the clerk please swear in the jury? */ /* ********* * CLERK * ********* * Will the jury please stand and raise your right hand? [Wait for * everyone to stand.] Do each of you swear that you will fairly try the * case before this court, and that you will return a true verdict according to * the evidence and the instructions of the court, so help you, God? Please * say “I do”. [Wait for jurors to say “I do.”] You may be seated. */ /* ********************* * DISTRICT ATTORNEY * ********************* * Your Honor and ladies and gentlemen of the jury: the defendant has been * charged with the act of the segregation of candidate keys from their natural * habitat. The evidence will show that a group of table keys were racially * profiled on the night of October 22nd. The next day the defendant was * arrested teaching the rules of apartheid segregation to the "superior" and * "unique" keys on October 29th. The evidence I will present to you will prove * that the defendant is guilty as charged. */ /* ******************* * PUBLIC DEFENDER * ******************* * Your Honor and ladies and gentlemen of the jury: under the law my client is * presumed innocent until proved guilty. During this trial, you will hear no * real evidence against my client. You will come to know the truth: that my * client was just performing the duties of his paid job with no ulterior * motives. * Therfore my client is not guilty. */ let hearing = (table) => { /* ********* * JUDGE * ********* * The prosecution may call its first witness. */ /* ********************* * DISTRICT ATTORNEY * ********************* * The people call the Back End of the table. */ /* ********* * CLERK * ********* * Please stand. Raise your right hand. Do you promise that the * testimony you shall give in the case before this court shall be the truth, * the whole truth, and nothing but the truth, so help you God? */ /* ********************* * DISTRICT ATTORNEY * ********************* * The people call the Back End of the table. */ /* ************ * BACK END * ************ * I do. */ /* ********* * CLERK * ********* * Please state your first and last name. */ /* ************ * BACK END * ************ * Relationah Aljabrah. */ /* ********* * CLERK * ********* * You may be seated. */ /* ********************* * DISTRICT ATTORNEY * ********************* * Please state the details of the crime as you saw it on the 22nd of October. */ /* ************ * BACK END * ************ * i was out there mindin my own business when i noticed half my friends * was missin! */ /* ********************* * DISTRICT ATTORNEY * ********************* * From this anecdote, we can conclude that the defendant was performing * an obstruction to the task of the BACK END worker, who was also * a witness to the crime. */ /* ********************* * DISTRICT ATTORNEY * ********************* * As the record may be seen in paragraph 5, your honour, there is a * stark "special casing" requirement in the code for the current hearing. * This has been addressed in the below transcript. */ if (table.length <= 2) { return [[]]; } /* ********************* * DISTRICT ATTORNEY * ********************* * As the jury may be able to see, this "candidate key extraction" * was a premeditated crime. The perpetrators of the crime had their * target columns decided many lines before the time of return. */ let col_names = table[0]; let table_rows = table.slice(1); let candidate_keys = (col_indices, rows) => { /* ******************* * PUBLIC DEFENDER * ******************* * The given claims from the People, your honour, are false, * as my client has an alibi during the time of crime. * The number of columns for the table was also a stark * "special case", preventing such a selection from happening! */ if (col_indices.length > 1) { let result_keys = []; for(let i = 0; i < col_indices.length; i++) { let recur_col_indices = col_indices.slice(); recur_col_indices.splice(i,1); /* ********* * JUDGE * ********* * The jury is thanked and excused for the session. * Court is adjourned, as we lack the stack frames to continue. */ let result_iter = candidate_keys(recur_col_indices, rows); for (let j = 0; j < result_iter.length; j++) { result_keys.push(result_iter[j]); } } if (result_keys.length > 0) { return result_keys; } } let selected_rows = []; for (let i = 0; i < rows.length; i++) { let curr_row = []; for (let j = 0; j < col_indices.length; j++) { curr_row.push(rows[i][col_indices[j]]); } selected_rows.push(curr_row); } for (let i = 0; i < selected_rows.length; i++) { for (let j = 0; j < selected_rows.length; j++) { if (i != j) { if (selected_rows[i].length == selected_rows[j].length) { let is_equal = true; for(let k = 0; k < selected_rows[i].length; k++) { if (selected_rows[i][k] != selected_rows[j][k]) { is_equal = false; break; } } if (is_equal) { return []; } } } } } return [col_indices]; } let range = []; for (let i = 0; i < table_rows[0].length; i++) { range.push(i); } let candidate_key_indices = candidate_keys(range, table_rows); let unique_candidate_keys = []; for (let i = 0; i < candidate_key_indices.length; i++) { let isnt_added = true; for(let j = 0; j < unique_candidate_keys.length; j++) { let is_equal = true; if (candidate_key_indices[i].length == unique_candidate_keys[j].length) { for (let k = 0; k < candidate_key_indices.length; k++) { if (candidate_key_indices[i][k] != unique_candidate_keys[j][k]) { is_equal = false; break; } } } else { is_equal = false; } if (is_equal) { isnt_added = false; break; } } if (isnt_added) { unique_candidate_keys.push(candidate_key_indices[i]); } } for (let i = 0; i < unique_candidate_keys.length; i++) { for (let j = 0; j < unique_candidate_keys[i].length; j++) { unique_candidate_keys[i][j] = col_names[unique_candidate_keys[i][j]]; } } return unique_candidate_keys; }; |
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 | // right into the wall socket 🥺 extension String: Error {} let verbose: Bool = CommandLine.arguments.last == "-v" func display(board: [[Int]]) { for (index, row) in board.enumerated() { for col in row { print("│",terminator:"") if col == 0 { print(" ",terminator:"") } else if col == 1 { print("①",terminator:"") } else { print("❶",terminator:"") } } print("│") if index == 5 { print("└─┴─┴─┴─┴─┴─┴─┘") } else { print("├─┼─┼─┼─┼─┼─┼─┤") } } } func move(board: inout [[Int]], depth: inout [Int], player: Int, col: Int) { board[depth[col]][col] = player depth[col] -= 1 } func win(board: [[Int]], depth: [Int], player: Int, col: Int) -> Bool { for (moveRow, moveCol) in [(0,1),(1,0),(-1,0),(0,-1),(1,1),(1,-1),(-1,-1),(-1,1)]{ if (0..<4).allSatisfy({board[depth[col] + $0 * moveRow][col + $0 * moveCol] == player}) { return true } } return false } var board: [[Int]] = [[Int]](repeating: [Int](repeating: 0, count: 7), count: 6) var depth: [Int] = [Int](repeating: 5, count: 7) var lPlayer: Int = 2 var lMove: Int = 0 if "f" == readLine() { let cMove: Int = (0..<7).filter({depth[$0] > 0}).randomElement()! print(cMove+1) move(board: &board, depth: &depth, player: 2, col: cMove) lPlayer = 2 lMove = cMove } while !win(board: board, depth: depth, player: lPlayer, col: lMove) { switch lPlayer { case 2: if verbose { print("Enter move: ", terminator: "") } if let StrMove = readLine() { if let tMove = Int(StrMove) { lMove = tMove-1 } } else { if verbose { print("invalid move! :3") } continue } if depth[lMove] == 0 { if verbose { print("Column \(lMove) is full.") } continue } move(board: &board, depth: &depth, player: 1, col: lMove) lPlayer = 1 case 1: if verbose { print("Computer move: ", terminator: "") } let cMove: Int = (0..<7).filter({depth[$0] > 0}).randomElement()! print(cMove+1) if verbose { display(board: board) } move(board: &board, depth: &depth, player: 2, col: cMove) lPlayer = 2 lMove = cMove default: print("zoinks!") throw "oopsies!" } } switch lPlayer { case 1: print("You Win!") case 2: print("Computer Wins!") default: print("]¥ÍH›ØáôPS Wins!") } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from manim import * class e(Scene): def construct(self): r=float(input("r = ")) R=float(input("R = ")) d=float(input("d = ")) d/=r p=ValueTracker(0) C=Circle(radius=R) c=always_redraw(lambda:VGroup(Circle(radius=abs(r),color=GREEN),Dot().shift(abs(d*r)*RIGHT),Dot(),Line().set_length(d*r).shift(0.5*d*r*RIGHT)).rotate(p.get_value(),about_point=ORIGIN).move_to(C.get_center()).shift((R+r)*RIGHT).rotate(abs(r/R)*p.get_value(),about_point=C.get_center())) t=TracedPath(c[1].get_center) self.play(Create(C)) self.play(Create(c)) self.add(t) self.play(p.animate.set_value(20*PI), run_time=10, rate_func=rate_functions.linear) self.wait() with tempconfig({"quality": "medium_quality", "preview": True}): scene=e() scene.render() |
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 | title 2048 author Friedrich Nietzsche homepage www.puzzlescript.net ======== OBJECTS ======== Background #bbada0 Empty #bbada0 Two #eee4da #776e65 #bbada0 20000 20000 20000 20010 22222 Four #eee1c9 #776e65 #bbada0 20000 20000 20000 20100 22222 Eight #f3b27a #f9f6f2 #bbada0 20000 20000 20000 21000 22222 Sixteen #f69664 #f9f6f2 #bbada0 20000 20000 20001 20000 22222 ThirtyTwo #f77c5f #f9f6f2 #bbada0 20000 20000 20010 20000 22222 SixtyFour #f75f3b #f9f6f2 #bbada0 20000 20000 20100 20000 22222 OneTwoEight #edcf72 #f9f6f2 #bbada0 20000 20000 21000 20000 22222 TwoFiveSix #edcc61 #f9f6f2 #bbada0 20000 20001 20000 20000 22222 FiveOneTwo #edc850 #f9f6f2 #bbada0 20000 20010 20000 20000 22222 OneZeroTwoFour #edc53f #f9f6f2 #bbada0 20000 20100 20000 20000 22222 TwoZeroFourEight #edc22e #f9f6f2 #bbada0 20000 21000 20000 20000 22222 ======= LEGEND ======= . = Background E = Empty 2 = Two Spawn = Two or Four Player = Two and Four and Eight and Sixteen and ThirtyTwo and SixtyFour and OneTwoEight and TwoFiveSix and FiveOneTwo and OneZeroTwoFour and TwoZeroFourEight ======= SOUNDS ======= ================ COLLISIONLAYERS ================ Background Empty Two Four Eight Sixteen ThirtyTwo SixtyFour OneTwoEight TwoFiveSix FiveOneTwo OneZeroTwoFour TwoZeroFourEight ====== RULES ====== [ > Two | Empty ] -> [ Empty | > Two ] [ > Four | Empty ] -> [ Empty | > Four ] [ > Eight | Empty ] -> [ Empty | > Eight ] [ > Sixteen | Empty ] -> [ Empty | > Sixteen ] [ > ThirtyTwo | Empty ] -> [ Empty | > ThirtyTwo ] [ > SixtyFour | Empty ] -> [ Empty | > SixtyFour ] [ > OneTwoEight | Empty ] -> [ Empty | > OneTwoEight ] [ > TwoFiveSix | Empty ] -> [ Empty | > TwoFiveSix ] [ > FiveOneTwo | Empty ] -> [ Empty | > FiveOneTwo ] [ > OneZeroTwoFour | Empty ] -> [ Empty | > OneZeroTwoFour ] [ > TwoZeroFourEight | Empty ] -> [ Empty | > TwoZeroFourEight ] [ > Two | Four ] -> [ Two | Four ] [ > Two | Eight ] -> [ Two | Eight ] [ > Two | Sixteen ] -> [ Two | Sixteen ] [ > Two | ThirtyTwo ] -> [ Two | ThirtyTwo ] [ > Two | SixtyFour ] -> [ Two | SixtyFour ] [ > Two | OneTwoEight ] -> [ Two | OneTwoEight ] [ > Two | TwoFiveSix ] -> [ Two | TwoFiveSix ] [ > Two | FiveOneTwo ] -> [ Two | FiveOneTwo ] [ > Two | OneZeroTwoFour ] -> [ Two | OneZeroTwoFour ] [ > Two | TwoZeroFourEight ] -> [ Two | TwoZeroFourEight ] [ > Four | Two ] -> [ Four | Two ] [ > Four | Eight ] -> [ Four | Eight ] [ > Four | Sixteen ] -> [ Four | Sixteen ] [ > Four | ThirtyTwo ] -> [ Four | ThirtyTwo ] [ > Four | SixtyFour ] -> [ Four | SixtyFour ] [ > Four | OneTwoEight ] -> [ Four | OneTwoEight ] [ > Four | TwoFiveSix ] -> [ Four | TwoFiveSix ] [ > Four | FiveOneTwo ] -> [ Four | FiveOneTwo ] [ > Four | OneZeroTwoFour ] -> [ Four | OneZeroTwoFour ] [ > Four | TwoZeroFourEight ] -> [ Four | TwoZeroFourEight ] [ > Eight | Two ] -> [ Eight | Two ] [ > Eight | Four ] -> [ Eight | Four ] [ > Eight | Sixteen ] -> [ Eight | Sixteen ] [ > Eight | ThirtyTwo ] -> [ Eight | ThirtyTwo ] [ > Eight | SixtyFour ] -> [ Eight | SixtyFour ] [ > Eight | OneTwoEight ] -> [ Eight | OneTwoEight ] [ > Eight | TwoFiveSix ] -> [ Eight | TwoFiveSix ] [ > Eight | FiveOneTwo ] -> [ Eight | FiveOneTwo ] [ > Eight | OneZeroTwoFour ] -> [ Eight | OneZeroTwoFour ] [ > Eight | TwoZeroFourEight ] -> [ Eight | TwoZeroFourEight ] [ > Sixteen | Two ] -> [ Sixteen | Two ] [ > Sixteen | Four ] -> [ Sixteen | Four ] [ > Sixteen | Eight ] -> [ Sixteen | Eight ] [ > Sixteen | ThirtyTwo ] -> [ Sixteen | ThirtyTwo ] [ > Sixteen | SixtyFour ] -> [ Sixteen | SixtyFour ] [ > Sixteen | OneTwoEight ] -> [ Sixteen | OneTwoEight ] [ > Sixteen | TwoFiveSix ] -> [ Sixteen | TwoFiveSix ] [ > Sixteen | FiveOneTwo ] -> [ Sixteen | FiveOneTwo ] [ > Sixteen | OneZeroTwoFour ] -> [ Sixteen | OneZeroTwoFour ] [ > Sixteen | TwoZeroFourEight ] -> [ Sixteen | TwoZeroFourEight ] [ > ThirtyTwo | Two ] -> [ ThirtyTwo | Two ] [ > ThirtyTwo | Four ] -> [ ThirtyTwo | Four ] [ > ThirtyTwo | Eight ] -> [ ThirtyTwo | Eight ] [ > ThirtyTwo | Sixteen ] -> [ ThirtyTwo | Sixteen ] [ > ThirtyTwo | SixtyFour ] -> [ ThirtyTwo | SixtyFour ] [ > ThirtyTwo | OneTwoEight ] -> [ ThirtyTwo | OneTwoEight ] [ > ThirtyTwo | TwoFiveSix ] -> [ ThirtyTwo | TwoFiveSix ] [ > ThirtyTwo | FiveOneTwo ] -> [ ThirtyTwo | FiveOneTwo ] [ > ThirtyTwo | OneZeroTwoFour ] -> [ ThirtyTwo | OneZeroTwoFour ] [ > ThirtyTwo | TwoZeroFourEight ] -> [ ThirtyTwo | TwoZeroFourEight ] [ > SixtyFour | Two ] -> [ SixtyFour | Two ] [ > SixtyFour | Four ] -> [ SixtyFour | Four ] [ > SixtyFour | Eight ] -> [ SixtyFour | Eight ] [ > SixtyFour | Sixteen ] -> [ SixtyFour | Sixteen ] [ > SixtyFour | ThirtyTwo ] -> [ SixtyFour | ThirtyTwo ] [ > SixtyFour | OneTwoEight ] -> [ SixtyFour | OneTwoEight ] [ > SixtyFour | TwoFiveSix ] -> [ SixtyFour | TwoFiveSix ] [ > SixtyFour | FiveOneTwo ] -> [ SixtyFour | FiveOneTwo ] [ > SixtyFour | OneZeroTwoFour ] -> [ SixtyFour | OneZeroTwoFour ] [ > SixtyFour | TwoZeroFourEight ] -> [ SixtyFour | TwoZeroFourEight ] [ > OneTwoEight | Two ] -> [ OneTwoEight | Two ] [ > OneTwoEight | Four ] -> [ OneTwoEight | Four ] [ > OneTwoEight | Eight ] -> [ OneTwoEight | Eight ] [ > OneTwoEight | Sixteen ] -> [ OneTwoEight | Sixteen ] [ > OneTwoEight | ThirtyTwo ] -> [ OneTwoEight | ThirtyTwo ] [ > OneTwoEight | SixtyFour ] -> [ OneTwoEight | SixtyFour ] [ > OneTwoEight | TwoFiveSix ] -> [ OneTwoEight | TwoFiveSix ] [ > OneTwoEight | FiveOneTwo ] -> [ OneTwoEight | FiveOneTwo ] [ > OneTwoEight | OneZeroTwoFour ] -> [ OneTwoEight | OneZeroTwoFour ] [ > OneTwoEight | TwoZeroFourEight ] -> [ OneTwoEight | TwoZeroFourEight ] [ > TwoFiveSix | Two ] -> [ TwoFiveSix | Two ] [ > TwoFiveSix | Four ] -> [ TwoFiveSix | Four ] [ > TwoFiveSix | Eight ] -> [ TwoFiveSix | Eight ] [ > TwoFiveSix | Sixteen ] -> [ TwoFiveSix | Sixteen ] [ > TwoFiveSix | ThirtyTwo ] -> [ TwoFiveSix | ThirtyTwo ] [ > TwoFiveSix | SixtyFour ] -> [ TwoFiveSix | SixtyFour ] [ > TwoFiveSix | OneTwoEight ] -> [ TwoFiveSix | OneTwoEight ] [ > TwoFiveSix | FiveOneTwo ] -> [ TwoFiveSix | FiveOneTwo ] [ > TwoFiveSix | OneZeroTwoFour ] -> [ TwoFiveSix | OneZeroTwoFour ] [ > TwoFiveSix | TwoZeroFourEight ] -> [ TwoFiveSix | TwoZeroFourEight ] [ > FiveOneTwo | Two ] -> [ FiveOneTwo | Two ] [ > FiveOneTwo | Four ] -> [ FiveOneTwo | Four ] [ > FiveOneTwo | Eight ] -> [ FiveOneTwo | Eight ] [ > FiveOneTwo | Sixteen ] -> [ FiveOneTwo | Sixteen ] [ > FiveOneTwo | ThirtyTwo ] -> [ FiveOneTwo | ThirtyTwo ] [ > FiveOneTwo | SixtyFour ] -> [ FiveOneTwo | SixtyFour ] [ > FiveOneTwo | OneTwoEight ] -> [ FiveOneTwo | OneTwoEight ] [ > FiveOneTwo | TwoFiveSix ] -> [ FiveOneTwo | TwoFiveSix ] [ > FiveOneTwo | OneZeroTwoFour ] -> [ FiveOneTwo | OneZeroTwoFour ] [ > FiveOneTwo | TwoZeroFourEight ] -> [ FiveOneTwo | TwoZeroFourEight ] [ > OneZeroTwoFour | Two ] -> [ OneZeroTwoFour | Two ] [ > OneZeroTwoFour | Four ] -> [ OneZeroTwoFour | Four ] [ > OneZeroTwoFour | Eight ] -> [ OneZeroTwoFour | Eight ] [ > OneZeroTwoFour | Sixteen ] -> [ OneZeroTwoFour | Sixteen ] [ > OneZeroTwoFour | ThirtyTwo ] -> [ OneZeroTwoFour | ThirtyTwo ] [ > OneZeroTwoFour | SixtyFour ] -> [ OneZeroTwoFour | SixtyFour ] [ > OneZeroTwoFour | OneTwoEight ] -> [ OneZeroTwoFour | OneTwoEight ] [ > OneZeroTwoFour | TwoFiveSix ] -> [ OneZeroTwoFour | TwoFiveSix ] [ > OneZeroTwoFour | FiveOneTwo ] -> [ OneZeroTwoFour | FiveOneTwo ] [ > OneZeroTwoFour | TwoZeroFourEight ] -> [ OneZeroTwoFour | TwoZeroFourEight ] [ > TwoZeroFourEight | Two ] -> [ TwoZeroFourEight | Two ] [ > TwoZeroFourEight | Four ] -> [ TwoZeroFourEight | Four ] [ > TwoZeroFourEight | Eight ] -> [ TwoZeroFourEight | Eight ] [ > TwoZeroFourEight | Sixteen ] -> [ TwoZeroFourEight | Sixteen ] [ > TwoZeroFourEight | ThirtyTwo ] -> [ TwoZeroFourEight | ThirtyTwo ] [ > TwoZeroFourEight | SixtyFour ] -> [ TwoZeroFourEight | SixtyFour ] [ > TwoZeroFourEight | OneTwoEight ] -> [ TwoZeroFourEight | OneTwoEight ] [ > TwoZeroFourEight | TwoFiveSix ] -> [ TwoZeroFourEight | TwoFiveSix ] [ > TwoZeroFourEight | FiveOneTwo ] -> [ TwoZeroFourEight | FiveOneTwo ] [ > TwoZeroFourEight | OneZeroTwoFour ] -> [ TwoZeroFourEight | OneZeroTwoFour ] [ > Two | Two ] -> [ Empty | Four ] [ > Four | Four ] -> [ Empty | Eight ] [ > Eight | Eight ] -> [ Empty | Sixteen ] [ > Sixteen | Sixteen ] -> [ Empty | ThirtyTwo ] [ > ThirtyTwo | ThirtyTwo ] -> [ Empty | SixtyFour ] [ > SixtyFour | SixtyFour ] -> [ Empty | OneTwoEight ] [ > OneTwoEight | OneTwoEight ] -> [ Empty | TwoFiveSix ] [ > TwoFiveSix | TwoFiveSix ] -> [ Empty | FiveOneTwo ] [ > FiveOneTwo | FiveOneTwo ] -> [ Empty | OneZeroTwoFour ] [ > OneZeroTwoFour | OneZeroTwoFour ] -> [ Empty | TwoZeroFourEight ] random [ Empty ] -> [ random Spawn ] ============== WINCONDITIONS ============== Some TwoZeroFourEight ======= LEVELS ======= 2EEE EEEE EEEE EEEE |
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 | " Made In Emacs " Tested In VIM - Vi IMproved 8.1 " Open File " Enter Insert Mode, Type In Your Program " Enter Normal Mode, Type :so sotrue.vim<RET> " Nested Comments Are Supported let program = join(getline(1, '$'), "\n") " remove comments and find strings let s:index = 0 let s:tokens = [] while s:index < program->len() let item = program[s:index] if item == '{' " comment '{' let start = s:index let depth = 1 let s:index = s:index + 1 while depth != 0 " close comment '}' let depth = depth + (program[s:index] == '{') - (program[s:index] == '}') let s:index = s:index + 1 endwhile let s:index = s:index - 1 elseif item == '"' " string '"' let start = s:index + 1 let s:index = s:index + 1 while program[s:index] != '"' let s:index = s:index + 1 endwhile let s:tokens = s:tokens->add(["print",program[start:s:index-1]]) elseif item =~# '\d' let num = 0 while program[s:index] =~# '\d' let num = num * 10 + str2nr(program[s:index]) let s:index = s:index + 1 endwhile let s:index = s:index - 1 let s:tokens = s:tokens->add(["num",num]) elseif item == "'" let s:tokens = s:tokens->add(["num",char2nr(program[s:index + 1])]) let s:index = s:index + 1 elseif item == '[' || item == ']' let s:tokens = s:tokens->add(["sq",program[s:index:s:index]]) elseif item =~# '[a-z]' let s:tokens = s:tokens->add(["var",program[s:index:s:index]]) elseif item =~# '\s' else let s:tokens = s:tokens->add(["cmd",program[s:index:s:index]]) endif let s:index = s:index + 1 endwhile " parse quotations let s:stk = [] let s:topquot = [] for [type,data] in s:tokens if type == "sq" && data == "[" let s:stk = add(s:stk, s:topquot) let s:topquot = [] elseif type == "sq" && data == "]" let tmp = remove(s:stk, -1) let s:topquot = add(tmp,["quot",s:topquot]) " pop from stk, add topquot to it, add it to top quot else let s:topquot = add(s:topquot, [type,data]) endif endfor " run the program let s:plen = len(s:topquot) let s:pptrs = [] " program pointers let s:cstk = [] " call stack let s:vars = {} " variables in the FALSE program let s:cptr = 0 " current execution point let s:cprg = s:topquot " current quotation to execute, starting at full program " for while mainly let s:mode = "exec" let s:sndq = [] " stores quote for while loop let s:mstk = [] while s:cptr < s:plen if s:cptr >= len(s:cprg) " handle quots if s:mode == "whilecond" if remove(s:mstk, -1) != 0 let temp = s:cprg let s:cprg = s:sndq let s:sndq = temp let s:cptr = -1 let s:mode = "whilebody" else " lower level of nesting. let [mo,cp,pr,sn] = remove(s:cstk, -1) let s:mode = mo let s:cptr = cp let s:cprg = pr let s:sndq = sn endif elseif s:mode == "whilebody" let temp = s:cprg let s:cprg = s:sndq let s:sndq = temp let s:cptr = -1 let s:mode = "whilecond" elseif s:mode == "exec" let [mo,cp,pr,sn] = remove(s:cstk, -1) let s:mode = mo let s:cptr = cp let s:cprg = pr let s:sndq = sn endif else let [type, data] = s:cprg[s:cptr] if type == 'cmd' if data == ';' let a = remove(s:mstk, -1) call add(s:mstk, vars[a]) elseif data == ':' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) let s:vars[a] = b elseif data == '$' call add(s:mstk, deepcopy(s:mstk[-1])) elseif data == '%' call remove(s:mstk, -1) elseif data == '\' let s:mstk[-2:-1] = reverse(s:mstk[-2:-1]) elseif data == '@' call add(s:mstk,remove(s:mstk,-3)) elseif data == 'O' let a = remove(s:mstk, -1) call add(s:mstk,deepcopy(s:mstk[a])) elseif data == '+' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk,a+b) elseif data == '-' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk,a-b) elseif data == '*' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk,a*b) elseif data == '/' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk,a/b) elseif data == '_' call add(s:mstk,-remove(s:mstk,-1)) elseif data == '&' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk,str2nr(system($"echo $(({a}&{b}))"))) elseif data == '|' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk,str2nr(system($"echo $(({a}|{b}))"))) elseif data == '~' let a = remove(s:mstk, -1) call add(s:mstk,str2nr(system($"echo $((~{a}))"))) elseif data == '=' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk, a == b ? -1 : 0) elseif data == '>' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:mstk, b > a ? -1 : 0) elseif data == '!' call add(s:cstk, [s:mode, s:cptr, copy(s:cprg), copy(s:sndq)]) let s:mode = "exec" let s:cptr = -1 let s:cond = [] let s:cprg = remove(s:mstk, -1) elseif data == '?' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) if a != 0 call add(s:cstk, [s:mode, s:cptr, copy(s:cprg), copy(s:sndq)]) let s:mode = "exec" let s:cptr = -1 let s:cond = [] let s:cprg = a endif elseif data == '#' let a = remove(s:mstk, -1) let b = remove(s:mstk, -1) call add(s:cstk, [s:mode, s:cptr, copy(s:cprg), copy(s:sndq)]) let s:mode = "whilecond" let s:cptr = -1 let s:sndq = a let s:cprg = b elseif data == '^' call add(s:mstk, getchar()) elseif data == ',' echo nr2char(remove(s:mstk, -1)) elseif data == '.' echo remove(s:mstk, -1) else throw 'Invalid Instruction' + data endif elseif type == 'var' call add(s:mstk, data) elseif type == 'quot' call add(s:mstk, data) elseif type == 'num' call add(s:mstk, data) elseif type == 'print' echon data else endif endif let s:cptr = s:cptr + 1 endwhile |
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 | # Brain-flak interpreter in Python # soon to be added: proper debugging capability # Flakhead society approved def read_until_matching(s, start): stack_height = 0 for idx, char in enumerate(s[start + 1 :]): match char: case "{": stack_height += 1 case "}": stack_height -= 1 if stack_height == -1: return idx + start + 1 return False class Interpreter: left = [] right = [] main = [] active = left index = 0 current_value = 0 running = False def reset(self): self.left = [] self.right = [] self.main = [] self.active = self.left self.index = 0 self.current_value = 0 self.running = False def __init__(self, source): self.source = source def step(self): if not self.running: return False is_nilad = True match self.source[self.index : self.index + 2]: case "()": self.current_value += 1 case "[]": self.current_value += len(self.active) case "{}": if self.active: self.current_value += self.active.pop() case "<>": self.active = self.right if self.active == self.left else self.left case _: is_nilad = False if is_nilad: self.index += 2 else: match self.source[self.index]: case "(": self.main.append(("(", self.current_value, self.index)) self.current_value = 0 case "[": self.main.append(("[", self.current_value, self.index)) self.current_value = 0 case "{": self.main.append(("{", 0, self.index)) new_index = read_until_matching(self.source, self.index) if not self.active or self.active[-1] == 0: self.main.pop() self.index = new_index case "<": self.main.append(("<", self.current_value, self.index)) self.current_value = 0 case ")": _, inc, _ = self.main.pop() self.active.append(self.current_value) self.current_value += inc case "]": _, inc, _ = self.main.pop() self.current_value *= -1 self.current_value += inc case "}": _, inc, idx = self.main.pop() self.index = idx - 1 self.current_value += inc case ">": _, inc, _ = self.main.pop() self.current_value = inc self.index += 1 if self.index >= len(self.source): self.running = False return True def run(self, input): self.reset() self.left = input self.active = self.left self.running = True while self.running: self.step() return self.active for code, input in [ ("(([]){[{}]{}([])}{})", [5, 69, 700, 8214]), # sum stack ("({}{})", [0x12, 123]), # add two numbers ("(())", []), # 1 ("<>((()))<>{({}[()])<>({}<>)<>(({})<>({}<>))<>}<>{}{}", [9]), # Fibonacci # ('(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()())(()()()())(()()()()()()()())(()()())(()()()())(())(()()()()())(()()()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(())(()()()()())(()()()()()()())(()()()()()()()())(()()()()()())(())(()())(()()())(())(())(())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(()())(()()())(()()()())(()())(()())(())(()())(()())(()())(()()()())(()())(()()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(()()())(())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(()()())(())(()()()()()()())(()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(()())(()())(()()()()()()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(()()())(())(()()()()()()())(()()()()()()()())(())(()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(()()())(())(()()()()()()())(()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(()()())(())(()()()()()()())(()()()()()()()())(())(()())(())(()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(()()())(())(()()()()()()())(()()()()()()()())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()()()()()()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()())(()()()()()()())(()()()()()()()())(()())(()()()())(()())(()()()()()()())(())(()()())(()()()()()()())(()()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(())(()())(()())(()()()())(()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()()())(()()()()()()())(()()()()()()()())(())(()()()()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()())(()()()())(()()()()()()()())(()()())(()()()())(()()()())(()())(()()()())(()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()())(()()()())(()()()())(()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()()())(())(()()()()()()())(()()()()()()()())(())(()())(()()())(())(())(())(()()()()()()())(()()()()()()()())(()()()()())(())(()())(()()()()()())(()())(())(()())(()())(()())(()()()())(()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()()())(()()()())(()()()())(()())(()()()()()()()())(()()()()()()())(()()()()()()()())(()()()()()()())(()()())(()()()())(())(()()()()()()())(()()()()()()()())(()()())(()()()())(()())(()()()()()()()()){({}<>)<>}<>([]){({}[()]<(([{}]()<((((((((()()()()()){}){}){})<>))()))>)<>){({}()<({}())>){({}()<({}(((()()())){}{}){}())>){({}()<({}()())>){({}()<({}(((()()()){}()){}){}())>){({}()<({}()())>){({}()<({}(((()()()()())){}{}){})>){(<{}({}()())>)}}}}}}}{}([]<({}<{({}<>)<>}<>>)>){({}[()]<({}<>)<>>)}{}{({}()<((({}[()])()))>)}{}<>>)}{}{<>({}<>)}', []) ]: print(Interpreter(code).run(input)) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | entry = exp => { prec = 0 while(isNaN(exp)){ texp = "" spc = " ".repeat(prec) rspc = new RegExp("-?\\d"+spc+"[+\\-\\/*]"+spc+"-?\\d") do { texp = exp exp = exp.replace(rspc, (exp, _a, _b, _c, _d, _e, _f, _g) => eval(exp)) } while (exp != texp) prec++ } return exp } console.log("9 / 1+2 - 1 / 2 -> "+entry("9 / 1+2 - 1 / 2")) console.log("0-6 * 2 -> "+entry("0-6 * 2")) console.log("4 / 1 + 1 -> "+entry("4 / 1 + 1")) console.log("2-4/2 -> "+entry("2-4/2")) console.log("-4 -> "+entry("-4")) console.log("34 -> "+entry("34")) console.log("1 / 0 -> "+entry("1 / 0")) console.log("9*9*9*9*9*9*9*9*9*9 -> "+entry("9*9*9*9*9*9*9*9*9*9")) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> int main() { int i, radix; scanf("%d%d", &i, &radix); while(i % radix != i) { int tmp = i; int sum = 0; while(tmp) { sum = sum + tmp % radix; tmp = tmp / radix; } i = sum; } printf("%d\n", i); } |
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 | 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz |
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 | ca/ 0000775 0001750 0001751 00000000000 14372132716 011674 5 ustar razetime razetime ca/src/ 0000775 0001750 0001751 00000000000 14371746062 012467 5 ustar razetime razetime ca/src/main.rs 0000664 0001750 0001751 00000002272 14372132231 013750 0 ustar razetime razetime use rand::prelude::*; fn maze(w: usize, h: usize) -> Vec<bool> { let mut vec = (0..w * h) .into_iter() .map(|_| -> bool { random() }) .collect::<Vec<bool>>(); for _ in 0..100 { let mut next = vec![false; w * h]; for i in 0..(w * h) { let mut count = 0; for j in [ vec.get(i - w - 1), vec.get(i - w), vec.get(i - w + 1), vec.get(i - 1), vec.get(i + 1), vec.get(i + w - 1), vec.get(i + w), vec.get(i + w + 1), ] { match j { Some(true) => count += 1, _ => (), } } if vec[i] { next[i] = count >= 1 && count <= 5; } else { next[i] = count == 3; } } vec = next; } return vec; } fn main() { let res = maze(10, 10); for (i, j) in res.iter().enumerate() { if *j { print!("#") } else { print!(" ") } if (i + 1) % 10 == 0 { println!("") } } } ca/Cargo.toml 0000664 0001750 0001751 00000000272 14371746741 013635 0 ustar razetime razetime [package] name = "ca" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] rand = "0.8.5" |
1 2 3 4 5 6 7 8 9 10 11 12 | import re def entry(terrain): str = '' for i in range(max(terrain)): for j in range(len(terrain)): if i < terrain[j]: str += '#' else: str += ' ' str += '\n' collected,_ = re.subn('# +#', lambda match: match.group(0).replace(' ','@'), str) return collected.count('@') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import Data.List import Data.Maybe import qualified Data.IntMap.Strict as IM entry :: [[Bool]] -> Int -> Int -> [Int] entry mat a b = fromJust $ entry' (adjToMap mat) a b [] entry' :: IM.IntMap [Int] -> Int -> Int -> [Int] -> Maybe [Int] entry' graph a b visited | a == b = Just [b] | next == [] = Nothing | a /= b = Just $ (:) a $ fromJust $ fromJust $ find isJust $ map (\x -> entry' graph x b (a : visited)) next where next = fromJust (IM.lookup a graph) \\ visited adjToMap :: [[Bool]] -> IM.IntMap [Int] adjToMap mat = IM.fromList [(idx, [ v | (True, v) <- zip row [0..]]) | (idx, row) <- zip [0..] mat] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | class Entry: def __init__(self): self.keys = [] self.values = [] def get(self, key, default=None): for i in range(len(self.keys)): if len(str(self.keys[i])) == len(str(key)): if self.keys[i] == key: return self.values[i] return default def insert(self, key, value): if key in self.keys: self.values[self.keys.index(key)] = value else: self.keys.append(key) self.values.append(value) |
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 | # // Code by SoundOfSpouting#6980 (UID: 151149148639330304) # /* hemorrhoids # * # * Copyright (C) Kamila Szewczyk, 2017-2021. # * License: MIT # * # * 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 CUCKED", 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. # */ # /* # * -------------------------------------------------------------------------------------------------------------------------- # * A VERY VERY IMPORTANT NOTE! THIS FILE MAY SEEM OBFUSCATED OR OVERALL UNREADABLE. HERE'S WHY. # * Back in the day when I started the hemorrhoids project (early 2017), I thought that I'd write this reference implementation, # * and then write an hemorrhoids version of it, so that my self compiler actually runs the project. # * Later on, I thought that I'll rather write hemorrhoids in C(pip install playsound), so I froze the hemorrhoids self compiler in v0.9 and started to tweak # * this program, that was meant to be the reference implementation. # * There's no need for running away in terror, as the most of the code is just parsing the input and outputting the premade # * instruction microcode in the `s' string, containing instruction names and the microcode. # * Actually, this file is terrifying, threatening, because it is written in dirac. No FALSE speech will be tolerated. Fear it. # */ import sys as y av = y.argv if len(av) > 1: v1 = av[1] try: v2 = eval(v1) except SyntaxError: pass import os import re import functools as ft import string as st import copy as cp import random as rd import math as m from turtle import * from PIL import Image from playsound import playsound ri = rd.randint rt = lambda seq: seq[ri(0, len(seq)-1)] N = None _i = __import__ _b = __builtins__ _B = dir(_b) ab = abs al = all an = any bn = bin c = chr cx = complex d = dict dr = dir em = enumerate e = eval x = exec b = lambda x: lambda y: eval(x) fm = lambda x,y: map(b(x),y) ff = lambda x,y: filter(b(x),y) fr = ft.reduce fl = float gtat = getattr hsat = hasattr dlat = delattr stat = setattr hx = hex i = input n = lambda *args: eval(input(*args)) sr = "" t = int l = len ls = list ot = oct o = open f = lambda s: o(s).read() p = print r = range rp = repr rvr = reversed rnd = round srt = sorted s = str sm = sum t = Screen() v = vars w = Turtle() z = zip def rf(s): # regex finder index = s.index("!") regex = re.compile(s[:index]) search = s[index + 1 :] if search[0] == "!": return regex.findall(search[1:]) else: return regex.findall(eval(search)) q = chr(34) k = "\n" def e(s): raise RuntimeError(s) j = input("Enter image file ") i = Image.open(j) t.setup(width=i.width, height=i.height, startx=0, starty=0) t.bgpic(picname=j) x1=int(input("x1 ")) y1=int(input("y1 ")) x2=int(input("x2 ")) y2=int(input("y2 ")) c=input("c ") w.pc(c) w.pu() playsound("sound.mp3") w.goto(x1,y1) w.pd() w.goto(x2,y2) playsound("sound.mp3") done() |
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 | use rand::prelude::*; use std::collections::VecDeque; use std::iter::FromIterator; fn adjacent( x: isize, y: isize, width: isize, height: isize, ) -> impl Iterator<Item = (usize, usize)> { vec![(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)] .into_iter() .filter(move |&(a, b)| a < width && b < height && a >= 0 && b >= 0) .map(|(x, y)| (x as usize, y as usize)) } fn entry(grid: Vec<bool>, width: usize, _height: usize, x: usize, y: usize) -> Vec<bool> { let mut result: Vec<bool> = grid; result[x + width * y] = true; let mut pairs: VecDeque<(usize, usize)> = VecDeque::from_iter([(x, y)]); while !pairs.is_empty() { let (x1, y1) = pairs.pop_front().unwrap(); result[x1 + width * y1] = true; for (x2, y2) in adjacent(x1 as isize, y1 as isize, width as isize, _height as isize) { if !result[x2 + width * y2] { result[x2 + width * y2] = true; pairs.push_back((x2, y2)); } } } result } fn disp(grid: Vec<bool>, width: usize) { for (i, &item) in grid.iter().enumerate() { if i % width == 0 { println!(); } print!("{}", if item { "#" } else { "." }); } println!() } fn debug(grid: Vec<bool>, width: usize, _height: usize, x: usize, y: usize) { println!("x = {}, y = {}", x, y); let out: Vec<bool> = entry(grid.clone(), width, _height, x, y); disp(grid, width); println!("---"); disp(out, width); println!("==="); } fn rand_debug() { let mut rng = rand::thread_rng(); let width: usize = rng.gen_range(10..20); let height: usize = rng.gen_range(10..20); let x: usize = rng.gen_range(0..width); let y: usize = rng.gen_range(0..height); let size: usize = width * height; let mut grid: Vec<bool> = Vec::with_capacity(size); for _ in 0..size { grid.push(rand::random()); } debug(grid, width, height, x, y); } fn main() { debug( vec![ false, true, false, false, false, false, false, true, false, false, true, true, false, false, false, false, true, true, true, true, false, false, true, false, false, ], 5, 5, 4, 1, ); for _ in 0..20 { rand_debug(); } } |
1 |
post a comment