As a referance:
IN: scratchpad
USING: prettyprint kernel arrays ;
! <array> (n element -- array) : array of n element's
5 1 <array> . ! { 1 1 1 1 1 }
8 "H" <array> .
! 1array ( x -- array ) : 1 element array from x
{ 1 } 1 1array = .
! 2array ...
"Hello" "World" 2array .
! 3array ...
1 2 3 3array .
! 4array ...
0 1 1array 2 3 2array 3 4 5 3array 4array .
! >array (seq -- array ) converts stuff to arrays
"Hello" >array .
! array? / pair? ( object -- ? ) determines if something is an array
{ } array? .
"Hello" array? .
"Hello" >array array? .
1 array? .
(aka directly computing the fibbonaci sequence)
def binet(n):
sqrt5 = 5 ** 0.5
phi = (1 + sqrt5) / 2
psi = (1 - sqrt5) / 2
return int((phi ** n - psi ** n) / sqrt5)
import codewars_test as test
from solution import binet
@test.describe("Binet Formula")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(binet(0), 0)
test.assert_equals(binet(10), 55)
test.assert_equals(binet(100), 354224848179263111168)
without the Animal factory, rat.speak
would return an AttributeError instead of a NotImplementedError.
class Animal:
def speak(self): raise NotImplementedError
class Dog(Animal):
def speak(self): return "Woof!"
class Cat(Animal):
def speak(self): return "Meow!"
class Rat(Animal):
pass
class AnimalFactory:
def create_animal(self, animal_type):
match animal_type:
case "dog": return Dog()
case "cat": return Cat()
case "rat": return Rat()
import codewars_test as test
from solution import *
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
factory = AnimalFactory()
dog = factory.create_animal("dog")
test.assert_equals(dog.speak(),"Woof!")
cat = factory.create_animal("cat")
test.assert_equals(cat.speak(),"Meow!")
rat = factory.create_animal("rat")
test.expect_error(
function=rat.speak,
message=":-C",
exception = NotImplementedError
)
RandomBool=lambda:bool(ord('}')>ord(open('/dev/urandom','rb').read(True^False)))^\ __import__("secrets").choice([__import__("random").getrandbits(1), __import__("random").getrandbits(1)]) # might as well make it worse...
RandomBool=lambda:bool(ord(open('/dev/urandom','rb').read(1))&1)# This is also terribad, and the previous randint ones are better, but why not keep having fun- RandomBool=lambda:bool(ord('}')>ord(open('/dev/urandom','rb').read(True^False)))^\
- __import__("secrets").choice([__import__("random").getrandbits(1),
- __import__("random").getrandbits(1)])
- # might as well make it worse...
import __future__ import _weakrefset import grp import reprlib import _abc import _xxsubinterpreters import gzip import requests import _ast import _xxtestfuzz import hashlib import resource import _asyncio import abc import heapq # import retrying import _bisect import aifc import hmac import rlcompleter import _blake2 import antigravity import html import runpy #import appdirs #import html5lib import sched import _bz2 import argparse import http import secrets import _codecs import array import idna import select import _codecs_cn import ast import imaplib import selectors import _codecs_hk import asynchat import imghdr import setuptools import _codecs_iso2022 import asyncio import imp import shelve import _codecs_jp import asyncore import importlib import shlex import _codecs_kr import atexit import inspect import shutil import _codecs_tw import audioop import io import signal import _collections import base64 import ipaddress import site import _collections_abc import bdb import itertools import six import _compat_pickle import binascii import json import smtpd import _compression import binhex import keyword import smtplib import _contextvars import bisect import lib2to3 import sndhdr import _crypt import builtins import linecache import socket import _csv import bz2 import locale import socketserver import _ctypes import cProfile #import lockfile import spwd import _ctypes_test #import cachecontrol import logging import sqlite3 import _curses import calendar import lzma import sre_compile import _curses_panel import certifi import mailbox import sre_constants import _datetime import cgi import mailcap import sre_parse import _dbm import cgitb #import main import ssl import _decimal #import chardet import marshal import stat #import _dummy_thread import chunk import math import statistics import _elementtree import cmath import mimetypes import string import _functools import cmd import mmap import stringprep import _gdbm import code import modulefinder import struct import _hashlib import codecs #import msgpack import subprocess import _heapq import codeop import multiprocessing import sunau import _imp import collections import netrc #import symbol import _io #import colorama import nntplib import symtable import _json import colorsys import ntpath import sys import _locale import compileall import nturl2path import sysconfig import _lsprof import concurrent import numbers import syslog import _lzma import configparser import numpy import tabnanny import _markupbase import contextlib import opcode import tarfile import _md5 #import contextlib2 import operator import telnetlib import _multibytecodec import contextvars import optparse import tempfile import _multiprocessing import copy #import ordered_set import termios import _opcode import copyreg import os import textwrap import _operator import crypt import ossaudiodev #import this import _osx_support import csv import packaging import threading import _pickle import ctypes import pandas import time import _posixshmem import curses #import parser import timeit import _posixsubprocess import dataclasses import pathlib import token import _py_abc import datetime import pdb import tokenize import _pydecimal import dateutil #import pep517 #import toml import _pyio import dbm import pickle import trace import _queue import decimal import pickletools import traceback import _random import difflib import pip import tracemalloc import _sha1 import dis import pipes import tty import _sha256 #import distlib import pkg_resources import turtle import _sha3 #import distro import pkgutil import turtledemo import _sha512 import platform import types import _signal import doctest import plistlib import typing import _sitebuiltins #import dummy_threading import poplib import unicodedata import _socket import posix import unittest import _sqlite3 import email import posixpath import urllib import _sre import encodings import pprint import urllib3 import _ssl import ensurepip import profile import uu import _stat import enum #import progress import uuid import _statistics import errno import pstats import venv import _string import faulthandler import pty import warnings import _strptime import fcntl import pwd import wave import _struct import filecmp import py_compile import weakref import _symtable import fileinput import pyclbr import webbrowser import fnmatch import pydoc #import webencodings import _testbuffer #import formatter import pydoc_data import wsgiref import _testcapi import fractions import pyexpat import xdrlib import _testimportmultiple import ftplib import pyparsing import xml import _testinternalcapi import functools #import pytoml import xmlrpc import _testmultiphase import gc import pytz import xxlimited import _thread import genericpath import queue import xxsubtype import _threading_local import getopt import quopri import zipapp import _tracemalloc import getpass import random import zipfile import _warnings import gettext import re import zipimport import _weakref import glob import readline import zlib
- import __future__
- import _weakrefset
- import grp
- import reprlib
- import _abc
- import _xxsubinterpreters
- import gzip
- import requests
- import _ast
- import _xxtestfuzz
- import hashlib
- import resource
- import _asyncio
- import abc
- import heapq
- # import retrying
- import _bisect
- import aifc
- import hmac
- import rlcompleter
- import _blake2
- import antigravity
- import html
- import runpy
- #import appdirs
- #import html5lib
- import sched
- import _bz2
- import argparse
- import http
- import secrets
- import _codecs
- import array
- import idna
- import select
- import _codecs_cn
- import ast
- import imaplib
- import selectors
- import _codecs_hk
- import asynchat
- import imghdr
- import setuptools
- import _codecs_iso2022
- import asyncio
- import imp
- import shelve
- import _codecs_jp
- import asyncore
- import importlib
- import shlex
- import _codecs_kr
- import atexit
- import inspect
- import shutil
- import _codecs_tw
- import audioop
- import io
- import signal
- import _collections
- import base64
- import ipaddress
- import site
- import _collections_abc
- import bdb
- import itertools
- import six
- import _compat_pickle
- import binascii
- import json
- import smtpd
- import _compression
- import binhex
- import keyword
- import smtplib
- import _contextvars
- import bisect
- import lib2to3
- import sndhdr
- import _crypt
- import builtins
- import linecache
- import socket
- import _csv
- import bz2
- import locale
- import socketserver
- import _ctypes
- import cProfile
- #import lockfile
- import spwd
- import _ctypes_test
- #import cachecontrol
- import logging
- import sqlite3
- import _curses
- import calendar
- import lzma
- import sre_compile
- import _curses_panel
- import certifi
- import mailbox
- import sre_constants
- import _datetime
- import cgi
- import mailcap
- import sre_parse
- import _dbm
- import cgitb
- #import main
- import ssl
- import _decimal
- #import chardet
- import marshal
- import stat
- #import _dummy_thread
- import chunk
- import math
- import statistics
- import _elementtree
- import cmath
- import mimetypes
- import string
- import _functools
- import cmd
- import mmap
- import stringprep
- import _gdbm
- import code
- import modulefinder
- import struct
- import _hashlib
- import codecs
- #import msgpack
- import subprocess
- import _heapq
- import codeop
- import multiprocessing
- import sunau
- import _imp
- import collections
- import netrc
- #import symbol
- import _io
- #import colorama
- import nntplib
- import symtable
- import _json
- import colorsys
- import ntpath
- import sys
- import _locale
- import compileall
- import nturl2path
- import sysconfig
- import _lsprof
- import concurrent
- import numbers
- import syslog
- import _lzma
- import configparser
- import numpy
- import tabnanny
- import _markupbase
- import contextlib
- import opcode
- import tarfile
- import _md5
- #import contextlib2
- import operator
- import telnetlib
- import _multibytecodec
- import contextvars
- import optparse
- import tempfile
- import _multiprocessing
- import copy
- #import ordered_set
- import termios
- import _opcode
- import copyreg
- import os
- import textwrap
- import _operator
- import crypt
- import ossaudiodev
import this- #import this
- import _osx_support
- import csv
- import packaging
- import threading
- import _pickle
- import ctypes
- import pandas
- import time
- import _posixshmem
- import curses
- #import parser
- import timeit
- import _posixsubprocess
- import dataclasses
- import pathlib
- import token
- import _py_abc
- import datetime
- import pdb
- import tokenize
- import _pydecimal
- import dateutil
- #import pep517
- #import toml
- import _pyio
- import dbm
- import pickle
- import trace
- import _queue
- import decimal
- import pickletools
- import traceback
- import _random
- import difflib
- import pip
- import tracemalloc
- import _sha1
- import dis
- import pipes
- import tty
- import _sha256
- #import distlib
- import pkg_resources
- import turtle
- import _sha3
- #import distro
- import pkgutil
- import turtledemo
- import _sha512
- import platform
- import types
- import _signal
- import doctest
- import plistlib
- import typing
- import _sitebuiltins
- #import dummy_threading
- import poplib
- import unicodedata
- import _socket
- import posix
- import unittest
- import _sqlite3
- import email
- import posixpath
- import urllib
- import _sre
- import encodings
- import pprint
- import urllib3
- import _ssl
- import ensurepip
- import profile
- import uu
- import _stat
- import enum
- #import progress
- import uuid
- import _statistics
- import errno
- import pstats
- import venv
- import _string
- import faulthandler
- import pty
- import warnings
- import _strptime
- import fcntl
- import pwd
- import wave
- import _struct
- import filecmp
- import py_compile
- import weakref
- import _symtable
- import fileinput
- import pyclbr
- import webbrowser
- import fnmatch
- import pydoc
- #import webencodings
- import _testbuffer
- #import formatter
- import pydoc_data
- import wsgiref
- import _testcapi
- import fractions
- import pyexpat
- import xdrlib
- import _testimportmultiple
- import ftplib
- import pyparsing
- import xml
- import _testinternalcapi
- import functools
- #import pytoml
- import xmlrpc
- import _testmultiphase
- import gc
- import pytz
- import xxlimited
- import _thread
- import genericpath
- import queue
- import xxsubtype
- import _threading_local
- import getopt
- import quopri
- import zipapp
- import _tracemalloc
- import getpass
- import random
- import zipfile
- import _warnings
- import gettext
- import re
- import zipimport
- import _weakref
- import glob
- import readline
- import zlib
import codewars_test as test # TODO Write tests import solution # or from solution import example with open(r"/workspace/solution.txt") as file: imports = [x.replace('import ','') for x in file.read().splitlines() if not '#' in x] for x in imports: print(f"------------------{x}------------------------\n") print(dir(x),'\n') test.expect(True)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.expect(True)- with open(r"/workspace/solution.txt") as file:
- imports = [x.replace('import ','') for x in file.read().splitlines() if not '#' in x]
- for x in imports:
- print(f"------------------{x}------------------------\n")
- print(dir(x),'\n')
- test.expect(True)
minified.
>,+[-[-<+>>>+<<]>>>+[[-]<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->[-]>>+>+<<<]]]]]]]]]<]>>[>]++++++[-<++++++++>]>>]<<<[.[-]<<<]<[->+>[-]+<<]>>[+++[->++++++++<]>.[-]<]<]
>,+[-[-<+>>>+<<]>>>+[[-]<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->[-]>>+>+<<<]]]]]]]]]<]>>[>]++++++[-<++++++++>]>>]<<<[.[-]<<<]<[->+>[-]+<<]>>[+++[->++++++++<]>.[-]<]<]- >,+[-[-<+>>>+<<]>>>+[[-]<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->[-]>>+>+<<<]]]]]]]]]<]>>[>]++++++[-<++++++++>]>>]<<<[.[-]<<<]<[->+>[-]+<<]>>[+++[->++++++++<]>.[-]<]<]
Codewars can format html stuff!
Woah, nested descriptions!
ππππ
\_(oUo)_/
Or see an html reference here.
It also works in the console. Press the run button!
x = """
<main>
<h1>Heading... </h1>
<h2>Heading... </h2>
<h3>Heading... </h3>
<h4>Heading... </h4>
<h5>Heading... </h5>
<h6>Heading... </h6>
<p>
The formatter recognizes whitespace,
so be careful with indentation.
<p>The formatter can <b>also</b> do...</p>
<b>Bold words</b>
<i>italics</i>
<em>emphasis</em>
<mark>highlights</mark>
<small>small text</small>
<sub>sub</sub> Text
<sup>sup</sup> Text
<u>Underline... </u>
<abbr title="National Aeronautics and Space Administration">NASA</abbr> (Abbriviations)
<strike>strikethrough</strike>
<del> deprecated info </del> <ins> new info </ins>
<s> not relevant </s>
<a href="https://www.codewars.com/kumite/new">links (my favorite feature)</a>
<time datetime="2020-08-17 08:00">Monday at 8:00 AM</time> (smart time formatting)
</p>
</main>
<code>
// code blocks don't really show up different on the console...
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
</code>
<table>
<thead>
<tr>
<th>Numbers</th>
<th>Letters</th>
<th>Colors</th>
</tr>
</thead>
<tfoot>
<tr>
<td>123</td>
<td>ABC</td>
<td>RGB</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>1</td>
<td>A</td>
<td>Red</td>
</tr>
<tr>
<td>2</td>
<td>B</td>
<td>Green</td>
</tr>
<tr>
<td>3</td>
<td>C</td>
<td>Blue</td>
</tr>
</tbody>
</table>
<details>
<summary>This part's really cool...</summary>
<p>If you wanted to hide stuff,</p>
<p>Make some details section,</p>
<p>Or if you liked drop down menus,</p>
<p>You can do that now!</p>
</details>
<section>
<h3>Section 123</h3>
<p>yay, html. </p>
</section>
<ul>
<li>List items!</li>
<li>List items!</li>
</ul>
<select>
<optgroup label="Choice [1-3]">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</optgroup>
<optgroup label="Choice [4-6]">
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</optgroup>
</select>
<div>yoooooo a circle</div>
</div>
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
<textarea id="textarea" name="textarea" rows="4" cols="40">
Hello \(οΏ£οΈΆοΏ£*\))
Click and drag the bottem right corner to resize!
</textarea>
<iframe style="border-radius:12px" src="https://open.spotify.com/embed/track/2374M0fQpWi3dLnB54qaLX?utm_source=generator" width="75%" height="140" frameBorder="0" allowfullscreen="" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture" loading="lazy"></iframe><form>
<fieldset>
<legend>Info Stealing Form:</legend>
<label for="name">Name</label><br>
<input name="name" id="name"><br>
<label for="dob">Date of Birth<label><br>
<input name="dob" id="dob" type="date">
<label for="name">Social Security Number:</label><br>
<input name="SSN" id="no, this isn't collected anywhere."><br>
</fieldset>
<form action="" method="get">
<label for="Rating">Select your reaction from this kumite:</label>
<input list="reactions" name="Rating" id="Rating">
<datalist id="reactions">
<option value="WOAH!!">
<option value="Nice.">
<option value="Meh.">
<option value="Bad.">
<option value="BOOOOOOOOO!">
</datalist>
<input type="submit">
</form>
"""
print(x)
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
see the og as well.
from random import choice class Random_Bool(object): def __repr__(self): return repr(self.r()) def __init__(self): self.r = lambda: choice([True,False]) random_boolean = Random_Bool()
from dataclasses import dataclassfrom random import choice,randintclass returnable_argument:def get__approx_value_of(variable, get_type = False):try:if exec(f"{get_type}"):return (variable, type(variable))return variableexcept (SyntaxError, TypeError, NameError) as Error:print(f'Warning: {Error} was raised and excepted with values: {Error.args}')@dataclassclass _Random_Bool(object):def __repr__(_______, __________ = '___________'):assert "no, but acually yes"_____,_,__=locals,bool,int;x=1;_1_ =__import__("random").choice________ = lambda: eval("_(_1_([_(randint(bool(False),int(x))),(_(randint(False,True)))]))")return repr(_(_______.________()))def __init__(self,________________=None):assert all([self,returnable_argument.get__approx_value_of(self)])_____,_,__=locals,bool,int;x=1;_1_ =__import__("random").choiceself.________=lambda:_(_1_([_(randint(False,True)),(_(randint(False,True)))]))random_boolean = _Random_Bool()- from random import choice
- class Random_Bool(object):
- def __repr__(self):
- return repr(self.r())
- def __init__(self):
- self.r = lambda: choice([True,False])
- random_boolean = Random_Bool()
print(random_boolean) print(random_boolean.r()) # or if you actually wanted to use this... rb = Random_Bool() print(rb.r())
print(random_boolean.________())print(random_boolean)- print(random_boolean)
- print(random_boolean.r())
- # or if you actually wanted to use this...
- rb = Random_Bool()
- print(rb.r())
from dataclasses import dataclass
from random import choice,randint
class returnable_argument:
def get__approx_value_of(variable, get_type = False):
try:
if exec(f"{get_type}"):
return (variable, type(variable))
return variable
except (SyntaxError, TypeError, NameError) as Error:
print(f'Warning: {Error} was raised and excepted with values: {Error.args}')
@dataclass
class _Random_Bool(object):
def __repr__(_______, __________ = '___________'):
assert "no, but acually yes"
_____,_,__=locals,bool,int;x=1;_1_ =__import__("random").choice
________ = lambda: eval("_(_1_([_(randint(bool(False),int(x))),(_(randint(False,True)))]))")
return repr(_(_______.________()))
def __init__(self,________________=None):
assert all([self,returnable_argument.get__approx_value_of(self)])
_____,_,__=locals,bool,int;x=1;_1_ =__import__("random").choice
self.________=lambda:_(_1_([_(randint(False,True)),(_(randint(False,True)))]))
random_boolean = _Random_Bool()
print(random_boolean.________())
print(random_boolean)
__import__: 0.22252854499674868 seconds
from + import: 0.5542596579980454 seconds
well then.
import timeit
print("__import__: ",timeit.timeit("__import__('random').randint"))
print("from + import: ",timeit.timeit("from random import randint"))
you can do this weird import thing to achive the one-line.
if anyone here could tell me what I just found, that would be great...
import os
import subprocess
print((ve := os.listdir(".venv")))
for x in ve:
try:
print(x, os.listdir(f".venv/{x}"))
for y in x:
try:
print(y, os.listdir(f".venv/{x}/{y}"))
for z in y:
try:
with open(f".venv/{x}/{y}/{z}","r") as file: print(file.open())
except:
print("...goes on...")
except:
try:
with open(rf".venv/{x}") as f:
print(f.read())
except:
print()
except:
with open(rf".venv/{x}") as f:
print(f.read())
[laughs in integer overflow]!
{-# OPTIONS --safe #-}
module set-in-set where
-- Basically just a modified version of http://liamoc.net/posts/2015-09-10-girards-paradox.html
-- Some preliminaries, just to avoid any library imports
data _β‘_ {β : _} {A : Set β} : A -> A -> Set where
refl : β {a} -> a β‘ a
record Ξ£ (A : Set) (P : A -> Set) : Set where
constructor _,_
field
projβ : A
projβ : P projβ
open Ξ£
data β₯ : Set where
-- This shows the problem
WTF : Setβ
WTF = Setβββββββββββββββ
β
ββββ
-- 18446744073709551615 = 2^64 - 1
-- The following is basically copying from the link
data SET : Set where
set : (X : Setβββββββββββββββ
β
ββββ
) β (X β SET) β SET
_β_ : SET β SET β Set
a β set X f = Ξ£ X (Ξ» x β a β‘ f x)
_β_ : SET β SET β Set
a β b = (a β b) β β₯
Ξ : SET
Ξ = set (Ξ£ SET (Ξ» s β s β s)) projβ
xβΞβxβx : β {X} β X β Ξ β X β X
xβΞβxβx ((Y , YβY) , refl) = YβY
ΞβΞ : Ξ β Ξ
ΞβΞ ΞβΞ = xβΞβxβx ΞβΞ ΞβΞ
xβxβxβΞ : β {X} β X β X β X β Ξ
xβxβxβΞ {X} XβX = (X , XβX) , refl
falso : β₯
falso = ΞβΞ (xβxβxβΞ ΞβΞ)
def days(month,day): return ((y := d.date)((x := d.datetime.now().year), month, day) - y(x, 1, 1)).days + 1
- def days(month,day):
return (d.date(d.datetime.now().year, month, day) - d.date(d.datetime.now().year, 1, 1)).days + 1- return ((y := d.date)((x := d.datetime.now().year), month, day) - y(x, 1, 1)).days + 1