Activity for CrSb0001
| Type | On... | Excerpt | Status | Date |
|---|---|---|---|---|
| Edit | Post #293712 |
Post edited: |
— | over 1 year ago |
| Edit | Post #293788 |
Post edited: -14 bytes |
— | over 1 year ago |
| Edit | Post #294049 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Integer to Roman numeral [Lean 4], 232 bytes ```lean def r(i):=Id.run do let M:=[999,899,499,399,99,89,49,39,9,8,4,3,0] let N:=["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"] let mut s:="" let mut n:=i for x in List.range 13do while n>M[x]do s:=s++N[x];n:=n-M[x]-1 return s ``` Note that you will n... (more) |
— | over 1 year ago |
| Edit | Post #294045 |
Post edited: -59 bytes |
— | over 1 year ago |
| Edit | Post #294045 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Print the modular multiplicative inverse / virtual fractions Lean4, 113 56 bytes ```lean #eval(λx=>x^32767%4^8)(λx=>1+x2)(List.range 49) ``` [Try it online!] Something to notice is that you apparently don't need type signatures in functions or a function at all, in that case, and that mapping is right associative. Obligatory hexdump sin... (more) |
— | over 1 year ago |
| Comment | Post #293849 |
I can try to fix this while still preserving the bytecount. (more) |
— | over 1 year ago |
| Edit | Post #293915 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Compute the determinant Python 3.8+, 28 bytes ```python from numpy.linalg import det ``` Remember that `from ... import ...` can be used to save bytes. Note that this has already been mentioned in a comment section on @Quintec's answer, but I'm only posting this so this method specifically has its own answer, a... (more) |
— | over 1 year ago |
| Edit | Post #293849 |
Post edited: -1 byte |
— | over 1 year ago |
| Edit | Post #293849 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Caesar shift cipher Python 3, 86 85 bytes The reasoning behind why this works is basically that 1. we can directly compare the ordinal values of characters (apparently) and 2. we only need that if a character is alphanumeric, then 'A' which is very interesting to think about. Also, if we have an expression o... (more) |
— | over 1 year ago |
| Comment | Post #284028 |
Since everything is comparable in Python 2, you could for example write
```python
if a<b<[]>c>d:foo()
```
for 19 bytes instead of
```python
if a<b and c>d:foo()
```
for 20 bytes since lists are always greater than integers here.
---
Note that this doesn't work in Python 3 due to som... (more) |
— | over 1 year ago |
| Comment | Post #284147 |
We can further golf this using the following snippet:
```python
for i in range(150):print(i//15,'-',i%15)
```
This is 41 bytes (compared to your 49), unless we need `x` and/or `y` later.
As an alternative, if we need to use `y` later on, we can do this for 45 bytes:
```python
y=15
for... (more) |
— | over 1 year ago |
| Edit | Post #293759 |
Post edited: -2 bytes |
— | over 1 year ago |
| Edit | Post #293751 |
Post edited: -12 bytes |
— | over 1 year ago |
| Edit | Post #293712 |
Post edited: |
— | over 1 year ago |
| Edit | Post #293788 |
Post edited: |
— | over 1 year ago |
| Edit | Post #293788 |
Post edited: |
— | over 1 year ago |
| Edit | Post #293788 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Cumulative Counts [Lean 4], 111 97 bytes ```lean def d(l:List Nat):=((λx=>(l.reverse.drop x).count l.reverse[x])(List.range l.length)).reverse ``` [Try it online!] Given how verbose Lean syntax is, and how you can't really assign variables to keywords in a way that it saves bytes the vast majority of the ... (more) |
— | over 1 year ago |
| Edit | Post #293736 |
Post edited: -15 bytes |
— | over 1 year ago |
| Edit | Post #293785 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Cumulative Counts Python 3, 50 bytes We can simply omit the lambda name since we don't refer to it anywhere in the lambda definition. ```python lambda l:[l[:i+1].count(j)for i,j in enumerate(l)] ``` Example usage in the terminal: ```python >>>(lambda l:[l[:i+1].count(j)for i,j in enumerate(l)])([1,1,2... (more) |
— | over 1 year ago |
| Edit | Post #293736 |
Post edited: -5 bytes |
— | over 1 year ago |
| Edit | Post #293750 |
Post edited: |
— | over 1 year ago |
| Comment | Post #293750 |
Sorry, I can change it to “a positive integer >= 0” (more) |
— | over 1 year ago |
| Comment | Post #293750 |
…isn’t that how integers are typically stored in computer memory? I don’t see what you’re trying to ask (more) |
— | over 1 year ago |
| Edit | Post #293759 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Caesar shift cipher [Lean 4], 183 181 bytes ``` def c(t:String)(s:Nat):String:=t.map (λc=>if Char.isAlpha c then let b:=if Char.isLower c then 'a'else 'A';let h:=(Char.toNat c-Char.toNat b+s)%26+Char.toNat b;Char.ofNat h else c) ``` Try it online! Honestly it's surprising that 1) you can just throw everythi... (more) |
— | over 1 year ago |
| Edit | Post #293751 |
Post edited: -5 bytes |
— | over 1 year ago |
| Comment | Post #293750 |
@#53890 I'll keep the idea of first posting to the Sandbox in mind. (more) |
— | over 1 year ago |
| Comment | Post #293750 |
I've updated the ruleset in the question @#53890 @#77222 (more) |
— | over 1 year ago |
| Edit | Post #293750 |
Post edited: |
— | over 1 year ago |
| Edit | Post #293736 |
Post edited: Updated bytecount to take into account non-printable characters. |
— | over 1 year ago |
| Edit | Post #293751 |
Post edited: -3 bytes |
— | over 1 year ago |
| Comment | Post #293750 |
If it’s a builtin function that takes in a base 10 number and outputs a number in base 16 as a string or whatever, it is banned. So both `toHex` and `.toString(16)` would be banned.
As for xxd, I would say that it does not apply in the context of this challenge, as it is used primarily to crea... (more) |
— | over 1 year ago |
| Edit | Post #293751 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Convert to Hexadecimal Lean 4, 103 100 95 83 bytes ```lean def h:=λi=>if iif i| 00000010 3c 31 36 74 68 65 6e 20 73 21 22 7b 22 30 31 32 |<16then s!"{"012| 00000020 33 34 35 36 37 38 39 41 42 43 44 45 46 22 2e 67 |3456789ABCDEF".g| 00000030 65 74 20 e2 9f a8 69 e2 9f a9 7d 22 65 6c 73 65 |et ...i...}"else| 0... (more) |
— | over 1 year ago |
| Edit | Post #293750 | Initial revision | — | over 1 year ago |
| Question | — |
Convert to Hexadecimal Challenge Write a program that takes in a number greater than or equal to 0 and outputs its representation in hexadecimal (base 16). Examples ```none 0 => 0 1 => 1 10 => A 15 => F 16 => 10 107 => 6B 153 => 99 207 => CF 1000 => 3E8 10381 => 288D 4882... (more) |
— | over 1 year ago |
| Edit | Post #293745 | Initial revision | — | over 1 year ago |
| Answer | — |
A: "Hello, {name}!" Lean 4, 39 bytes ```lean def x(i:String):String:=s!"Hello, {i}!" ``` Try it online! (Note that TIO only supports Lean 3, so I sadly am unable to use a link from there.) (more) |
— | over 1 year ago |
| Edit | Post #293736 |
Post edited: -6 bytes |
— | over 1 year ago |
| Edit | Post #293739 | Initial revision | — | over 1 year ago |
| Question | — |
Tips for golfing in Lean [Lean] is an interactive theorem prover and a functional programming language created in 2013. What tips do you have for golfing in Lean? Tips should be specific to Lean ("remove comments" is not an answer), and stick to one tip per answer. (more) |
— | over 1 year ago |
| Edit | Post #293736 | Initial revision | — | over 1 year ago |
| Answer | — |
A: Give the fool's fibonacci sequence [Lean 4], 115 109 104 89 bytes Note: had to update bytecount to take into account non-printable characters. For anyone who isn't familiar with Lean, it's basically an interactive theorem prover that can also be used for regular math computation. Those who are familiar with Haskell would... (more) |
— | over 1 year ago |
| Edit | Post #293713 |
Post edited: -13 bytes, -69 bytes total. |
— | over 1 year ago |
